diff options
author | Rob Landley <rob@landley.net> | 2006-03-16 15:20:45 +0000 |
---|---|---|
committer | Rob Landley <rob@landley.net> | 2006-03-16 15:20:45 +0000 |
commit | 4bb1b04fd1d7d6fe410e1af14816d11da456aac5 (patch) | |
tree | 601a54598057fc267def41fce1acecfb8e5a2845 | |
parent | ea9a471acd94f604f360ea16df5896e795361ac7 (diff) | |
download | busybox-w32-4bb1b04fd1d7d6fe410e1af14816d11da456aac5.tar.gz busybox-w32-4bb1b04fd1d7d6fe410e1af14816d11da456aac5.tar.bz2 busybox-w32-4bb1b04fd1d7d6fe410e1af14816d11da456aac5.zip |
Redo test suite to be able to test more than one command at a time. Eliminate
$COMMAND environment variable, instead put full command line (including
command to run) in second argument. Modify $PATH to have test versions of
commands at start of path. (Also more infrastructure for testing as root,
work in progress...)
-rwxr-xr-x | testsuite/busybox.tests | 56 | ||||
-rwxr-xr-x | testsuite/egrep.tests | 19 | ||||
-rwxr-xr-x | testsuite/grep.tests | 42 | ||||
-rwxr-xr-x | testsuite/pidof.tests | 18 | ||||
-rwxr-xr-x | testsuite/sed.tests | 121 | ||||
-rwxr-xr-x | testsuite/sort.tests | 19 | ||||
-rwxr-xr-x | testsuite/testing.sh | 63 | ||||
-rwxr-xr-x | testsuite/uniq.tests | 25 |
8 files changed, 189 insertions, 174 deletions
diff --git a/testsuite/busybox.tests b/testsuite/busybox.tests index f31f38f06..30d96f946 100755 --- a/testsuite/busybox.tests +++ b/testsuite/busybox.tests | |||
@@ -4,57 +4,55 @@ | |||
4 | # Copyright 2005 by Rob Landley <rob@landley.net> | 4 | # Copyright 2005 by Rob Landley <rob@landley.net> |
5 | # Licensed under GPL v2, see file LICENSE for details. | 5 | # Licensed under GPL v2, see file LICENSE for details. |
6 | 6 | ||
7 | if [ ${#COMMAND} -eq 0 ]; then COMMAND=busybox; fi | ||
8 | . testing.sh | 7 | . testing.sh |
9 | 8 | ||
10 | HELPDUMP=`$COMMAND` | 9 | # verify the applet order is correct in applets.h, otherwise applets won't |
10 | # be called properly. | ||
11 | #sed -n -e '/^USE_^\tAPPLET/{s:.*(::;s:,.*::;s:"::g;p}' | ||
12 | # ../include/applets.h > applet.order1 | ||
13 | #LC_ALL=C sort applet.order.current > applet.order.correct | ||
14 | #diff -u applet.order.current applet.order.correct | ||
15 | #FAILCOUNT=$[$FAILCOUNT+$?] | ||
16 | #rm -f applet.order.current applet.order.correct | ||
17 | |||
18 | |||
19 | |||
20 | |||
21 | HELPDUMP=`busybox` | ||
11 | 22 | ||
12 | # We need to test under calling the binary under other names. | 23 | # We need to test under calling the binary under other names. |
13 | 24 | ||
14 | ln -s `which "$COMMAND"` busybox-suffix | ||
15 | ln -s `which "$COMMAND"` unknown | ||
16 | 25 | ||
17 | testing "busybox --help busybox" "--help busybox" "$HELPDUMP\n\n" "" "" | 26 | testing "busybox --help busybox" "busybox --help busybox" "$HELPDUMP\n\n" "" "" |
18 | 27 | ||
19 | for i in busybox busybox-suffix | 28 | ln -s `which busybox` busybox-suffix |
29 | for i in busybox ./busybox-suffix | ||
20 | do | 30 | do |
21 | # The gratuitous "\n"s are due to a shell idiosyncrasy: | 31 | # The gratuitous "\n"s are due to a shell idiosyncrasy: |
22 | # environment variables seem to strip trailing whitespace. | 32 | # environment variables seem to strip trailing whitespace. |
23 | 33 | ||
24 | testing "$i" "" "$HELPDUMP\n\n" "" "" | 34 | testing "" "$i" "$HELPDUMP\n\n" "" "" |
25 | 35 | ||
26 | testing "$i unknown" "unknown 2>&1" \ | 36 | testing "$i unknown" "$i unknown 2>&1" \ |
27 | "unknown: applet not found\n" "" "" | 37 | "unknown: applet not found\n" "" "" |
28 | 38 | ||
29 | testing "$i --help" "--help 2>&1" "$HELPDUMP\n\n" "" "" | 39 | testing "$i --help" "$i --help 2>&1" "$HELPDUMP\n\n" "" "" |
30 | 40 | ||
31 | optional CAT | 41 | optional CAT |
32 | testing "$i cat" "cat" "moo" "" "moo" | 42 | testing "" "$i cat" "moo" "" "moo" |
33 | testing "$i --help cat" "--help cat 2>&1 | grep prints" \ | 43 | testing "$i --help cat" "$i --help cat 2>&1 | grep prints" \ |
34 | "Concatenates FILE(s) and prints them to stdout.\n" "" "" | 44 | "Concatenates FILE(s) and prints them to stdout.\n" "" "" |
35 | optional "" | 45 | optional "" |
36 | 46 | ||
37 | testing "$i --help unknown" "--help unknown 2>&1" \ | 47 | testing "$i --help unknown" "$i --help unknown 2>&1" \ |
38 | "unknown: applet not found\n" "" "" | 48 | "unknown: applet not found\n" "" "" |
39 | |||
40 | COMMAND=./busybox-suffix | ||
41 | done | 49 | done |
50 | rm busybox-suffix | ||
42 | 51 | ||
43 | COMMAND="./unknown" | 52 | ln -s `which busybox` unknown |
44 | testing "busybox as unknown name" "2>&1" "unknown: applet not found\n" "" "" | ||
45 | |||
46 | rm -f busybox-suffix unknown | ||
47 | |||
48 | |||
49 | # verify the applet order is correct in applets.h | ||
50 | # otherwise applets wont be called properly | ||
51 | sed -n \ | ||
52 | -e '/^\tAPPLET/{s:.*(::;s:,.*::;s:"::g;p}' \ | ||
53 | ../include/applets.h > applet.order.current | ||
54 | LC_ALL=C sort applet.order.current > applet.order.correct | ||
55 | diff -u applet.order.current applet.order.correct | ||
56 | FAILCOUNT=$[$FAILCOUNT+$?] | ||
57 | rm -f applet.order.current applet.order.correct | ||
58 | 53 | ||
54 | testing "busybox as unknown name" "./unknown 2>&1" \ | ||
55 | "unknown: applet not found\n" "" "" | ||
56 | rm unknown | ||
59 | 57 | ||
60 | exit $FAILCOUNT | 58 | exit $FAILCOUNT |
diff --git a/testsuite/egrep.tests b/testsuite/egrep.tests deleted file mode 100755 index 61ce009d7..000000000 --- a/testsuite/egrep.tests +++ /dev/null | |||
@@ -1,19 +0,0 @@ | |||
1 | #!/bin/sh | ||
2 | |||
3 | # egrep tests. | ||
4 | # Copyright 2005 by Rob Landley <rob@landley.net> | ||
5 | # Licensed under GPL v2, see file LICENSE for details. | ||
6 | |||
7 | # AUDIT: | ||
8 | |||
9 | [ ${#COMMAND} -eq 0 ] && COMMAND=egrep | ||
10 | . testing.sh | ||
11 | |||
12 | optional FEATURE_GREP_EGREP_ALIAS | ||
13 | |||
14 | testing "grep is also egrep" "foo" "foo\n" "" "foo\nbar\n" | ||
15 | testing "egrep is not case insensitive" "foo ; [ \$? -ne 0 ] && echo yes" \ | ||
16 | "yes\n" "" "FOO\n" | ||
17 | |||
18 | |||
19 | exit $FAILCOUNT | ||
diff --git a/testsuite/grep.tests b/testsuite/grep.tests index 2a7a7b901..cc9520e90 100755 --- a/testsuite/grep.tests +++ b/testsuite/grep.tests | |||
@@ -6,7 +6,6 @@ | |||
6 | 6 | ||
7 | # AUDIT: | 7 | # AUDIT: |
8 | 8 | ||
9 | [ ${#COMMAND} -eq 0 ] && COMMAND=grep | ||
10 | . testing.sh | 9 | . testing.sh |
11 | 10 | ||
12 | # testing "test name" "options" "expected result" "file input" "stdin" | 11 | # testing "test name" "options" "expected result" "file input" "stdin" |
@@ -15,64 +14,69 @@ | |||
15 | 14 | ||
16 | # Test exit status | 15 | # Test exit status |
17 | 16 | ||
18 | testing "grep (exit with error)" "nonexistent 2> /dev/null ; echo \$?" \ | 17 | testing "grep (exit with error)" "grep nonexistent 2> /dev/null ; echo \$?" \ |
19 | "1\n" "" "" | 18 | "1\n" "" "" |
20 | testing "grep (exit success)" "grep $0 > /dev/null 2>&1 ; echo \$?" "0\n" \ | 19 | testing "grep (exit success)" "grep grep $0 > /dev/null 2>&1 ; echo \$?" "0\n" \ |
21 | "" "" | 20 | "" "" |
22 | # Test various data sources and destinations | 21 | # Test various data sources and destinations |
23 | 22 | ||
24 | testing "grep (default to stdin)" "two" "two\n" "" \ | 23 | testing "grep (default to stdin)" "grep two" "two\n" "" \ |
25 | "one\ntwo\nthree\nthree\nthree\n" | 24 | "one\ntwo\nthree\nthree\nthree\n" |
26 | testing "grep - (specify stdin)" "two -" "two\n" "" \ | 25 | testing "grep - (specify stdin)" "grep two -" "two\n" "" \ |
27 | "one\ntwo\nthree\nthree\nthree\n" | 26 | "one\ntwo\nthree\nthree\nthree\n" |
28 | testing "grep input (specify file)" "two input" "two\n" \ | 27 | testing "grep input (specify file)" "grep two input" "two\n" \ |
29 | "one\ntwo\nthree\nthree\nthree\n" "" | 28 | "one\ntwo\nthree\nthree\nthree\n" "" |
30 | 29 | ||
31 | # Note that this assumes actual is empty. | 30 | # Note that this assumes actual is empty. |
32 | testing "grep input actual (two files)" "two input actual 2> /dev/null" \ | 31 | testing "grep input actual (two files)" "grep two input actual 2> /dev/null" \ |
33 | "input:two\n" "one\ntwo\nthree\nthree\nthree\n" "" | 32 | "input:two\n" "one\ntwo\nthree\nthree\nthree\n" "" |
34 | 33 | ||
35 | testing "grep - infile (specify stdin and file)" "two - input" \ | 34 | testing "grep - infile (specify stdin and file)" "grep two - input" \ |
36 | "(standard input):two\ninput:two\n" "one\ntwo\nthree\n" \ | 35 | "(standard input):two\ninput:two\n" "one\ntwo\nthree\n" \ |
37 | "one\ntwo\ntoo\nthree\nthree\n" | 36 | "one\ntwo\ntoo\nthree\nthree\n" |
38 | 37 | ||
39 | # Check if we see the correct return value if both stdin and non-existing file | 38 | # Check if we see the correct return value if both stdin and non-existing file |
40 | # are given. | 39 | # are given. |
41 | testing "grep - nofile (specify stdin and nonexisting file)" \ | 40 | testing "grep - nofile (specify stdin and nonexisting file)" \ |
42 | "two - nonexistent 2> /dev/null ; echo \$?" \ | 41 | "grep two - nonexistent 2> /dev/null ; echo \$?" \ |
43 | "(standard input):two\n(standard input):two\n2\n" \ | 42 | "(standard input):two\n(standard input):two\n2\n" \ |
44 | "" "one\ntwo\ntwo\nthree\nthree\nthree\n" | 43 | "" "one\ntwo\ntwo\nthree\nthree\nthree\n" |
45 | testing "grep -q - nofile (specify stdin and nonexisting file, no match)" \ | 44 | testing "grep -q - nofile (specify stdin and nonexisting file, no match)" \ |
46 | "-q nomatch - nonexistent 2> /dev/null ; echo \$?" \ | 45 | "grep -q nomatch - nonexistent 2> /dev/null ; echo \$?" \ |
47 | "2\n" "" "one\ntwo\ntwo\nthree\nthree\nthree\n" | 46 | "2\n" "" "one\ntwo\ntwo\nthree\nthree\nthree\n" |
48 | # SUSv3: If the -q option is specified, the exit status shall be zero | 47 | # SUSv3: If the -q option is specified, the exit status shall be zero |
49 | # if an input line is selected, even if an error was detected. | 48 | # if an input line is selected, even if an error was detected. |
50 | testing "grep -q - nofile (specify stdin and nonexisting file, match)" \ | 49 | testing "grep -q - nofile (specify stdin and nonexisting file, match)" \ |
51 | "-q two - nonexistent ; echo \$?" \ | 50 | "grep -q two - nonexistent ; echo \$?" \ |
52 | "0\n" "" "one\ntwo\ntwo\nthree\nthree\nthree\n" | 51 | "0\n" "" "one\ntwo\ntwo\nthree\nthree\nthree\n" |
53 | 52 | ||
54 | # Test various command line options | 53 | # Test various command line options |
55 | # -s no error messages | 54 | # -s no error messages |
56 | testing "grep -s nofile (nonexisting file, no match)" \ | 55 | testing "grep -s nofile (nonexisting file, no match)" \ |
57 | "-s nomatch nonexistent ; echo \$?" "2\n" "" "" | 56 | "grep -s nomatch nonexistent ; echo \$?" "2\n" "" "" |
58 | testing "grep -s nofile - (stdin and nonexisting file, match)" \ | 57 | testing "grep -s nofile - (stdin and nonexisting file, match)" \ |
59 | "-s domatch nonexistent - ; echo \$?" "(standard input):domatch\n2\n" \ | 58 | "grep -s domatch nonexistent - ; echo \$?" \ |
60 | "" "nomatch\ndomatch\nend\n" | 59 | "(standard input):domatch\n2\n" "" "nomatch\ndomatch\nend\n" |
61 | 60 | ||
62 | # This doesn't match GNU behaviour (Binary file input matches) | 61 | # This doesn't match GNU behaviour (Binary file input matches) |
63 | # acts like GNU grep -a | 62 | # acts like GNU grep -a |
64 | testing "grep handles binary files" "foo input" "foo\n" "\0foo\n\n" "" | 63 | testing "grep handles binary files" "grep foo input" "foo\n" "\0foo\n\n" "" |
65 | # This doesn't match GNU behaviour (Binary file (standard input) matches) | 64 | # This doesn't match GNU behaviour (Binary file (standard input) matches) |
66 | # acts like GNU grep -a | 65 | # acts like GNU grep -a |
67 | testing "grep handles binary stdin" "foo" "foo\n" "" "\0foo\n\n" | 66 | testing "grep handles binary stdin" "grep foo" "foo\n" "" "\0foo\n\n" |
68 | 67 | ||
69 | testing "grep matches NUL" ". input > /dev/null 2>&1 ; echo \$?" "0\n" "\0\n" "" | 68 | testing "grep matches NUL" "grep . input > /dev/null 2>&1 ; echo \$?" \ |
69 | "0\n" "\0\n" "" | ||
70 | 70 | ||
71 | # -e regex | 71 | # -e regex |
72 | testing "grep handles multiple regexps" "-e one -e two input ; echo \$?" \ | 72 | testing "grep handles multiple regexps" "grep -e one -e two input ; echo \$?" \ |
73 | "one\ntwo\n0\n" "one\ntwo\n" "" | 73 | "one\ntwo\n0\n" "one\ntwo\n" "" |
74 | 74 | ||
75 | optional FEATURE_GREP_EGREP_ALIAS | 75 | optional FEATURE_GREP_EGREP_ALIAS |
76 | testing "grep -E supports extended regexps" "-E fo+" "foo\n" "" "b\ar\nfoo\nbaz" | 76 | testing "grep -E supports extended regexps" "grep -E fo+" "foo\n" "" \ |
77 | "b\ar\nfoo\nbaz" | ||
78 | testing "grep is also egrep" "egrep foo" "foo\n" "" "foo\nbar\n" | ||
79 | testing "egrep is not case insensitive" \ | ||
80 | "egrep foo ; [ \$? -ne 0 ] && echo yes" "yes\n" "" "FOO\n" | ||
77 | 81 | ||
78 | exit $FAILCOUNT | 82 | exit $FAILCOUNT |
diff --git a/testsuite/pidof.tests b/testsuite/pidof.tests index 0515522f8..831dd2483 100755 --- a/testsuite/pidof.tests +++ b/testsuite/pidof.tests | |||
@@ -6,22 +6,24 @@ | |||
6 | 6 | ||
7 | # AUDIT: | 7 | # AUDIT: |
8 | 8 | ||
9 | [ ${#COMMAND} -eq 0 ] && COMMAND=pidof | ||
10 | . testing.sh | 9 | . testing.sh |
11 | 10 | ||
12 | # testing "test name" "options" "expected result" "file input" "stdin" | 11 | # testing "test name" "options" "expected result" "file input" "stdin" |
13 | 12 | ||
14 | testing "pidof (exit with error)" "veryunlikelyoccuringbinaryname ; echo \$?" \ | 13 | testing "pidof (exit with error)" \ |
15 | "\n1\n" "" "" | 14 | "pidof veryunlikelyoccuringbinaryname ; echo \$?" "1\n" "" "" |
16 | testing "pidof (exit with success)" "pidof > /dev/null; echo \$?" "0\n" "" "" | 15 | testing "pidof (exit with success)" "pidof pidof > /dev/null; echo \$?" \ |
16 | "0\n" "" "" | ||
17 | # We can get away with this because it says #!/bin/sh up top. | ||
17 | 18 | ||
19 | testing "pidof this" "pidof pidof.tests | grep -o -w $$" "$$\n" "" "" | ||
18 | 20 | ||
19 | optional FEATURE_PIDOF_SINGLE | 21 | optional FEATURE_PIDOF_SINGLE |
20 | testing "pidof -s" "-s $(basename $0) ; echo -n \$?" \ | 22 | testing "pidof -s" "pidof -s init" "1\n" "" "" |
21 | "$(pidof -s $(basename $0) ; echo -n $?)" "" "" | ||
22 | 23 | ||
23 | optional FEATURE_PIDOF_OMIT | 24 | optional FEATURE_PIDOF_OMIT |
24 | testing "pidof -o %PPID" "$(basename $0) -o %PPID ; echo -n \$?" \ | 25 | testing "pidof -o %PPID" "pidof -o %PPID pidof.tests | grep -o -w $$" "" "" "" |
25 | "$(pidof $(basename $0) -o %PPID ; echo -n $?)" "" "" | 26 | testing "pidof -o %PPID NOP" "pidof -o %PPID -s init" "1\n" "" "" |
27 | testing "pidof -o init" "pidof -o 1 init | grep -o -w 1" "" "" "" | ||
26 | 28 | ||
27 | exit $FAILCOUNT | 29 | exit $FAILCOUNT |
diff --git a/testsuite/sed.tests b/testsuite/sed.tests index 6fcaa19df..4d6e2e67e 100755 --- a/testsuite/sed.tests +++ b/testsuite/sed.tests | |||
@@ -4,16 +4,15 @@ | |||
4 | # Copyright 2005 by Rob Landley <rob@landley.net> | 4 | # Copyright 2005 by Rob Landley <rob@landley.net> |
5 | # Licensed under GPL v2, see file LICENSE for details. | 5 | # Licensed under GPL v2, see file LICENSE for details. |
6 | 6 | ||
7 | [ -z "$COMMAND" ] && COMMAND=sed | ||
8 | . testing.sh | 7 | . testing.sh |
9 | 8 | ||
10 | # testing "description" "arguments" "result" "infile" "stdin" | 9 | # testing "description" "arguments" "result" "infile" "stdin" |
11 | 10 | ||
12 | # Corner cases | 11 | # Corner cases |
13 | testing "sed no files (stdin)" '""' "hello\n" "" "hello\n" | 12 | testing "sed no files (stdin)" 'sed ""' "hello\n" "" "hello\n" |
14 | testing "sed explicit stdin" '"" -' "hello\n" "" "hello\n" | 13 | testing "sed explicit stdin" 'sed "" -' "hello\n" "" "hello\n" |
15 | testing "sed handles empty lines" "-e 's/\$/@/'" "@\n" "" "\n" | 14 | testing "sed handles empty lines" "sed -e 's/\$/@/'" "@\n" "" "\n" |
16 | testing "sed stdin twice" '"" - -' "hello" "" "hello" | 15 | testing "sed stdin twice" 'sed "" - -' "hello" "" "hello" |
17 | 16 | ||
18 | # Trailing EOF. | 17 | # Trailing EOF. |
19 | # Match $, at end of each file or all files? | 18 | # Match $, at end of each file or all files? |
@@ -39,139 +38,145 @@ testing "sed stdin twice" '"" - -' "hello" "" "hello" | |||
39 | # End of script with trailing \ | 38 | # End of script with trailing \ |
40 | 39 | ||
41 | # command list | 40 | # command list |
42 | testing "sed accepts blanks before command" "-e '1 d'" "" "" "" | 41 | testing "sed accepts blanks before command" "sed -e '1 d'" "" "" "" |
43 | testing "sed accepts newlines in -e" "-e 'i\ | 42 | testing "sed accepts newlines in -e" "sed -e 'i\ |
44 | 1 | 43 | 1 |
45 | a\ | 44 | a\ |
46 | 3'" "1\n2\n3\n" "" "2\n" | 45 | 3'" "1\n2\n3\n" "" "2\n" |
47 | testing "sed accepts multiple -e" "-e 'i\' -e '1' -e 'a\' -e '3'" \ | 46 | testing "sed accepts multiple -e" "sed -e 'i\' -e '1' -e 'a\' -e '3'" \ |
48 | "1\n2\n3\n" "" "2\n" | 47 | "1\n2\n3\n" "" "2\n" |
49 | 48 | ||
50 | # substitutions | 49 | # substitutions |
51 | testing "sed -n" "-n -e s/foo/bar/ -e s/bar/baz/" "" "" "foo\n" | 50 | testing "sed -n" "sed -n -e s/foo/bar/ -e s/bar/baz/" "" "" "foo\n" |
52 | testing "sed s//p" "-e s/foo/bar/p -e s/bar/baz/p" "bar\nbaz\nbaz\n" \ | 51 | testing "sed s//p" "sed -e s/foo/bar/p -e s/bar/baz/p" "bar\nbaz\nbaz\n" \ |
53 | "" "foo\n" | 52 | "" "foo\n" |
54 | testing "sed -n s//p" "-ne s/abc/def/p" "def\n" "" "abc\n" | 53 | testing "sed -n s//p" "sed -ne s/abc/def/p" "def\n" "" "abc\n" |
55 | testing "sed s//g (exhaustive)" "-e 's/[[:space:]]*/,/g'" ",1,2,3,4,5,\n" \ | 54 | testing "sed s//g (exhaustive)" "sed -e 's/[[:space:]]*/,/g'" ",1,2,3,4,5,\n" \ |
56 | "" "12345\n" | 55 | "" "12345\n" |
57 | testing "sed s arbitrary delimiter" "-e 's woo boing '" "boing\n" "" "woo\n" | 56 | testing "sed s arbitrary delimiter" "sed -e 's woo boing '" "boing\n" "" "woo\n" |
58 | testing "sed s chains" "-e s/foo/bar/ -e s/bar/baz/" "baz\n" "" "foo\n" | 57 | testing "sed s chains" "sed -e s/foo/bar/ -e s/bar/baz/" "baz\n" "" "foo\n" |
59 | testing "sed s chains2" "-e s/foo/bar/ -e s/baz/nee/" "bar\n" "" "foo\n" | 58 | testing "sed s chains2" "sed -e s/foo/bar/ -e s/baz/nee/" "bar\n" "" "foo\n" |
60 | testing "sed s [delimiter]" "-e 's@[@]@@'" "onetwo" "" "one@two" | 59 | testing "sed s [delimiter]" "sed -e 's@[@]@@'" "onetwo" "" "one@two" |
61 | 60 | ||
62 | # branch | 61 | # branch |
63 | testing "sed b (branch)" "-e 'b one;p;: one'" "foo\n" "" "foo\n" | 62 | testing "sed b (branch)" "sed -e 'b one;p;: one'" "foo\n" "" "foo\n" |
64 | testing "sed b (branch with no label jumps to end)" "-e 'b;p'" \ | 63 | testing "sed b (branch with no label jumps to end)" "sed -e 'b;p'" \ |
65 | "foo\n" "" "foo\n" | 64 | "foo\n" "" "foo\n" |
66 | 65 | ||
67 | # test and branch | 66 | # test and branch |
68 | testing "sed t (test/branch)" "-e 's/a/1/;t one;p;: one;p'" \ | 67 | testing "sed t (test/branch)" "sed -e 's/a/1/;t one;p;: one;p'" \ |
69 | "1\n1\nb\nb\nb\nc\nc\nc\n" "" "a\nb\nc\n" | 68 | "1\n1\nb\nb\nb\nc\nc\nc\n" "" "a\nb\nc\n" |
70 | testing "sed t (test/branch clears test bit)" "-e 's/a/b/;:loop;t loop'" \ | 69 | testing "sed t (test/branch clears test bit)" "sed -e 's/a/b/;:loop;t loop'" \ |
71 | "b\nb\nc\n" "" "a\nb\nc\n" | 70 | "b\nb\nc\n" "" "a\nb\nc\n" |
72 | testing "sed T (!test/branch)" "-e 's/a/1/;T notone;p;: notone;p'" \ | 71 | testing "sed T (!test/branch)" "sed -e 's/a/1/;T notone;p;: notone;p'" \ |
73 | "1\n1\n1\nb\nb\nc\nc\n" "" "a\nb\nc\n" | 72 | "1\n1\n1\nb\nb\nc\nc\n" "" "a\nb\nc\n" |
74 | 73 | ||
75 | # Normal sed end-of-script doesn't print "c" because n flushed the pattern | 74 | # Normal sed end-of-script doesn't print "c" because n flushed the pattern |
76 | # space. If n hits EOF, pattern space is empty when script ends. | 75 | # space. If n hits EOF, pattern space is empty when script ends. |
77 | # Query: how does this interact with no newline at EOF? | 76 | # Query: how does this interact with no newline at EOF? |
78 | testing "sed n (flushes pattern space, terminates early)" "-e 'n;p'" \ | 77 | testing "sed n (flushes pattern space, terminates early)" "sed -e 'n;p'" \ |
79 | "a\nb\nb\nc\n" "" "a\nb\nc\n" | 78 | "a\nb\nb\nc\n" "" "a\nb\nc\n" |
80 | # N does _not_ flush pattern space, therefore c is still in there @ script end. | 79 | # N does _not_ flush pattern space, therefore c is still in there @ script end. |
81 | testing "sed N (doesn't flush pattern space when terminating)" "-e 'N;p'" \ | 80 | testing "sed N (doesn't flush pattern space when terminating)" "sed -e 'N;p'" \ |
82 | "a\nb\na\nb\nc\n" "" "a\nb\nc\n" | 81 | "a\nb\na\nb\nc\n" "" "a\nb\nc\n" |
83 | testing "sed address match newline" '"/b/N;/b\\nc/i woo"' "a\nwoo\nb\nc\nd\n" \ | 82 | testing "sed address match newline" 'sed "/b/N;/b\\nc/i woo"' \ |
84 | "" "a\nb\nc\nd\n" | 83 | "a\nwoo\nb\nc\nd\n" "" "a\nb\nc\nd\n" |
85 | 84 | ||
86 | # Multiple lines in pattern space | 85 | # Multiple lines in pattern space |
87 | testing "sed N (stops at end of input) and P (prints to first newline only)" \ | 86 | testing "sed N (stops at end of input) and P (prints to first newline only)" \ |
88 | "-n 'N;P;p'" "a\na\nb\n" "" "a\nb\nc\n" | 87 | "sed -n 'N;P;p'" "a\na\nb\n" "" "a\nb\nc\n" |
89 | 88 | ||
90 | # Hold space | 89 | # Hold space |
91 | testing "sed G (append hold space to pattern space)" 'G' "a\n\nb\n\nc\n\n" \ | 90 | testing "sed G (append hold space to pattern space)" 'sed G' "a\n\nb\n\nc\n\n" \ |
92 | "" "a\nb\nc\n" | 91 | "" "a\nb\nc\n" |
93 | #testing "sed g/G (swap/append hold and patter space)" | 92 | #testing "sed g/G (swap/append hold and patter space)" |
94 | #testing "sed g (swap hold/pattern space)" | 93 | #testing "sed g (swap hold/pattern space)" |
95 | 94 | ||
96 | testing "sed d ends script iteration" \ | 95 | testing "sed d ends script iteration" \ |
97 | "-e '/ook/d;s/ook/ping/p;i woot'" "" "" "ook\n" | 96 | "sed -e '/ook/d;s/ook/ping/p;i woot'" "" "" "ook\n" |
98 | testing "sed d ends script iteration (2)" \ | 97 | testing "sed d ends script iteration (2)" \ |
99 | "-e '/ook/d;a\' -e 'bang'" "woot\nbang\n" "" "ook\nwoot\n" | 98 | "sed -e '/ook/d;a\' -e 'bang'" "woot\nbang\n" "" "ook\nwoot\n" |
100 | 99 | ||
101 | # Multiple files, with varying newlines and NUL bytes | 100 | # Multiple files, with varying newlines and NUL bytes |
102 | testing "sed embedded NUL" "-e 's/woo/bang/'" "\0bang\0woo\0" "" "\0woo\0woo\0" | 101 | testing "sed embedded NUL" "sed -e 's/woo/bang/'" "\0bang\0woo\0" "" \ |
103 | testing "sed embedded NUL g" "-e 's/woo/bang/g'" "bang\0bang\0" "" "woo\0woo\0" | 102 | "\0woo\0woo\0" |
103 | testing "sed embedded NUL g" "sed -e 's/woo/bang/g'" "bang\0bang\0" "" \ | ||
104 | "woo\0woo\0" | ||
104 | echo -e "/woo/a he\0llo" > sed.commands | 105 | echo -e "/woo/a he\0llo" > sed.commands |
105 | testing "sed NUL in command" "-f sed.commands" "woo\nhe\0llo\n" "" "woo" | 106 | testing "sed NUL in command" "sed -f sed.commands" "woo\nhe\0llo\n" "" "woo" |
106 | rm sed.commands | 107 | rm sed.commands |
107 | 108 | ||
108 | # sed has funky behavior with newlines at the end of file. Test lots of | 109 | # sed has funky behavior with newlines at the end of file. Test lots of |
109 | # corner cases with the optional newline appending behavior. | 110 | # corner cases with the optional newline appending behavior. |
110 | 111 | ||
111 | testing "sed normal newlines" "-e 's/woo/bang/' input -" "bang\nbang\n" \ | 112 | testing "sed normal newlines" "sed -e 's/woo/bang/' input -" "bang\nbang\n" \ |
112 | "woo\n" "woo\n" | 113 | "woo\n" "woo\n" |
113 | testing "sed leave off trailing newline" "-e 's/woo/bang/' input -" \ | 114 | testing "sed leave off trailing newline" "sed -e 's/woo/bang/' input -" \ |
114 | "bang\nbang" "woo\n" "woo" | 115 | "bang\nbang" "woo\n" "woo" |
115 | testing "sed autoinsert newline" "-e 's/woo/bang/' input -" "bang\nbang" \ | 116 | testing "sed autoinsert newline" "sed -e 's/woo/bang/' input -" "bang\nbang" \ |
116 | "woo" "woo" | 117 | "woo" "woo" |
117 | testing "sed empty file plus cat" "-e 's/nohit//' input -" "one\ntwo" \ | 118 | testing "sed empty file plus cat" "sed -e 's/nohit//' input -" "one\ntwo" \ |
118 | "" "one\ntwo" | 119 | "" "one\ntwo" |
119 | testing "sed cat plus empty file" "-e 's/nohit//' input -" "one\ntwo" \ | 120 | testing "sed cat plus empty file" "sed -e 's/nohit//' input -" "one\ntwo" \ |
120 | "one\ntwo" "" | 121 | "one\ntwo" "" |
121 | testing "sed append autoinserts newline" "-e '/woot/a woo' -" "woot\nwoo\n" \ | 122 | testing "sed append autoinserts newline" "sed -e '/woot/a woo' -" \ |
122 | "" "woot" | 123 | "woot\nwoo\n" "" "woot" |
123 | testing "sed insert doesn't autoinsert newline" "-e '/woot/i woo' -" \ | 124 | testing "sed insert doesn't autoinsert newline" "sed -e '/woot/i woo' -" \ |
124 | "woo\nwoot" "" "woot" | 125 | "woo\nwoot" "" "woot" |
125 | testing "sed print autoinsert newlines" "-e 'p' -" "one\none" "" "one" | 126 | testing "sed print autoinsert newlines" "sed -e 'p' -" "one\none" "" "one" |
126 | testing "sed print autoinsert newlines two files" "-e 'p' input -" \ | 127 | testing "sed print autoinsert newlines two files" "sed -e 'p' input -" \ |
127 | "one\none\ntwo\ntwo" "one" "two" | 128 | "one\none\ntwo\ntwo" "one" "two" |
128 | testing "sed noprint, no match, no newline" "-ne 's/woo/bang/' input" \ | 129 | testing "sed noprint, no match, no newline" "sed -ne 's/woo/bang/' input" \ |
129 | "" "no\n" "" | 130 | "" "no\n" "" |
130 | testing "sed selective matches with one nl" "-ne 's/woo/bang/p' input -" \ | 131 | testing "sed selective matches with one nl" "sed -ne 's/woo/bang/p' input -" \ |
131 | "a bang\nc bang\n" "a woo\nb no" "c woo\nd no" | 132 | "a bang\nc bang\n" "a woo\nb no" "c woo\nd no" |
132 | testing "sed selective matches insert newline" "-ne 's/woo/bang/p' input -" \ | 133 | testing "sed selective matches insert newline" \ |
133 | "a bang\nb bang\nd bang" "a woo\nb woo" "c no\nd woo" | 134 | "sed -ne 's/woo/bang/p' input -" "a bang\nb bang\nd bang" \ |
134 | testing "sed selective matches noinsert newline" "-ne 's/woo/bang/p' input -" \ | 135 | "a woo\nb woo" "c no\nd woo" |
135 | "a bang\nb bang" "a woo\nb woo" "c no\nd no" | 136 | testing "sed selective matches noinsert newline" \ |
136 | testing "sed clusternewline" "-e '/one/a 111' -e '/two/i 222' -e p input -" \ | 137 | "sed -ne 's/woo/bang/p' input -" "a bang\nb bang" "a woo\nb woo" \ |
138 | "c no\nd no" | ||
139 | testing "sed clusternewline" \ | ||
140 | "sed -e '/one/a 111' -e '/two/i 222' -e p input -" \ | ||
137 | "one\none\n111\n222\ntwo\ntwo" "one" "two" | 141 | "one\none\n111\n222\ntwo\ntwo" "one" "two" |
138 | 142 | ||
139 | # Test end-of-file matching behavior | 143 | # Test end-of-file matching behavior |
140 | 144 | ||
141 | testing "sed match EOF" " -e '"'$p'"'" "hello\nthere\nthere" "" "hello\nthere" | 145 | testing "sed match EOF" "sed -e '"'$p'"'" "hello\nthere\nthere" "" \ |
142 | testing "sed match EOF two files" " -e '"'$p'"' input -" \ | 146 | "hello\nthere" |
147 | testing "sed match EOF two files" "sed -e '"'$p'"' input -" \ | ||
143 | "one\ntwo\nthree\nfour\nfour" "one\ntwo" "three\nfour" | 148 | "one\ntwo\nthree\nfour\nfour" "one\ntwo" "three\nfour" |
144 | echo -ne "three\nfour" > input2 | 149 | echo -ne "three\nfour" > input2 |
145 | testing "sed match EOF inline" \ | 150 | testing "sed match EOF inline" \ |
146 | " -e '"'$i ook'"' -i input input2 && cat input input2" \ | 151 | "sed -e '"'$i ook'"' -i input input2 && cat input input2" \ |
147 | "one\nook\ntwothree\nook\nfour" "one\ntwo" "" | 152 | "one\nook\ntwothree\nook\nfour" "one\ntwo" "" |
148 | rm input2 | 153 | rm input2 |
149 | 154 | ||
150 | # Test lie-to-autoconf | 155 | # Test lie-to-autoconf |
151 | 156 | ||
152 | testing "sed lie-to-autoconf" "--version | grep -o 'GNU sed version '" \ | 157 | testing "sed lie-to-autoconf" "sed --version | grep -o 'GNU sed version '" \ |
153 | "GNU sed version \n" "" "" | 158 | "GNU sed version \n" "" "" |
154 | 159 | ||
155 | # Jump to nonexistent label | 160 | # Jump to nonexistent label |
156 | testing "sed nonexistent label" "-e 'b walrus' 2> /dev/null || echo yes" \ | 161 | testing "sed nonexistent label" "sed -e 'b walrus' 2> /dev/null || echo yes" \ |
157 | "yes\n" "" "" | 162 | "yes\n" "" "" |
158 | 163 | ||
159 | testing "sed backref from empty s uses range regex" \ | 164 | testing "sed backref from empty s uses range regex" \ |
160 | "-e '/woot/s//eep \0 eep/'" "eep woot eep" "" "woot" | 165 | "sed -e '/woot/s//eep \0 eep/'" "eep woot eep" "" "woot" |
161 | 166 | ||
162 | testing "sed backref from empty s uses range regex with newline" \ | 167 | testing "sed backref from empty s uses range regex with newline" \ |
163 | "-e '/woot/s//eep \0 eep/'" "eep woot eep\n" "" "woot\n" | 168 | "sed -e '/woot/s//eep \0 eep/'" "eep woot eep\n" "" "woot\n" |
164 | 169 | ||
165 | # -i with no filename | 170 | # -i with no filename |
166 | 171 | ||
167 | touch ./- # Detect gnu failure mode here. | 172 | touch ./- # Detect gnu failure mode here. |
168 | testing "sed -i with no arg [GNUFAIL]" "-e '' -i 2> /dev/null || echo yes" \ | 173 | testing "sed -i with no arg [GNUFAIL]" "sed -e '' -i 2> /dev/null || echo yes" \ |
169 | "yes\n" "" "" | 174 | "yes\n" "" "" |
170 | rm ./- # Clean up | 175 | rm ./- # Clean up |
171 | 176 | ||
172 | # Ponder this a bit more, why "woo not found" from gnu version? | 177 | # Ponder this a bit more, why "woo not found" from gnu version? |
173 | #testing "sed doesn't substitute in deleted line" \ | 178 | #testing "sed doesn't substitute in deleted line" \ |
174 | # "-e '/ook/d;s/ook//;t woo;a bang;'" "bang" "" "ook\n" | 179 | # "sed -e '/ook/d;s/ook//;t woo;a bang;'" "bang" "" "ook\n" |
175 | 180 | ||
176 | # This makes both seds very unhappy. Why? | 181 | # This makes both seds very unhappy. Why? |
177 | #testing "sed -g (exhaustive)" "sed -e 's/[[:space:]]*/,/g'" ",1,2,3,4,5," \ | 182 | #testing "sed -g (exhaustive)" "sed -e 's/[[:space:]]*/,/g'" ",1,2,3,4,5," \ |
diff --git a/testsuite/sort.tests b/testsuite/sort.tests index 294530988..d1b42532d 100755 --- a/testsuite/sort.tests +++ b/testsuite/sort.tests | |||
@@ -4,16 +4,15 @@ | |||
4 | # Copyright 2005 by Rob Landley <rob@landley.net> | 4 | # Copyright 2005 by Rob Landley <rob@landley.net> |
5 | # Licensed under GPL v2, see file LICENSE for details. | 5 | # Licensed under GPL v2, see file LICENSE for details. |
6 | 6 | ||
7 | if [ ${#COMMAND} -eq 0 ]; then COMMAND=sort; fi | ||
8 | . testing.sh | 7 | . testing.sh |
9 | 8 | ||
10 | # The basic tests. These should work even with the small busybox. | 9 | # The basic tests. These should work even with the small busybox. |
11 | 10 | ||
12 | testing "sort" "input" "a\nb\nc\n" "c\na\nb\n" "" | 11 | testing "sort" "sort input" "a\nb\nc\n" "c\na\nb\n" "" |
13 | testing "sort #2" "input" "010\n1\n3\n" "3\n1\n010\n" "" | 12 | testing "sort #2" "sort input" "010\n1\n3\n" "3\n1\n010\n" "" |
14 | testing "sort stdin" "" "a\nb\nc\n" "" "b\na\nc\n" | 13 | testing "sort stdin" "sort" "a\nb\nc\n" "" "b\na\nc\n" |
15 | testing "sort numeric" "-n input" "1\n3\n010\n" "3\n1\n010\n" "" | 14 | testing "sort numeric" "sort -n input" "1\n3\n010\n" "3\n1\n010\n" "" |
16 | testing "sort reverse" "-r input" "wook\nwalrus\npoint\npabst\naargh\n" \ | 15 | testing "sort reverse" "sort -r input" "wook\nwalrus\npoint\npabst\naargh\n" \ |
17 | "point\nwook\npabst\naargh\nwalrus\n" "" | 16 | "point\nwook\npabst\naargh\nwalrus\n" "" |
18 | 17 | ||
19 | # These tests require the full option set. | 18 | # These tests require the full option set. |
@@ -30,7 +29,7 @@ egg 1 2 papyrus | |||
30 | 29 | ||
31 | # Sorting with keys | 30 | # Sorting with keys |
32 | 31 | ||
33 | testing "sort one key" "-k4,4 input" \ | 32 | testing "sort one key" "sort -k4,4 input" \ |
34 | "999 3 0 algebra | 33 | "999 3 0 algebra |
35 | egg 1 2 papyrus | 34 | egg 1 2 papyrus |
36 | 7 3 42 soup | 35 | 7 3 42 soup |
@@ -38,7 +37,7 @@ egg 1 2 papyrus | |||
38 | 42 1 010 zoology | 37 | 42 1 010 zoology |
39 | " "$data" "" | 38 | " "$data" "" |
40 | 39 | ||
41 | testing "sort key range with numeric option" "-k2,3n input" \ | 40 | testing "sort key range with numeric option" "sort -k2,3n input" \ |
42 | "42 1 010 zoology | 41 | "42 1 010 zoology |
43 | 42 1 3 woot | 42 | 42 1 3 woot |
44 | egg 1 2 papyrus | 43 | egg 1 2 papyrus |
@@ -49,7 +48,7 @@ egg 1 2 papyrus | |||
49 | # Busybox is definitely doing this one wrong just now. FIXME | 48 | # Busybox is definitely doing this one wrong just now. FIXME |
50 | 49 | ||
51 | testing "sort key range with numeric option and global reverse" \ | 50 | testing "sort key range with numeric option and global reverse" \ |
52 | "-k2,3n -r input" \ | 51 | "sort -k2,3n -r input" \ |
53 | "egg 1 2 papyrus | 52 | "egg 1 2 papyrus |
54 | 42 1 3 woot | 53 | 42 1 3 woot |
55 | 42 1 010 zoology | 54 | 42 1 010 zoology |
@@ -59,7 +58,7 @@ testing "sort key range with numeric option and global reverse" \ | |||
59 | 58 | ||
60 | # | 59 | # |
61 | 60 | ||
62 | testing "sort key range with multiple options" "-k2,3rn input" \ | 61 | testing "sort key range with multiple options" "sort -k2,3rn input" \ |
63 | "7 3 42 soup | 62 | "7 3 42 soup |
64 | 999 3 0 algebra | 63 | 999 3 0 algebra |
65 | 42 1 010 zoology | 64 | 42 1 010 zoology |
diff --git a/testsuite/testing.sh b/testsuite/testing.sh index 08f4200c5..bec5976e1 100755 --- a/testsuite/testing.sh +++ b/testsuite/testing.sh | |||
@@ -56,45 +56,41 @@ optional() | |||
56 | 56 | ||
57 | testing () | 57 | testing () |
58 | { | 58 | { |
59 | NAME="$1" | ||
60 | [ -z "$1" ] && NAME=$2 | ||
61 | |||
59 | if [ $# -ne 5 ] | 62 | if [ $# -ne 5 ] |
60 | then | 63 | then |
61 | echo "Test $1 has the wrong number of arguments ($# $*)" >&2 | 64 | echo "Test $NAME has the wrong number of arguments ($# $*)" >&2 |
62 | exit | 65 | exit |
63 | fi | 66 | fi |
64 | 67 | ||
65 | if [ -n "$DEBUG" ] ; then | 68 | [ -n "$DEBUG" ] && set -x |
66 | set -x | ||
67 | fi | ||
68 | 69 | ||
69 | if [ -n "$SKIP" ] | 70 | if [ -n "$SKIP" ] |
70 | then | 71 | then |
71 | echo "SKIPPED: $1" | 72 | echo "SKIPPED: $NAME" |
72 | return 0 | 73 | return 0 |
73 | fi | 74 | fi |
74 | 75 | ||
75 | echo -ne "$3" > expected | 76 | echo -ne "$3" > expected |
76 | echo -ne "$4" > input | 77 | echo -ne "$4" > input |
77 | echo -ne "$5" | eval "$COMMAND $2" > actual | 78 | [ -z "$VERBOSE" ] || echo "echo '$5' | $COMMAND $2" |
79 | echo -ne "$5" | eval "$2" > actual | ||
78 | RETVAL=$? | 80 | RETVAL=$? |
79 | 81 | ||
80 | cmp expected actual > /dev/null | 82 | cmp expected actual > /dev/null |
81 | if [ $? -ne 0 ] | 83 | if [ $? -ne 0 ] |
82 | then | 84 | then |
83 | FAILCOUNT=$[$FAILCOUNT+1] | 85 | FAILCOUNT=$[$FAILCOUNT+1] |
84 | echo "FAIL: $1" | 86 | echo "FAIL: $NAME" |
85 | if [ -n "$VERBOSE" ] | 87 | [ -n "$VERBOSE" ] && diff -u expected actual |
86 | then | ||
87 | diff -u expected actual | ||
88 | fi | ||
89 | else | 88 | else |
90 | echo "PASS: $1" | 89 | echo "PASS: $NAME" |
91 | fi | 90 | fi |
92 | rm -f input expected actual | 91 | rm -f input expected actual |
93 | 92 | ||
94 | if [ -n "$DEBUG" ] | 93 | [ -n "$DEBUG" ] && set +x |
95 | then | ||
96 | set +x | ||
97 | fi | ||
98 | 94 | ||
99 | return $RETVAL | 95 | return $RETVAL |
100 | } | 96 | } |
@@ -108,6 +104,8 @@ function mkchroot | |||
108 | { | 104 | { |
109 | [ $# -lt 2 ] && return | 105 | [ $# -lt 2 ] && return |
110 | 106 | ||
107 | echo -n . | ||
108 | |||
111 | dest=$1 | 109 | dest=$1 |
112 | shift | 110 | shift |
113 | for i in "$@" | 111 | for i in "$@" |
@@ -119,9 +117,38 @@ function mkchroot | |||
119 | mkdir -p "$dest/$d" && | 117 | mkdir -p "$dest/$d" && |
120 | cat "$i" > "$dest/$i" && | 118 | cat "$i" > "$dest/$i" && |
121 | chmod +x "$dest/$i" | 119 | chmod +x "$dest/$i" |
122 | else | ||
123 | i="$dest/$i" | ||
124 | fi | 120 | fi |
125 | mkchroot "$dest" $(ldd "$i" | egrep -o '/.* ') | 121 | mkchroot "$dest" $(ldd "$i" | egrep -o '/.* ') |
126 | done | 122 | done |
127 | } | 123 | } |
124 | |||
125 | # Set up a chroot environment and run commands within it. | ||
126 | # Needed commands listed on command line | ||
127 | # Script fed to stdin. | ||
128 | |||
129 | function dochroot | ||
130 | { | ||
131 | mkdir tmpdir4chroot | ||
132 | mount -t ramfs tmpdir4chroot tmpdir4chroot | ||
133 | mkdir -p tmpdir4chroot/{etc,sys,proc,tmp,dev} | ||
134 | cp -L testing.sh tmpdir4chroot | ||
135 | |||
136 | # Copy utilities from command line arguments | ||
137 | |||
138 | echo -n "Setup chroot" | ||
139 | mkchroot tmpdir4chroot $* | ||
140 | echo | ||
141 | |||
142 | mknod tmpdir4chroot/dev/tty c 5 0 | ||
143 | mknod tmpdir4chroot/dev/null c 1 3 | ||
144 | mknod tmpdir4chroot/dev/zero c 1 5 | ||
145 | |||
146 | # Copy script from stdin | ||
147 | |||
148 | cat > tmpdir4chroot/test.sh | ||
149 | chmod +x tmpdir4chroot/test.sh | ||
150 | chroot tmpdir4chroot /test.sh | ||
151 | umount -l tmpdir4chroot | ||
152 | rmdir tmpdir4chroot | ||
153 | } | ||
154 | |||
diff --git a/testsuite/uniq.tests b/testsuite/uniq.tests index 95764740b..a1b69c2e5 100755 --- a/testsuite/uniq.tests +++ b/testsuite/uniq.tests | |||
@@ -6,7 +6,6 @@ | |||
6 | 6 | ||
7 | # AUDIT: Full SUSv3 coverage (except internationalization). | 7 | # AUDIT: Full SUSv3 coverage (except internationalization). |
8 | 8 | ||
9 | if [ ${#COMMAND} -eq 0 ]; then COMMAND=uniq; fi | ||
10 | . testing.sh | 9 | . testing.sh |
11 | 10 | ||
12 | # testing "test name" "options" "expected result" "file input" "stdin" | 11 | # testing "test name" "options" "expected result" "file input" "stdin" |
@@ -15,25 +14,25 @@ if [ ${#COMMAND} -eq 0 ]; then COMMAND=uniq; fi | |||
15 | 14 | ||
16 | # Test exit status | 15 | # Test exit status |
17 | 16 | ||
18 | testing "uniq (exit with error)" "nonexistent 2> /dev/null || echo yes" \ | 17 | testing "uniq (exit with error)" "uniq nonexistent 2> /dev/null || echo yes" \ |
19 | "yes\n" "" "" | 18 | "yes\n" "" "" |
20 | testing "uniq (exit success)" "/dev/null && echo yes" "yes\n" "" "" | 19 | testing "uniq (exit success)" "uniq /dev/null && echo yes" "yes\n" "" "" |
21 | 20 | ||
22 | # Test various data sources and destinations | 21 | # Test various data sources and destinations |
23 | 22 | ||
24 | testing "uniq (default to stdin)" "" "one\ntwo\nthree\n" "" \ | 23 | testing "uniq (default to stdin)" "uniq" "one\ntwo\nthree\n" "" \ |
25 | "one\ntwo\ntwo\nthree\nthree\nthree\n" | 24 | "one\ntwo\ntwo\nthree\nthree\nthree\n" |
26 | testing "uniq - (specify stdin)" "-" "one\ntwo\nthree\n" "" \ | 25 | testing "uniq - (specify stdin)" "uniq -" "one\ntwo\nthree\n" "" \ |
27 | "one\ntwo\ntwo\nthree\nthree\nthree\n" | 26 | "one\ntwo\ntwo\nthree\nthree\nthree\n" |
28 | testing "uniq input (specify file)" "input" "one\ntwo\nthree\n" \ | 27 | testing "uniq input (specify file)" "uniq input" "one\ntwo\nthree\n" \ |
29 | "one\ntwo\ntwo\nthree\nthree\nthree\n" "" | 28 | "one\ntwo\ntwo\nthree\nthree\nthree\n" "" |
30 | 29 | ||
31 | testing "uniq input outfile (two files)" "input actual > /dev/null" \ | 30 | testing "uniq input outfile (two files)" "uniq input actual > /dev/null" \ |
32 | "one\ntwo\nthree\n" "one\ntwo\ntwo\nthree\nthree\nthree\n" "" | 31 | "one\ntwo\nthree\n" "one\ntwo\ntwo\nthree\nthree\nthree\n" "" |
33 | testing "uniq (stdin) outfile" "- actual" \ | 32 | testing "uniq (stdin) outfile" "uniq - actual" \ |
34 | "one\ntwo\nthree\n" "" "one\ntwo\ntwo\nthree\nthree\nthree\n" | 33 | "one\ntwo\nthree\n" "" "one\ntwo\ntwo\nthree\nthree\nthree\n" |
35 | # Note: SUSv3 doesn't seem to require support for "-" output, but we do anyway. | 34 | # Note: SUSv3 doesn't seem to require support for "-" output, but we do anyway. |
36 | testing "uniq input - (specify stdout)" "input -" \ | 35 | testing "uniq input - (specify stdout)" "uniq input -" \ |
37 | "one\ntwo\nthree\n" "one\ntwo\ntwo\nthree\nthree\nthree\n" "" | 36 | "one\ntwo\nthree\n" "one\ntwo\ntwo\nthree\nthree\nthree\n" "" |
38 | 37 | ||
39 | 38 | ||
@@ -47,13 +46,13 @@ testing "uniq input - (specify stdout)" "input -" \ | |||
47 | 46 | ||
48 | # Leading whitespace is a minor technical violation of the spec, | 47 | # Leading whitespace is a minor technical violation of the spec, |
49 | # but since gnu does it... | 48 | # but since gnu does it... |
50 | testing "uniq -c (occurrence count)" "-c | sed 's/^[ \t]*//'" \ | 49 | testing "uniq -c (occurrence count)" "uniq -c | sed 's/^[ \t]*//'" \ |
51 | "1 one\n2 two\n3 three\n" "" \ | 50 | "1 one\n2 two\n3 three\n" "" \ |
52 | "one\ntwo\ntwo\nthree\nthree\nthree\n" | 51 | "one\ntwo\ntwo\nthree\nthree\nthree\n" |
53 | testing "uniq -d (dups only) " "-d" "two\nthree\n" "" \ | 52 | testing "uniq -d (dups only) " "uniq -d" "two\nthree\n" "" \ |
54 | "one\ntwo\ntwo\nthree\nthree\nthree\n" | 53 | "one\ntwo\ntwo\nthree\nthree\nthree\n" |
55 | 54 | ||
56 | testing "uniq -f -s (skip fields and chars)" "-f2 -s 3" \ | 55 | testing "uniq -f -s (skip fields and chars)" "uniq -f2 -s 3" \ |
57 | "cc dd ee8 | 56 | "cc dd ee8 |
58 | aa bb cc9 | 57 | aa bb cc9 |
59 | " "" \ | 58 | " "" \ |
@@ -65,7 +64,7 @@ aa bb cc9 | |||
65 | # -d is "Suppress the writing fo lines that are not repeated in the input." | 64 | # -d is "Suppress the writing fo lines that are not repeated in the input." |
66 | # -u is "Suppress the writing of lines that are repeated in the input." | 65 | # -u is "Suppress the writing of lines that are repeated in the input." |
67 | # Therefore, together this means they should produce no output. | 66 | # Therefore, together this means they should produce no output. |
68 | testing "uniq -u and -d produce no output" "-d -u" "" "" \ | 67 | testing "uniq -u and -d produce no output" "uniq -d -u" "" "" \ |
69 | "one\ntwo\ntwo\nthree\nthree\nthree\n" | 68 | "one\ntwo\ntwo\nthree\nthree\nthree\n" |
70 | 69 | ||
71 | exit $FAILCOUNT | 70 | exit $FAILCOUNT |