Fix the test suite so that individual *.tests files can be run ala
[oweals/busybox.git] / testsuite / sort.tests
1 #!/bin/sh
2
3 # SUSv3 compliant sort tests.
4 # Copyright 2005 by Rob Landley <rob@landley.net>
5 # Licensed under GPL v2, see file LICENSE for details.
6
7 if [ ${#COMMAND} -eq 0 ]; then COMMAND=sort; fi
8 . testing.sh
9
10 # The basic tests.  These should work even with the small busybox.
11
12 testing "sort" "input" "a\nb\nc\n" "c\na\nb\n" ""
13 testing "sort #2" "input" "010\n1\n3\n" "3\n1\n010\n" ""
14 testing "sort stdin" "" "a\nb\nc\n" "" "b\na\nc\n"
15 testing "sort numeric" "-n input" "1\n3\n010\n" "3\n1\n010\n" ""
16 testing "sort reverse" "-r input" "wook\nwalrus\npoint\npabst\naargh\n" \
17         "point\nwook\npabst\naargh\nwalrus\n" ""
18
19 # These tests require the full option set.
20
21 optional FEATURE_SORT_BIG
22 # Longish chunk of data re-used by the next few tests
23
24 data="42        1       3       woot
25 42      1       010     zoology
26 egg     1       2       papyrus
27 7       3       42      soup
28 999     3       0       algebra
29 "
30
31 # Sorting with keys
32
33 testing "sort one key" "-k4,4 input" \
34 "999    3       0       algebra
35 egg     1       2       papyrus
36 7       3       42      soup
37 42      1       3       woot
38 42      1       010     zoology
39 " "$data" ""
40
41 testing "sort key range with numeric option" "-k2,3n input" \
42 "42     1       010     zoology
43 42      1       3       woot
44 egg     1       2       papyrus
45 7       3       42      soup
46 999     3       0       algebra
47 " "$data" ""
48
49 # Busybox is definitely doing this one wrong just now.  FIXME
50
51 testing "sort key range with numeric option and global reverse" \
52 "-k2,3n -r input" \
53 "egg    1       2       papyrus
54 42      1       3       woot
55 42      1       010     zoology
56 999     3       0       algebra
57 7       3       42      soup
58 " "$data" ""
59
60
61
62 testing "sort key range with multiple options" "-k2,3rn input" \
63 "7      3       42      soup
64 999     3       0       algebra
65 42      1       010     zoology
66 42      1       3       woot
67 egg     1       2       papyrus
68 " "$data" ""
69
70 exit $FAILCOUNT