4 |
# Copyright 2005 by Rob Landley <rob@landley.net> |
# Copyright 2005 by Rob Landley <rob@landley.net> |
5 |
# Licensed under GPL v2, see file LICENSE for details. |
# Licensed under GPL v2, see file LICENSE for details. |
6 |
|
|
7 |
. testing.sh |
. ./testing.sh |
8 |
|
|
9 |
# testing "description" "arguments" "result" "infile" "stdin" |
# testing "description" "arguments" "result" "infile" "stdin" |
10 |
|
|
51 |
testing "sed s//p" "sed -e s/foo/bar/p -e s/bar/baz/p" "bar\nbaz\nbaz\n" \ |
testing "sed s//p" "sed -e s/foo/bar/p -e s/bar/baz/p" "bar\nbaz\nbaz\n" \ |
52 |
"" "foo\n" |
"" "foo\n" |
53 |
testing "sed -n s//p" "sed -ne s/abc/def/p" "def\n" "" "abc\n" |
testing "sed -n s//p" "sed -ne s/abc/def/p" "def\n" "" "abc\n" |
54 |
|
test x"$SKIP_KNOWN_BUGS" = x"" && { |
55 |
testing "sed s//g (exhaustive)" "sed -e 's/[[:space:]]*/,/g'" ",1,2,3,4,5,\n" \ |
testing "sed s//g (exhaustive)" "sed -e 's/[[:space:]]*/,/g'" ",1,2,3,4,5,\n" \ |
56 |
"" "12345\n" |
"" "12345\n" |
57 |
|
} |
58 |
testing "sed s arbitrary delimiter" "sed -e 's woo boing '" "boing\n" "" "woo\n" |
testing "sed s arbitrary delimiter" "sed -e 's woo boing '" "boing\n" "" "woo\n" |
59 |
testing "sed s chains" "sed -e s/foo/bar/ -e s/bar/baz/" "baz\n" "" "foo\n" |
testing "sed s chains" "sed -e s/foo/bar/ -e s/bar/baz/" "baz\n" "" "foo\n" |
60 |
testing "sed s chains2" "sed -e s/foo/bar/ -e s/baz/nee/" "bar\n" "" "foo\n" |
testing "sed s chains2" "sed -e s/foo/bar/ -e s/baz/nee/" "bar\n" "" "foo\n" |
74 |
testing "sed T (!test/branch)" "sed -e 's/a/1/;T notone;p;: notone;p'" \ |
testing "sed T (!test/branch)" "sed -e 's/a/1/;T notone;p;: notone;p'" \ |
75 |
"1\n1\n1\nb\nb\nc\nc\n" "" "a\nb\nc\n" |
"1\n1\n1\nb\nb\nc\nc\n" "" "a\nb\nc\n" |
76 |
|
|
77 |
|
test x"$SKIP_KNOWN_BUGS" = x"" && { |
78 |
# Normal sed end-of-script doesn't print "c" because n flushed the pattern |
# Normal sed end-of-script doesn't print "c" because n flushed the pattern |
79 |
# space. If n hits EOF, pattern space is empty when script ends. |
# space. If n hits EOF, pattern space is empty when script ends. |
80 |
# Query: how does this interact with no newline at EOF? |
# Query: how does this interact with no newline at EOF? |
83 |
# N does _not_ flush pattern space, therefore c is still in there @ script end. |
# N does _not_ flush pattern space, therefore c is still in there @ script end. |
84 |
testing "sed N (doesn't flush pattern space when terminating)" "sed -e 'N;p'" \ |
testing "sed N (doesn't flush pattern space when terminating)" "sed -e 'N;p'" \ |
85 |
"a\nb\na\nb\nc\n" "" "a\nb\nc\n" |
"a\nb\na\nb\nc\n" "" "a\nb\nc\n" |
86 |
|
} |
87 |
testing "sed address match newline" 'sed "/b/N;/b\\nc/i woo"' \ |
testing "sed address match newline" 'sed "/b/N;/b\\nc/i woo"' \ |
88 |
"a\nwoo\nb\nc\nd\n" "" "a\nb\nc\nd\n" |
"a\nwoo\nb\nc\nd\n" "" "a\nb\nc\nd\n" |
89 |
|
|
103 |
"sed -e '/ook/d;a\' -e 'bang'" "woot\nbang\n" "" "ook\nwoot\n" |
"sed -e '/ook/d;a\' -e 'bang'" "woot\nbang\n" "" "ook\nwoot\n" |
104 |
|
|
105 |
# Multiple files, with varying newlines and NUL bytes |
# Multiple files, with varying newlines and NUL bytes |
106 |
|
test x"$SKIP_KNOWN_BUGS" = x"" && { |
107 |
testing "sed embedded NUL" "sed -e 's/woo/bang/'" "\0bang\0woo\0" "" \ |
testing "sed embedded NUL" "sed -e 's/woo/bang/'" "\0bang\0woo\0" "" \ |
108 |
"\0woo\0woo\0" |
"\0woo\0woo\0" |
109 |
|
} |
110 |
testing "sed embedded NUL g" "sed -e 's/woo/bang/g'" "bang\0bang\0" "" \ |
testing "sed embedded NUL g" "sed -e 's/woo/bang/g'" "bang\0bang\0" "" \ |
111 |
"woo\0woo\0" |
"woo\0woo\0" |
112 |
|
test x"$SKIP_KNOWN_BUGS" = x"" && { |
113 |
echo -e "/woo/a he\0llo" > sed.commands |
echo -e "/woo/a he\0llo" > sed.commands |
114 |
testing "sed NUL in command" "sed -f sed.commands" "woo\nhe\0llo\n" "" "woo" |
testing "sed NUL in command" "sed -f sed.commands" "woo\nhe\0llo\n" "" "woo" |
115 |
rm sed.commands |
rm sed.commands |
116 |
|
} |
117 |
|
|
118 |
# sed has funky behavior with newlines at the end of file. Test lots of |
# sed has funky behavior with newlines at the end of file. Test lots of |
119 |
# corner cases with the optional newline appending behavior. |
# corner cases with the optional newline appending behavior. |
128 |
"" "one\ntwo" |
"" "one\ntwo" |
129 |
testing "sed cat plus empty file" "sed -e 's/nohit//' input -" "one\ntwo" \ |
testing "sed cat plus empty file" "sed -e 's/nohit//' input -" "one\ntwo" \ |
130 |
"one\ntwo" "" |
"one\ntwo" "" |
131 |
|
test x"$SKIP_KNOWN_BUGS" = x"" && { |
132 |
testing "sed append autoinserts newline" "sed -e '/woot/a woo' -" \ |
testing "sed append autoinserts newline" "sed -e '/woot/a woo' -" \ |
133 |
"woot\nwoo\n" "" "woot" |
"woot\nwoo\n" "" "woot" |
134 |
|
} |
135 |
testing "sed insert doesn't autoinsert newline" "sed -e '/woot/i woo' -" \ |
testing "sed insert doesn't autoinsert newline" "sed -e '/woot/i woo' -" \ |
136 |
"woo\nwoot" "" "woot" |
"woo\nwoot" "" "woot" |
137 |
testing "sed print autoinsert newlines" "sed -e 'p' -" "one\none" "" "one" |
testing "sed print autoinsert newlines" "sed -e 'p' -" "one\none" "" "one" |
147 |
testing "sed selective matches noinsert newline" \ |
testing "sed selective matches noinsert newline" \ |
148 |
"sed -ne 's/woo/bang/p' input -" "a bang\nb bang" "a woo\nb woo" \ |
"sed -ne 's/woo/bang/p' input -" "a bang\nb bang" "a woo\nb woo" \ |
149 |
"c no\nd no" |
"c no\nd no" |
150 |
|
test x"$SKIP_KNOWN_BUGS" = x"" && { |
151 |
testing "sed clusternewline" \ |
testing "sed clusternewline" \ |
152 |
"sed -e '/one/a 111' -e '/two/i 222' -e p input -" \ |
"sed -e '/one/a 111' -e '/two/i 222' -e p input -" \ |
153 |
"one\none\n111\n222\ntwo\ntwo" "one" "two" |
"one\none\n111\n222\ntwo\ntwo" "one" "two" |
154 |
|
} |
155 |
testing "sed subst+write" \ |
testing "sed subst+write" \ |
156 |
"sed -e 's/i/z/' -e 'woutputw' input -; echo -n X; cat outputw" \ |
"sed -e 's/i/z/' -e 'woutputw' input -; echo -n X; cat outputw" \ |
157 |
"thzngy\nagaznXthzngy\nagazn" "thingy" "again" |
"thzngy\nagaznXthzngy\nagazn" "thingy" "again" |
187 |
"GNU sed version \n" "" "" |
"GNU sed version \n" "" "" |
188 |
|
|
189 |
# Jump to nonexistent label |
# Jump to nonexistent label |
190 |
testing "sed nonexistent label" "sed -e 'b walrus' 2> /dev/null || echo yes" \ |
test x"$SKIP_KNOWN_BUGS" = x"" && { |
191 |
|
# Incompatibility: illegal jump is not detected if input is "" |
192 |
|
# (that is, no lines at all). GNU sed 4.1.5 complains even in this case |
193 |
|
testing "sed nonexistent label" "sed -e 'b walrus' 2>/dev/null || echo yes" \ |
194 |
"yes\n" "" "" |
"yes\n" "" "" |
195 |
|
} |
196 |
|
|
197 |
testing "sed backref from empty s uses range regex" \ |
testing "sed backref from empty s uses range regex" \ |
198 |
"sed -e '/woot/s//eep \0 eep/'" "eep woot eep" "" "woot" |
"sed -e '/woot/s//eep \0 eep/'" "eep woot eep" "" "woot" |
223 |
"sed 's/1/x/;T;n;: next;s/3/y/;t quit;n;b next;: quit;q'" \ |
"sed 's/1/x/;T;n;: next;s/3/y/;t quit;n;b next;: quit;q'" \ |
224 |
"0\nx\n2\ny\n" "" "0\n1\n2\n3\n" |
"0\nx\n2\ny\n" "" "0\n1\n2\n3\n" |
225 |
|
|
226 |
|
testing "sed d does not break n,m matching" \ |
227 |
|
"sed -n '1d;1,3p'" \ |
228 |
|
"second\nthird\n" "" "first\nsecond\nthird\nfourth\n" |
229 |
|
|
230 |
|
testing "sed d does not break n,regex matching" \ |
231 |
|
"sed -n '1d;1,/hir/p'" \ |
232 |
|
"second\nthird\n" "" "first\nsecond\nthird\nfourth\n" |
233 |
|
|
234 |
|
testing "sed d does not break n,regex matching #2" \ |
235 |
|
"sed -n '1,5d;1,/hir/p'" \ |
236 |
|
"second2\nthird2\n" "" \ |
237 |
|
"first\nsecond\nthird\nfourth\n""first2\nsecond2\nthird2\nfourth2\n" |
238 |
|
|
239 |
|
testing "sed 2d;2,1p (gnu compat)" \ |
240 |
|
"sed -n '2d;2,1p'" \ |
241 |
|
"third\n" "" \ |
242 |
|
"first\nsecond\nthird\nfourth\n" |
243 |
|
|
244 |
|
# Regex means: "match / at BOL or nothing, then one or more not-slashes". |
245 |
|
# The bug was that second slash in /usr/lib was treated as "at BOL" too. |
246 |
|
testing "sed beginning (^) matches only once" \ |
247 |
|
"sed 's,\(^/\|\)[^/][^/]*,>\0<,g'" \ |
248 |
|
">/usr</>lib<\n" "" \ |
249 |
|
"/usr/lib\n" |
250 |
|
|
251 |
exit $FAILCOUNT |
exit $FAILCOUNT |