aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRob Landley <rob@landley.net>2005-11-10 06:26:40 +0000
committerRob Landley <rob@landley.net>2005-11-10 06:26:40 +0000
commit990025a7d971bbbdd982d2d070d3e47628d0fac0 (patch)
tree21e56ca95118f3874f7a889c285921377df47552
parentecfd1f6a350c91bd2b562cd3d04c160a54debc61 (diff)
downloadbusybox-w32-990025a7d971bbbdd982d2d070d3e47628d0fac0.tar.gz
busybox-w32-990025a7d971bbbdd982d2d070d3e47628d0fac0.tar.bz2
busybox-w32-990025a7d971bbbdd982d2d070d3e47628d0fac0.zip
Ok, I've converted the contents of the "testing/sed" directory into a
sed.tests file. My brain hurts now. (Lots of boggling at sed minutiae and corner cases and going "why is gnu giving that output". The behavior of N and n with regard to EOF are only understandable if you read the Open Group spec, not if you read the sed info page, by the way...) Some of the existing sed tests are just nuts. For example, sed-next-line is testing for our behavior (which is wrong), and would fail if run against gnu sed (which was getting it right. Again, this was a spec-boggling moment, with much head scratching. I've got to add a debug mode where the stuff output by the p command is a different color from the stuff output by normal end of script printing (when not suppressed by -n).) As for sed-handles-unsatisifed-backrefs: what is this test trying to _do_? I ran it against gnu sed and got an error message, and this behavior sounds perfectly reasonable. (It _is_ an unsatisfied backref.) The fact we currently ignore this case (and treat \1 as an empty string) isn't really behavior we should have a test depend on for success. The remaining one is sed-aic-commands, which is long and complicated. I'm trying to figure out if I should chop this into a number of smaller tests, or if having one big "does-many-things" test is a good idea. In any case, the _next_ step is to go through the Open Group standard and make tests for every case not yet covered. (And there are plenty. There are few comments in the file already.) Plus I have notes about corner cases from development that I need to collate and put into here. This file is maybe the first 1/3 of a truly comprehensive sed test. Rob
-rwxr-xr-xtestsuite/sed.tests109
-rw-r--r--testsuite/sed/sed-accepts-blanks-before-command1
-rw-r--r--testsuite/sed/sed-aic-commands134
-rw-r--r--testsuite/sed/sed-append-hold-space-to-pattern-space13
-rw-r--r--testsuite/sed/sed-append-next-line19
-rw-r--r--testsuite/sed/sed-branch1
-rw-r--r--testsuite/sed/sed-branch-conditional15
-rwxr-xr-xtestsuite/sed/sed-branch-conditional-inverted14
-rw-r--r--testsuite/sed/sed-branch-conditional211
-rw-r--r--testsuite/sed/sed-branch-no-label1
-rw-r--r--testsuite/sed/sed-chains-substs1
-rw-r--r--testsuite/sed/sed-chains-substs21
-rw-r--r--testsuite/sed/sed-does-not-substitute-in-deleted-line2
-rw-r--r--testsuite/sed/sed-handles-embedded-slashes1
-rw-r--r--testsuite/sed/sed-handles-empty-lines1
-rw-r--r--testsuite/sed/sed-handles-unsatisfied-backrefs6
-rw-r--r--testsuite/sed/sed-next-line12
-rw-r--r--testsuite/sed/sed-prints-line-once-for-multiple-substs4
-rw-r--r--testsuite/sed/sed-recurses-properly1
-rw-r--r--testsuite/sed/sed-regex-match-newline10
-rw-r--r--testsuite/sed/sed-splits-edit-commands-on-command-line9
-rw-r--r--testsuite/sed/sed-subst-subprint9
-rw-r--r--testsuite/sed/sed-write-to-stdout10
23 files changed, 109 insertions, 276 deletions
diff --git a/testsuite/sed.tests b/testsuite/sed.tests
new file mode 100755
index 000000000..479dd9ae7
--- /dev/null
+++ b/testsuite/sed.tests
@@ -0,0 +1,109 @@
1#!/bin/sh
2
3# SUSv3 compliant sed tests.
4# Copyright 2005 by Rob Landley <rob@landley.net>
5# Licensed under GPL v2, see file LICENSE for details.
6
7[ -z "$COMMAND" ] && COMMAND=sed
8. testing.sh
9
10# testing "description" "arguments" "result" "infile" "stdin"
11
12# Corner cases
13testing "sed as cat" '"" -' "hello\n" "" "hello\n"
14testing "sed handles empty lines" "-e 's/\$/@/'" "@\n" "" "\n"
15
16# no files (stdin)
17# explicit stdin
18# mix files and stdin (various orders)
19# list stdin twice
20# Trailing EOF.
21# Multiple files: first no EOF, second length 0.
22# Match $, at end of each file or all files?
23# First no EOF, second no matches at all.
24# -e corner cases
25# without -e
26# multiple -e
27# interact with a
28# -eee arg1 arg2 arg3
29# -f corner cases
30# -e -f -e
31# -n corner cases
32# no newline at EOF?
33# -r corner cases
34# Just make sure it works.
35# -i corner cases:
36# sed -i -
37# permissions
38# -i on a symlink
39# on a directory
40
41# command list
42testing "sed accepts blanks before command" "-e '1 d'" "" "" ""
43testing "sed accepts newlines in -e" "-e 'i\
441
45a\
463'" "1\n2\n3\n" "" "2\n"
47testing "sed accepts multiple -e" "-e 'i\' -e '1' -e 'a\' -e '3'" \
48 "1\n2\n3\n" "" "2\n"
49
50# substitutions
51testing "sed -n" "-n -e s/foo/bar/ -e s/bar/baz/" "" "" "foo\n"
52testing "sed s//p" "-e s/foo/bar/p -e s/bar/baz/p" "bar\nbaz\nbaz\n" \
53 "" "foo\n"
54testing "sed -n s//p" "-ne s/abc/def/p" "def\n" "" "abc\n"
55testing "sed s//g (exhaustive)" "-e 's/[[:space:]]*/,/g'" ",1,2,3,4,5,\n" \
56 "" "12345\n"
57testing "sed s arbitrary delimiter" "-e 's woo boing '" "boing\n" "" "woo\n"
58testing "sed s chains" "-e s/foo/bar/ -e s/bar/baz/" "baz\n" "" "foo\n"
59testing "sed s chains2" "-e s/foo/bar/ -e s/baz/nee/" "bar\n" "" "foo\n"
60testing "sed s [delimiter]" "-e 's@[@]@@'" "onetwo" "" "one@two"
61
62# branch
63testing "sed b (branch)" "-e 'b one;p;: one'" "foo\n" "" "foo\n"
64testing "sed b (branch with no label jumps to end)" "-e 'b;p'" \
65 "foo\n" "" "foo\n"
66
67# test and branch
68testing "sed t (test/branch)" "-e 's/a/1/;t one;p;: one;p'" \
69 "1\n1\nb\nb\nb\nc\nc\nc\n" "" "a\nb\nc\n"
70testing "sed t (test/branch clears test bit)" "-e 's/a/b/;:loop;t loop'" \
71 "b\nb\nc\n" "" "a\nb\nc\n"
72testing "sed T (!test/branch)" "-e 's/a/1/;T notone;p;: notone;p'" \
73 "1\n1\n1\nb\nb\nc\nc\n" "" "a\nb\nc\n"
74
75# 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.
77# Query: how does this interact with no newline at EOF?
78testing "sed n (flushes pattern space, terminates early)" "-e 'n;p'" \
79 "a\nb\nb\nc\n" "" "a\nb\nc\n"
80# N does _not_ flush pattern space, therefore c is still in there @ script end.
81testing "sed N (doesn't flush pattern space when terminating)" "-e 'N;p'" \
82 "a\nb\na\nb\nc\n" "" "a\nb\nc\n"
83testing "sed address match newline" '"/b/N;/b\\nc/i woo"' "a\nwoo\nb\nc\nd\n" \
84 "" "a\nb\nc\nd\n"
85
86# Multiple lines in pattern space
87testing "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"
89
90# Hold space
91testing "sed G (append hold space to pattern space)" 'G' "a\n\nb\n\nc\n\n" \
92 "" "a\nb\nc\n"
93#testing "sed g/G (swap/append hold and patter space)"
94#testing "sed g (swap hold/pattern space)"
95
96testing "sed d ends script iteration" \
97 "-e '/ook/d;s/ook/ping/p;i woot'" "" "" "ook\n"
98testing "sed d ends script iteration (2)" \
99 "-e '/ook/d;a\' -e 'bang'" "woot\nbang\n" "" "ook\nwoot\n"
100
101# Ponder this a bit more, why "woo not found" from gnu version?
102#testing "sed doesn't substitute in deleted line" \
103# "-e '/ook/d;s/ook//;t woo;a bang;'" "bang" "" "ook\n"
104
105# This makes both seds very unhappy. Why?
106#testing "sed -g (exhaustive)" "sed -e 's/[[:space:]]*/,/g'" ",1,2,3,4,5," \
107# "" "12345"
108
109exit $FAILCOUNT
diff --git a/testsuite/sed/sed-accepts-blanks-before-command b/testsuite/sed/sed-accepts-blanks-before-command
deleted file mode 100644
index 9597c2f8b..000000000
--- a/testsuite/sed/sed-accepts-blanks-before-command
+++ /dev/null
@@ -1 +0,0 @@
1busybox sed -e '1 d' </dev/null
diff --git a/testsuite/sed/sed-aic-commands b/testsuite/sed/sed-aic-commands
deleted file mode 100644
index b41c14ab8..000000000
--- a/testsuite/sed/sed-aic-commands
+++ /dev/null
@@ -1,134 +0,0 @@
1cat - >input <<EOF
22i\\
3before 2
45c\\
5Change 5
610a\\
7After 10
822i\\
9before 22\\
10Continued
1125c\\
12Change 25\\
13Continued
1420a\\
15After 20\\
16Continued
17 32i\\
18before 32\\
19Continued 1\\
20Continued 2\\
21Continued 3
22 35c\\
23Change 35\\
24Continued 1\\
25Continued 2\\
26Continued 3
27 30a\\
28After 30\\
29Continued 1\\
30Continued 2\\
31Continued 3
32EOF
33busybox sed -f input >output <<EOF
34 1 y
35 2 y
36 3 y
37 4 y
38 5 y
39 6 y
40 7 y
41 8 y
42 9 y
43 10 y
44 11 y
45 12 y
46 13 y
47 14 y
48 15 y
49 16 y
50 17 y
51 18 y
52 19 y
53 20 y
54 21 y
55 22 y
56 23 y
57 24 y
58 25 y
59 26 y
60 27 y
61 28 y
62 29 y
63 30 y
64 31 y
65 32 y
66 33 y
67 34 y
68 35 y
69 36 y
70 37 y
71 38 y
72 39 y
73 40 y
74EOF
75cmp -s output - <<EOF
76 1 y
77before 2
78 2 y
79 3 y
80 4 y
81Change 5
82 6 y
83 7 y
84 8 y
85 9 y
86 10 y
87After 10
88 11 y
89 12 y
90 13 y
91 14 y
92 15 y
93 16 y
94 17 y
95 18 y
96 19 y
97 20 y
98After 20
99Continued
100 21 y
101before 22
102Continued
103 22 y
104 23 y
105 24 y
106Change 25
107Continued
108 26 y
109 27 y
110 28 y
111 29 y
112 30 y
113After 30
114Continued 1
115Continued 2
116Continued 3
117 31 y
118before 32
119Continued 1
120Continued 2
121Continued 3
122 32 y
123 33 y
124 34 y
125Change 35
126Continued 1
127Continued 2
128Continued 3
129 36 y
130 37 y
131 38 y
132 39 y
133 40 y
134EOF
diff --git a/testsuite/sed/sed-append-hold-space-to-pattern-space b/testsuite/sed/sed-append-hold-space-to-pattern-space
deleted file mode 100644
index 6dda80fee..000000000
--- a/testsuite/sed/sed-append-hold-space-to-pattern-space
+++ /dev/null
@@ -1,13 +0,0 @@
1busybox sed 'G'>output <<EOF
2a
3b
4c
5EOF
6cmp -s output - <<EOF
7a
8
9b
10
11c
12
13EOF
diff --git a/testsuite/sed/sed-append-next-line b/testsuite/sed/sed-append-next-line
deleted file mode 100644
index 0621a319f..000000000
--- a/testsuite/sed/sed-append-next-line
+++ /dev/null
@@ -1,19 +0,0 @@
1# This will fail if CONFIG_FEATURE_SED_GNU_COMPATABILITY is defined
2busybox sed 'N;p'>output <<EOF
3a
4b
5c
6EOF
7
8set +e
9cmp -s output - <<EOF
10a
11b
12a
13b
14c
15EOF
16if [ $? != 0 ] ; then
17 exit 0;
18fi
19exit 1;
diff --git a/testsuite/sed/sed-branch b/testsuite/sed/sed-branch
deleted file mode 100644
index 4167569ad..000000000
--- a/testsuite/sed/sed-branch
+++ /dev/null
@@ -1 +0,0 @@
1test "$(echo foo | busybox sed 'b one;p;: one')" = foo
diff --git a/testsuite/sed/sed-branch-conditional b/testsuite/sed/sed-branch-conditional
deleted file mode 100644
index 47d0a5ff2..000000000
--- a/testsuite/sed/sed-branch-conditional
+++ /dev/null
@@ -1,15 +0,0 @@
1busybox sed 's/a/1/;t one;p;: one;p'>output <<EOF
2a
3b
4c
5EOF
6cmp -s output - <<EOF
71
81
9b
10b
11b
12c
13c
14c
15EOF
diff --git a/testsuite/sed/sed-branch-conditional-inverted b/testsuite/sed/sed-branch-conditional-inverted
deleted file mode 100755
index f4df84b3e..000000000
--- a/testsuite/sed/sed-branch-conditional-inverted
+++ /dev/null
@@ -1,14 +0,0 @@
1busybox sed 's/a/1/;T notone;p;: notone;p'>output <<EOF
2a
3b
4c
5EOF
6cmp -s output - <<EOF
71
81
91
10b
11b
12c
13c
14EOF
diff --git a/testsuite/sed/sed-branch-conditional2 b/testsuite/sed/sed-branch-conditional2
deleted file mode 100644
index f4b11f0f8..000000000
--- a/testsuite/sed/sed-branch-conditional2
+++ /dev/null
@@ -1,11 +0,0 @@
1#XFAIL
2busybox sed 's/a/b/;:loop;t loop'>output <<EOF
3a
4b
5c
6EOF
7cmp -s output - <<EOF
8b
9b
10c
11EOF
diff --git a/testsuite/sed/sed-branch-no-label b/testsuite/sed/sed-branch-no-label
deleted file mode 100644
index 446c1bcd9..000000000
--- a/testsuite/sed/sed-branch-no-label
+++ /dev/null
@@ -1 +0,0 @@
1test "$(echo foo | busybox sed 'b;p')" = foo
diff --git a/testsuite/sed/sed-chains-substs b/testsuite/sed/sed-chains-substs
deleted file mode 100644
index 266936ac4..000000000
--- a/testsuite/sed/sed-chains-substs
+++ /dev/null
@@ -1 +0,0 @@
1test "$(echo foo | busybox sed -e s/foo/bar/ -e s/bar/baz/)" = baz
diff --git a/testsuite/sed/sed-chains-substs2 b/testsuite/sed/sed-chains-substs2
deleted file mode 100644
index 90568f6e6..000000000
--- a/testsuite/sed/sed-chains-substs2
+++ /dev/null
@@ -1 +0,0 @@
1test x"$(echo foo | busybox -n sed -e s/foo/bar/ -e s/foo/baz/)" = x
diff --git a/testsuite/sed/sed-does-not-substitute-in-deleted-line b/testsuite/sed/sed-does-not-substitute-in-deleted-line
deleted file mode 100644
index 6f106e104..000000000
--- a/testsuite/sed/sed-does-not-substitute-in-deleted-line
+++ /dev/null
@@ -1,2 +0,0 @@
1echo foo | busybox sed -e /foo/d -e s/foo/bar/ >foo
2cmp foo /dev/null
diff --git a/testsuite/sed/sed-handles-embedded-slashes b/testsuite/sed/sed-handles-embedded-slashes
deleted file mode 100644
index cc287613d..000000000
--- a/testsuite/sed/sed-handles-embedded-slashes
+++ /dev/null
@@ -1 +0,0 @@
1test "$(echo fu/bar | busybox sed -e 's/[/]//')" = fubar
diff --git a/testsuite/sed/sed-handles-empty-lines b/testsuite/sed/sed-handles-empty-lines
deleted file mode 100644
index 2bb8f045a..000000000
--- a/testsuite/sed/sed-handles-empty-lines
+++ /dev/null
@@ -1 +0,0 @@
1test `echo | busybox sed -e 's/$/@/'` = @
diff --git a/testsuite/sed/sed-handles-unsatisfied-backrefs b/testsuite/sed/sed-handles-unsatisfied-backrefs
deleted file mode 100644
index 61bff8837..000000000
--- a/testsuite/sed/sed-handles-unsatisfied-backrefs
+++ /dev/null
@@ -1,6 +0,0 @@
1busybox sed -e 's/.*root=/\1/' >output <<EOF
2BOOT_IMAGE=vmlinuz root=/dev/hda5 initrd=init1
3EOF
4cmp -s output - <<EOF
5/dev/hda5 initrd=init1
6EOF
diff --git a/testsuite/sed/sed-next-line b/testsuite/sed/sed-next-line
deleted file mode 100644
index 38fe20cf2..000000000
--- a/testsuite/sed/sed-next-line
+++ /dev/null
@@ -1,12 +0,0 @@
1busybox sed 'n;p'>output <<EOF
2a
3b
4c
5EOF
6cmp -s output - <<EOF
7a
8b
9b
10c
11c
12EOF
diff --git a/testsuite/sed/sed-prints-line-once-for-multiple-substs b/testsuite/sed/sed-prints-line-once-for-multiple-substs
deleted file mode 100644
index ba8955d6e..000000000
--- a/testsuite/sed/sed-prints-line-once-for-multiple-substs
+++ /dev/null
@@ -1,4 +0,0 @@
1busybox sed -e s/1/2/g -e s/3/4/g >output <<EOF
21
3EOF
4echo 2 | cmp -s output -
diff --git a/testsuite/sed/sed-recurses-properly b/testsuite/sed/sed-recurses-properly
deleted file mode 100644
index a02667b41..000000000
--- a/testsuite/sed/sed-recurses-properly
+++ /dev/null
@@ -1 +0,0 @@
1test "`echo '12345' | busybox sed -e 's/[[:space:]]*/,/g')` = ',1,2,3,4,5,'"
diff --git a/testsuite/sed/sed-regex-match-newline b/testsuite/sed/sed-regex-match-newline
deleted file mode 100644
index 1057e1718..000000000
--- a/testsuite/sed/sed-regex-match-newline
+++ /dev/null
@@ -1,10 +0,0 @@
1# FEATURE: CONFIG_FEATURE_SED_EMBEDED_NEWLINE
2busybox sed -n 'N;/a\nb/p'>output <<EOF
3a
4b
5c
6EOF
7cmp -s output - <<EOF
8a
9b
10EOF
diff --git a/testsuite/sed/sed-splits-edit-commands-on-command-line b/testsuite/sed/sed-splits-edit-commands-on-command-line
deleted file mode 100644
index 6421fa552..000000000
--- a/testsuite/sed/sed-splits-edit-commands-on-command-line
+++ /dev/null
@@ -1,9 +0,0 @@
1echo 2 | busybox sed -e 'i\
21
3a\
43' > output
5cmp output - <<EOF
61
72
83
9EOF
diff --git a/testsuite/sed/sed-subst-subprint b/testsuite/sed/sed-subst-subprint
deleted file mode 100644
index 24f8bad7d..000000000
--- a/testsuite/sed/sed-subst-subprint
+++ /dev/null
@@ -1,9 +0,0 @@
1busybox sed 's/foo/bar/p'>output <<EOF
2foo
3bar
4EOF
5cmp -s output - <<EOF
6bar
7bar
8bar
9EOF
diff --git a/testsuite/sed/sed-write-to-stdout b/testsuite/sed/sed-write-to-stdout
deleted file mode 100644
index 95b4d724b..000000000
--- a/testsuite/sed/sed-write-to-stdout
+++ /dev/null
@@ -1,10 +0,0 @@
1busybox sed -n 'N;P;p'>output <<EOF
2a
3b
4c
5EOF
6cmp -s output - <<EOF
7a
8a
9b
10EOF