3
0

sort.tests 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  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 "glibc build sort" "sort -t. -k 1,1 -k 2n,2n -k 3 input" "\
  91. GLIBC_2.1
  92. GLIBC_2.1.1
  93. GLIBC_2.2
  94. GLIBC_2.2.1
  95. GLIBC_2.10
  96. GLIBC_2.20
  97. GLIBC_2.21
  98. " "\
  99. GLIBC_2.21
  100. GLIBC_2.1.1
  101. GLIBC_2.2.1
  102. GLIBC_2.2
  103. GLIBC_2.20
  104. GLIBC_2.10
  105. GLIBC_2.1
  106. " ""
  107. testing "glibc build sort unique" "sort -u -t. -k 1,1 -k 2n,2n -k 3 input" "\
  108. GLIBC_2.1
  109. GLIBC_2.1.1
  110. GLIBC_2.2
  111. GLIBC_2.2.1
  112. GLIBC_2.10
  113. GLIBC_2.20
  114. GLIBC_2.21
  115. " "\
  116. GLIBC_2.10
  117. GLIBC_2.2.1
  118. GLIBC_2.1.1
  119. GLIBC_2.20
  120. GLIBC_2.2
  121. GLIBC_2.1
  122. GLIBC_2.21
  123. " ""
  124. testing "sort -u should consider field only when discarding" "sort -u -k2 input" "\
  125. a c
  126. " "\
  127. a c
  128. b c
  129. " ""
  130. testing "sort -z outputs NUL terminated lines" "sort -z input" "\
  131. one\0three\0two\0\
  132. " "\
  133. one\0two\0three\0\
  134. " ""
  135. testing "sort key doesn't strip leading blanks, disables fallback global sort" \
  136. "sort -n -k2 -t ' '" " a \n 1 \n 2 \n" "" " 2 \n 1 \n a \n"
  137. testing "sort file in place" \
  138. "sort -o input input && cat input" "\
  139. 111
  140. 222
  141. " "\
  142. 222
  143. 111
  144. " ""
  145. # testing "description" "command(s)" "result" "infile" "stdin"
  146. exit $FAILCOUNT