3
0

sort.tests 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. #!/bin/sh
  2. # SUSv3 compliant sort tests.
  3. # Copyright 2005 by Rob Landley <rob@landley.net>
  4. # Licensed under GPLv2, see file LICENSE in this source tree.
  5. . ./testing.sh
  6. # The basic tests. These should work even with the small busybox.
  7. testing "sort" "sort input" "a\nb\nc\n" "c\na\nb\n" ""
  8. testing "sort #2" "sort input" "010\n1\n3\n" "3\n1\n010\n" ""
  9. testing "sort stdin" "sort" "a\nb\nc\n" "" "b\na\nc\n"
  10. testing "sort numeric" "sort -n input" "1\n3\n010\n" "3\n1\n010\n" ""
  11. testing "sort reverse" "sort -r input" "wook\nwalrus\npoint\npabst\naargh\n" \
  12. "point\nwook\npabst\naargh\nwalrus\n" ""
  13. # These tests require the full option set.
  14. optional FEATURE_SORT_BIG
  15. # Longish chunk of data re-used by the next few tests
  16. data="42 1 3 woot
  17. 42 1 010 zoology
  18. egg 1 2 papyrus
  19. 7 3 42 soup
  20. 999 3 0 algebra
  21. "
  22. # testing "description" "command(s)" "result" "infile" "stdin"
  23. # Sorting with keys
  24. testing "sort one key" "sort -k4,4 input" \
  25. "999 3 0 algebra
  26. egg 1 2 papyrus
  27. 7 3 42 soup
  28. 42 1 3 woot
  29. 42 1 010 zoology
  30. " "$data" ""
  31. testing "sort key range with numeric option" "sort -k2,3n input" \
  32. "42 1 010 zoology
  33. 42 1 3 woot
  34. egg 1 2 papyrus
  35. 7 3 42 soup
  36. 999 3 0 algebra
  37. " "$data" ""
  38. test x"$SKIP_KNOWN_BUGS" = x"" && {
  39. # Busybox is definitely doing these wrong. FIXME
  40. testing "sort key range with numeric option and global reverse" \
  41. "sort -k2,3n -r input" \
  42. "egg 1 2 papyrus
  43. 42 1 3 woot
  44. 42 1 010 zoology
  45. 999 3 0 algebra
  46. 7 3 42 soup
  47. " "$data" ""
  48. testing "sort key range with multiple options" "sort -k2,3rn input" \
  49. "7 3 42 soup
  50. 999 3 0 algebra
  51. 42 1 010 zoology
  52. 42 1 3 woot
  53. egg 1 2 papyrus
  54. " "$data" ""
  55. }
  56. testing "sort key range with two -k options" "sort -k 2,2n -k 1,1r input" "\
  57. d 2
  58. b 2
  59. c 3
  60. " "\
  61. c 3
  62. b 2
  63. d 2
  64. " ""
  65. testing "sort with non-default leading delim 1" "sort -n -k2 -t/ input" "\
  66. /a/2
  67. /b/1
  68. " "\
  69. /a/2
  70. /b/1
  71. " ""
  72. testing "sort with non-default leading delim 2" "sort -n -k3 -t/ input" "\
  73. /b/1
  74. /a/2
  75. " "\
  76. /b/1
  77. /a/2
  78. " ""
  79. testing "sort with non-default leading delim 3" "sort -n -k3 -t/ input" "\
  80. //a/2
  81. //b/1
  82. " "\
  83. //a/2
  84. //b/1
  85. " ""
  86. testing "sort -u should consider field only when discarding" "sort -u -k2 input" "\
  87. a c
  88. " "\
  89. a c
  90. b c
  91. " ""
  92. testing "sort -z outputs NUL terminated lines" "sort -z input" "\
  93. one\0three\0two\0\
  94. " "\
  95. one\0two\0three\0\
  96. " ""
  97. testing "sort key doesn't strip leading blanks, disables fallback global sort" \
  98. "sort -n -k2 -t ' '" " a \n 1 \n 2 \n" "" " 2 \n 1 \n a \n"
  99. testing "sort file in place" \
  100. "sort -o input input && cat input" "\
  101. 111
  102. 222
  103. " "\
  104. 222
  105. 111
  106. " ""
  107. # testing "description" "command(s)" "result" "infile" "stdin"
  108. exit $FAILCOUNT