sort.tests 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. #!/bin/bash
  2. # SUSv3 compliant sort tests.
  3. # Copyright 2005 by Rob Landley <rob@landley.net>
  4. # Licensed under GPL v2, see file LICENSE for details.
  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. # Sorting with keys
  23. testing "sort one key" "sort -k4,4 input" \
  24. "999 3 0 algebra
  25. egg 1 2 papyrus
  26. 7 3 42 soup
  27. 42 1 3 woot
  28. 42 1 010 zoology
  29. " "$data" ""
  30. testing "sort key range with numeric option" "sort -k2,3n input" \
  31. "42 1 010 zoology
  32. 42 1 3 woot
  33. egg 1 2 papyrus
  34. 7 3 42 soup
  35. 999 3 0 algebra
  36. " "$data" ""
  37. test x"$SKIP_KNOWN_BUGS" = x"" && {
  38. # Busybox is definitely doing these wrong. FIXME
  39. testing "sort key range with numeric option and global reverse" \
  40. "sort -k2,3n -r input" \
  41. "egg 1 2 papyrus
  42. 42 1 3 woot
  43. 42 1 010 zoology
  44. 999 3 0 algebra
  45. 7 3 42 soup
  46. " "$data" ""
  47. testing "sort key range with multiple options" "sort -k2,3rn input" \
  48. "7 3 42 soup
  49. 999 3 0 algebra
  50. 42 1 010 zoology
  51. 42 1 3 woot
  52. egg 1 2 papyrus
  53. " "$data" ""
  54. }
  55. testing "sort key range with two -k options" "sort -k 2,2n -k 1,1r input" "\
  56. d 2
  57. b 2
  58. c 3
  59. " "\
  60. c 3
  61. b 2
  62. d 2
  63. " ""
  64. testing "sort with non-default leading delim 1" "sort -n -k2 -t/ input" "\
  65. /a/2
  66. /b/1
  67. " "\
  68. /a/2
  69. /b/1
  70. " ""
  71. testing "sort with non-default leading delim 2" "sort -n -k3 -t/ input" "\
  72. /b/1
  73. /a/2
  74. " "\
  75. /b/1
  76. /a/2
  77. " ""
  78. testing "sort with non-default leading delim 3" "sort -n -k3 -t/ input" "\
  79. //a/2
  80. //b/1
  81. " "\
  82. //a/2
  83. //b/1
  84. " ""
  85. testing "sort -u should consider field only when discarding" "sort -u -k2 input" "\
  86. a c
  87. " "\
  88. a c
  89. b c
  90. " ""
  91. testing "sort -z outputs NUL terminated lines" "sort -z input" "\
  92. one\0three\0two\0\
  93. " "\
  94. one\0two\0three\0\
  95. " ""
  96. testing "sort key doesn't strip leading blanks, disables fallback global sort" \
  97. "sort -n -k2 -t ' '" " a \n 1 \n 2 \n" "" " 2 \n 1 \n a \n"
  98. exit $FAILCOUNT