Mercurial > hg > toybox
annotate scripts/test/sort.test @ 535:d51be130fda2
More stabs at getting #includes right, and moving off of deprecated functions.
author | Rob Landley <rob@landley.net> |
---|---|
date | Thu, 08 Mar 2012 20:14:55 -0600 |
parents | 87edfe8ae99e |
children | 47edfc1a4983 |
rev | line source |
---|---|
303
b8f6dd7cf7f7
Basic tests for sort. Needs more...
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
1 #!/bin/bash |
b8f6dd7cf7f7
Basic tests for sort. Needs more...
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
2 |
421 | 3 # SUSv4 compliant sort tests. |
4 # Copyright 2005, 2012 by Rob Landley <rob@landley.net> | |
303
b8f6dd7cf7f7
Basic tests for sort. Needs more...
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
5 |
421 | 6 [ -f testing.sh ] && . testing.sh |
303
b8f6dd7cf7f7
Basic tests for sort. Needs more...
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
7 |
b8f6dd7cf7f7
Basic tests for sort. Needs more...
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
8 # The basic tests. These should work even with the small config. |
b8f6dd7cf7f7
Basic tests for sort. Needs more...
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
9 |
b8f6dd7cf7f7
Basic tests for sort. Needs more...
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
10 testing "sort" "sort input" "a\nb\nc\n" "c\na\nb\n" "" |
b8f6dd7cf7f7
Basic tests for sort. Needs more...
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
11 testing "sort #2" "sort input" "010\n1\n3\n" "3\n1\n010\n" "" |
b8f6dd7cf7f7
Basic tests for sort. Needs more...
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
12 testing "sort stdin" "sort" "a\nb\nc\n" "" "b\na\nc\n" |
b8f6dd7cf7f7
Basic tests for sort. Needs more...
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
13 testing "sort numeric" "sort -n input" "1\n3\n010\n" "3\n1\n010\n" "" |
b8f6dd7cf7f7
Basic tests for sort. Needs more...
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
14 testing "sort reverse" "sort -r input" "wook\nwalrus\npoint\npabst\naargh\n" \ |
b8f6dd7cf7f7
Basic tests for sort. Needs more...
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
15 "point\nwook\npabst\naargh\nwalrus\n" "" |
b8f6dd7cf7f7
Basic tests for sort. Needs more...
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
16 |
b8f6dd7cf7f7
Basic tests for sort. Needs more...
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
17 # These tests require the full option set. |
b8f6dd7cf7f7
Basic tests for sort. Needs more...
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
18 |
b8f6dd7cf7f7
Basic tests for sort. Needs more...
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
19 optional SORT_BIG |
b8f6dd7cf7f7
Basic tests for sort. Needs more...
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
20 # Longish chunk of data re-used by the next few tests. The expected output |
b8f6dd7cf7f7
Basic tests for sort. Needs more...
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
21 # varies, but the input (this) is the same. |
b8f6dd7cf7f7
Basic tests for sort. Needs more...
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
22 |
b8f6dd7cf7f7
Basic tests for sort. Needs more...
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
23 data="42 1 3 woot |
b8f6dd7cf7f7
Basic tests for sort. Needs more...
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
24 42 1 010 zoology |
b8f6dd7cf7f7
Basic tests for sort. Needs more...
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
25 egg 1 2 papyrus |
b8f6dd7cf7f7
Basic tests for sort. Needs more...
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
26 7 3 42 soup |
b8f6dd7cf7f7
Basic tests for sort. Needs more...
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
27 999 3 0 algebra |
b8f6dd7cf7f7
Basic tests for sort. Needs more...
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
28 " |
b8f6dd7cf7f7
Basic tests for sort. Needs more...
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
29 |
b8f6dd7cf7f7
Basic tests for sort. Needs more...
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
30 # Sorting with keys |
b8f6dd7cf7f7
Basic tests for sort. Needs more...
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
31 |
b8f6dd7cf7f7
Basic tests for sort. Needs more...
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
32 testing "sort one key" "sort -k4,4 input" \ |
b8f6dd7cf7f7
Basic tests for sort. Needs more...
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
33 "999 3 0 algebra |
b8f6dd7cf7f7
Basic tests for sort. Needs more...
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
34 egg 1 2 papyrus |
b8f6dd7cf7f7
Basic tests for sort. Needs more...
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
35 7 3 42 soup |
b8f6dd7cf7f7
Basic tests for sort. Needs more...
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
36 42 1 3 woot |
b8f6dd7cf7f7
Basic tests for sort. Needs more...
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
37 42 1 010 zoology |
b8f6dd7cf7f7
Basic tests for sort. Needs more...
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
38 " "$data" "" |
b8f6dd7cf7f7
Basic tests for sort. Needs more...
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
39 |
b8f6dd7cf7f7
Basic tests for sort. Needs more...
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
40 # The numeric sort orders field 2, ignores field 3 (because numeric sort stops |
b8f6dd7cf7f7
Basic tests for sort. Needs more...
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
41 # at the whitespace), then the global fallback sort does an alpha sort on |
b8f6dd7cf7f7
Basic tests for sort. Needs more...
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
42 # the whole string (starting at the beginning of the line). |
b8f6dd7cf7f7
Basic tests for sort. Needs more...
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
43 |
b8f6dd7cf7f7
Basic tests for sort. Needs more...
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
44 testing "sort key range with numeric option" "sort -k2,3n input" \ |
b8f6dd7cf7f7
Basic tests for sort. Needs more...
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
45 "42 1 010 zoology |
b8f6dd7cf7f7
Basic tests for sort. Needs more...
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
46 42 1 3 woot |
b8f6dd7cf7f7
Basic tests for sort. Needs more...
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
47 egg 1 2 papyrus |
b8f6dd7cf7f7
Basic tests for sort. Needs more...
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
48 7 3 42 soup |
b8f6dd7cf7f7
Basic tests for sort. Needs more...
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
49 999 3 0 algebra |
b8f6dd7cf7f7
Basic tests for sort. Needs more...
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
50 " "$data" "" |
b8f6dd7cf7f7
Basic tests for sort. Needs more...
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
51 |
b8f6dd7cf7f7
Basic tests for sort. Needs more...
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
52 # Numeric sort on field 2 (again, ignore field 3 because it's numeric), |
b8f6dd7cf7f7
Basic tests for sort. Needs more...
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
53 # then do a _reversed_ alpha sort on the whole line as a tiebreaker. |
b8f6dd7cf7f7
Basic tests for sort. Needs more...
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
54 |
b8f6dd7cf7f7
Basic tests for sort. Needs more...
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
55 testing "sort key range with numeric option and global reverse" \ |
b8f6dd7cf7f7
Basic tests for sort. Needs more...
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
56 "sort -k2,3n -r input" \ |
b8f6dd7cf7f7
Basic tests for sort. Needs more...
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
57 "egg 1 2 papyrus |
b8f6dd7cf7f7
Basic tests for sort. Needs more...
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
58 42 1 3 woot |
b8f6dd7cf7f7
Basic tests for sort. Needs more...
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
59 42 1 010 zoology |
b8f6dd7cf7f7
Basic tests for sort. Needs more...
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
60 999 3 0 algebra |
b8f6dd7cf7f7
Basic tests for sort. Needs more...
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
61 7 3 42 soup |
b8f6dd7cf7f7
Basic tests for sort. Needs more...
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
62 " "$data" "" |
b8f6dd7cf7f7
Basic tests for sort. Needs more...
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
63 |
b8f6dd7cf7f7
Basic tests for sort. Needs more...
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
64 # Reversed numeric sort on field 2 (numeric ignores field 3), then |
b8f6dd7cf7f7
Basic tests for sort. Needs more...
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
65 # break ties with alpha sort on whole line. |
b8f6dd7cf7f7
Basic tests for sort. Needs more...
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
66 |
b8f6dd7cf7f7
Basic tests for sort. Needs more...
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
67 testing "sort key range with multiple options" "sort -k2,3rn input" \ |
b8f6dd7cf7f7
Basic tests for sort. Needs more...
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
68 "7 3 42 soup |
b8f6dd7cf7f7
Basic tests for sort. Needs more...
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
69 999 3 0 algebra |
b8f6dd7cf7f7
Basic tests for sort. Needs more...
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
70 42 1 010 zoology |
b8f6dd7cf7f7
Basic tests for sort. Needs more...
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
71 42 1 3 woot |
b8f6dd7cf7f7
Basic tests for sort. Needs more...
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
72 egg 1 2 papyrus |
b8f6dd7cf7f7
Basic tests for sort. Needs more...
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
73 " "$data" "" |
b8f6dd7cf7f7
Basic tests for sort. Needs more...
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
74 |
b8f6dd7cf7f7
Basic tests for sort. Needs more...
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
75 testing "sort key doesn't strip leading blanks, disables fallback global sort" \ |
b8f6dd7cf7f7
Basic tests for sort. Needs more...
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
76 "sort -n -k2 -t ' '" " a \n 1 \n 2 \n" "" " 2 \n 1 \n a \n" |
b8f6dd7cf7f7
Basic tests for sort. Needs more...
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
77 |
b8f6dd7cf7f7
Basic tests for sort. Needs more...
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
78 # Test case contributed by Joey Hess: |
b8f6dd7cf7f7
Basic tests for sort. Needs more...
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
79 |
b8f6dd7cf7f7
Basic tests for sort. Needs more...
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
80 testing "sort key edge case with -t" "sort -n -k4 -t/" \ |
b8f6dd7cf7f7
Basic tests for sort. Needs more...
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
81 "/usr/lib/finish-install.d/1 |
b8f6dd7cf7f7
Basic tests for sort. Needs more...
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
82 /usr/lib/finish-install.d/4 |
b8f6dd7cf7f7
Basic tests for sort. Needs more...
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
83 /usr/lib/prebaseconfig.d/2 |
b8f6dd7cf7f7
Basic tests for sort. Needs more...
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
84 /usr/lib/prebaseconfig.d/6 |
b8f6dd7cf7f7
Basic tests for sort. Needs more...
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
85 " "" "/usr/lib/finish-install.d/1 |
b8f6dd7cf7f7
Basic tests for sort. Needs more...
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
86 /usr/lib/prebaseconfig.d/2 |
b8f6dd7cf7f7
Basic tests for sort. Needs more...
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
87 /usr/lib/finish-install.d/4 |
b8f6dd7cf7f7
Basic tests for sort. Needs more...
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
88 /usr/lib/prebaseconfig.d/6 |
b8f6dd7cf7f7
Basic tests for sort. Needs more...
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
89 " |
b8f6dd7cf7f7
Basic tests for sort. Needs more...
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
90 |
431
87edfe8ae99e
Bugfix for -x, add CONFIG_SORT_FLOAT, and new test suite entry.
Rob Landley <rob@landley.net>
parents:
421
diff
changeset
|
91 testing "sort -x" "sort -x" "010\na0\n 0c0\n" "" "a0\n010\n 0c0\n" |
87edfe8ae99e
Bugfix for -x, add CONFIG_SORT_FLOAT, and new test suite entry.
Rob Landley <rob@landley.net>
parents:
421
diff
changeset
|
92 |
87edfe8ae99e
Bugfix for -x, add CONFIG_SORT_FLOAT, and new test suite entry.
Rob Landley <rob@landley.net>
parents:
421
diff
changeset
|
93 optional SORT_FLOAT |
87edfe8ae99e
Bugfix for -x, add CONFIG_SORT_FLOAT, and new test suite entry.
Rob Landley <rob@landley.net>
parents:
421
diff
changeset
|
94 |
87edfe8ae99e
Bugfix for -x, add CONFIG_SORT_FLOAT, and new test suite entry.
Rob Landley <rob@landley.net>
parents:
421
diff
changeset
|
95 # not numbers < NaN < -infinity < numbers < +infinity |
87edfe8ae99e
Bugfix for -x, add CONFIG_SORT_FLOAT, and new test suite entry.
Rob Landley <rob@landley.net>
parents:
421
diff
changeset
|
96 testing "sort -g" "sort -g" \ |
87edfe8ae99e
Bugfix for -x, add CONFIG_SORT_FLOAT, and new test suite entry.
Rob Landley <rob@landley.net>
parents:
421
diff
changeset
|
97 "bork\nNaN\n-inf\n0.4\n1.222\n01.37\n2.1\n+infinity\n" "" \ |
87edfe8ae99e
Bugfix for -x, add CONFIG_SORT_FLOAT, and new test suite entry.
Rob Landley <rob@landley.net>
parents:
421
diff
changeset
|
98 "01.37\n1.222\n2.1\n0.4\nNaN\nbork\n-inf\n+infinity\n" |
87edfe8ae99e
Bugfix for -x, add CONFIG_SORT_FLOAT, and new test suite entry.
Rob Landley <rob@landley.net>
parents:
421
diff
changeset
|
99 |
303
b8f6dd7cf7f7
Basic tests for sort. Needs more...
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
100 exit $FAILCOUNT |