3
0

sort.tests 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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 doesn't strip leading blanks, disables fallback global sort" \
  55. "sort -n -k2 -t ' '" " a \n 1 \n 2 \n" "" " 2 \n 1 \n a \n"
  56. testing "sort key edge case with -t" "sort -n -k4 -t/" \
  57. "/usr/lib/finish-install.d/1
  58. /usr/lib/finish-install.d/4
  59. /usr/lib/prebaseconfig.d/2
  60. /usr/lib/prebaseconfig.d/6
  61. " "" "/usr/lib/finish-install.d/1
  62. /usr/lib/prebaseconfig.d/2
  63. /usr/lib/finish-install.d/4
  64. /usr/lib/prebaseconfig.d/6
  65. "
  66. exit $FAILCOUNT