sort.tests 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  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. testing "sort key range with numeric option and global reverse" \
  39. "sort -k2,3n -r input" \
  40. "egg 1 2 papyrus
  41. 42 1 3 woot
  42. 42 1 010 zoology
  43. 999 3 0 algebra
  44. 7 3 42 soup
  45. " "$data" ""
  46. testing "sort key range with multiple options" "sort -k2,3rn input" \
  47. "7 3 42 soup
  48. 999 3 0 algebra
  49. 42 1 010 zoology
  50. 42 1 3 woot
  51. egg 1 2 papyrus
  52. " "$data" ""
  53. testing "sort key range with two -k options" "sort -k 2,2n -k 1,1r input" "\
  54. d 2
  55. b 2
  56. c 3
  57. " "\
  58. c 3
  59. b 2
  60. d 2
  61. " ""
  62. testing "sort with non-default leading delim 1" "sort -n -k2 -t/ input" "\
  63. /a/2
  64. /b/1
  65. " "\
  66. /a/2
  67. /b/1
  68. " ""
  69. testing "sort with non-default leading delim 2" "sort -n -k3 -t/ input" "\
  70. /b/1
  71. /a/2
  72. " "\
  73. /b/1
  74. /a/2
  75. " ""
  76. testing "sort with non-default leading delim 3" "sort -n -k3 -t/ input" "\
  77. //a/2
  78. //b/1
  79. " "\
  80. //a/2
  81. //b/1
  82. " ""
  83. testing "sort with non-default leading delim 4" "sort -t: -k1,1 input" "\
  84. a:b
  85. a/a:a
  86. " "\
  87. a/a:a
  88. a:b
  89. " ""
  90. testing "sort with ENDCHAR" "sort -t. -k1,1.1 -k2 input" "\
  91. ab.1
  92. aa.2
  93. " "\
  94. aa.2
  95. ab.1
  96. " ""
  97. testing "glibc build sort" "sort -t. -k 1,1 -k 2n,2n -k 3 input" "\
  98. GLIBC_2.1
  99. GLIBC_2.1.1
  100. GLIBC_2.2
  101. GLIBC_2.2.1
  102. GLIBC_2.10
  103. GLIBC_2.20
  104. GLIBC_2.21
  105. " "\
  106. GLIBC_2.21
  107. GLIBC_2.1.1
  108. GLIBC_2.2.1
  109. GLIBC_2.2
  110. GLIBC_2.20
  111. GLIBC_2.10
  112. GLIBC_2.1
  113. " ""
  114. testing "glibc build sort unique" "sort -u -t. -k 1,1 -k 2n,2n -k 3 input" "\
  115. GLIBC_2.1
  116. GLIBC_2.1.1
  117. GLIBC_2.2
  118. GLIBC_2.2.1
  119. GLIBC_2.10
  120. GLIBC_2.20
  121. GLIBC_2.21
  122. " "\
  123. GLIBC_2.10
  124. GLIBC_2.2.1
  125. GLIBC_2.1.1
  126. GLIBC_2.20
  127. GLIBC_2.2
  128. GLIBC_2.1
  129. GLIBC_2.21
  130. " ""
  131. testing "sort -u should consider field only when discarding" "sort -u -k2 input" "\
  132. a c
  133. " "\
  134. a c
  135. b c
  136. " ""
  137. testing "sort -z outputs NUL terminated lines" "sort -z input" "\
  138. one\0three\0two\0\
  139. " "\
  140. one\0two\0three\0\
  141. " ""
  142. testing "sort key doesn't strip leading blanks, disables fallback global sort" \
  143. "sort -n -k2 -t ' '" " a \n 1 \n 2 \n" "" " 2 \n 1 \n a \n"
  144. testing "sort file in place" \
  145. "sort -o input input && cat input" "\
  146. 111
  147. 222
  148. " "\
  149. 222
  150. 111
  151. " ""
  152. # testing "description" "command(s)" "result" "infile" "stdin"
  153. exit $FAILCOUNT