sort.tests 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  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. # Busybox is definitely doing this one wrong just now. FIXME
  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. #
  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. testing "sort key range with two -k options" "sort -k 2,2n -k 1,1r input" "\
  55. d 2
  56. b 2
  57. c 3
  58. " "\
  59. c 3
  60. b 2
  61. d 2
  62. " ""
  63. testing "sort with non-default leading delim 1" "sort -n -k2 -t/ input" "\
  64. /a/2
  65. /b/1
  66. " "\
  67. /a/2
  68. /b/1
  69. " ""
  70. testing "sort with non-default leading delim 2" "sort -n -k3 -t/ input" "\
  71. /b/1
  72. /a/2
  73. " "\
  74. /b/1
  75. /a/2
  76. " ""
  77. testing "sort with non-default leading delim 3" "sort -n -k3 -t/ input" "\
  78. //a/2
  79. //b/1
  80. " "\
  81. //a/2
  82. //b/1
  83. " ""
  84. testing "sort -u should consider field only when discarding" "sort -u -k2 input" "\
  85. a c
  86. " "\
  87. a c
  88. b c
  89. " ""
  90. testing "sort -z outputs NUL terminated lines" "sort -z input" "\
  91. one\0three\0two\0\
  92. " "\
  93. one\0two\0three\0\
  94. " ""
  95. testing "sort key doesn't strip leading blanks, disables fallback global sort" \
  96. "sort -n -k2 -t ' '" " a \n 1 \n 2 \n" "" " 2 \n 1 \n a \n"
  97. exit $FAILCOUNT