aboutsummaryrefslogtreecommitdiff
path: root/testsuite/sed.tests
diff options
context:
space:
mode:
Diffstat (limited to 'testsuite/sed.tests')
-rwxr-xr-xtestsuite/sed.tests121
1 files changed, 63 insertions, 58 deletions
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
13testing "sed no files (stdin)" '""' "hello\n" "" "hello\n" 12testing "sed no files (stdin)" 'sed ""' "hello\n" "" "hello\n"
14testing "sed explicit stdin" '"" -' "hello\n" "" "hello\n" 13testing "sed explicit stdin" 'sed "" -' "hello\n" "" "hello\n"
15testing "sed handles empty lines" "-e 's/\$/@/'" "@\n" "" "\n" 14testing "sed handles empty lines" "sed -e 's/\$/@/'" "@\n" "" "\n"
16testing "sed stdin twice" '"" - -' "hello" "" "hello" 15testing "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
42testing "sed accepts blanks before command" "-e '1 d'" "" "" "" 41testing "sed accepts blanks before command" "sed -e '1 d'" "" "" ""
43testing "sed accepts newlines in -e" "-e 'i\ 42testing "sed accepts newlines in -e" "sed -e 'i\
441 431
45a\ 44a\
463'" "1\n2\n3\n" "" "2\n" 453'" "1\n2\n3\n" "" "2\n"
47testing "sed accepts multiple -e" "-e 'i\' -e '1' -e 'a\' -e '3'" \ 46testing "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
51testing "sed -n" "-n -e s/foo/bar/ -e s/bar/baz/" "" "" "foo\n" 50testing "sed -n" "sed -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" \ 51testing "sed s//p" "sed -e s/foo/bar/p -e s/bar/baz/p" "bar\nbaz\nbaz\n" \
53 "" "foo\n" 52 "" "foo\n"
54testing "sed -n s//p" "-ne s/abc/def/p" "def\n" "" "abc\n" 53testing "sed -n s//p" "sed -ne s/abc/def/p" "def\n" "" "abc\n"
55testing "sed s//g (exhaustive)" "-e 's/[[:space:]]*/,/g'" ",1,2,3,4,5,\n" \ 54testing "sed s//g (exhaustive)" "sed -e 's/[[:space:]]*/,/g'" ",1,2,3,4,5,\n" \
56 "" "12345\n" 55 "" "12345\n"
57testing "sed s arbitrary delimiter" "-e 's woo boing '" "boing\n" "" "woo\n" 56testing "sed s arbitrary delimiter" "sed -e 's woo boing '" "boing\n" "" "woo\n"
58testing "sed s chains" "-e s/foo/bar/ -e s/bar/baz/" "baz\n" "" "foo\n" 57testing "sed s chains" "sed -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" 58testing "sed s chains2" "sed -e s/foo/bar/ -e s/baz/nee/" "bar\n" "" "foo\n"
60testing "sed s [delimiter]" "-e 's@[@]@@'" "onetwo" "" "one@two" 59testing "sed s [delimiter]" "sed -e 's@[@]@@'" "onetwo" "" "one@two"
61 60
62# branch 61# branch
63testing "sed b (branch)" "-e 'b one;p;: one'" "foo\n" "" "foo\n" 62testing "sed b (branch)" "sed -e 'b one;p;: one'" "foo\n" "" "foo\n"
64testing "sed b (branch with no label jumps to end)" "-e 'b;p'" \ 63testing "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
68testing "sed t (test/branch)" "-e 's/a/1/;t one;p;: one;p'" \ 67testing "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"
70testing "sed t (test/branch clears test bit)" "-e 's/a/b/;:loop;t loop'" \ 69testing "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"
72testing "sed T (!test/branch)" "-e 's/a/1/;T notone;p;: notone;p'" \ 71testing "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?
78testing "sed n (flushes pattern space, terminates early)" "-e 'n;p'" \ 77testing "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.
81testing "sed N (doesn't flush pattern space when terminating)" "-e 'N;p'" \ 80testing "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"
83testing "sed address match newline" '"/b/N;/b\\nc/i woo"' "a\nwoo\nb\nc\nd\n" \ 82testing "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
87testing "sed N (stops at end of input) and P (prints to first newline only)" \ 86testing "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
91testing "sed G (append hold space to pattern space)" 'G' "a\n\nb\n\nc\n\n" \ 90testing "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
96testing "sed d ends script iteration" \ 95testing "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"
98testing "sed d ends script iteration (2)" \ 97testing "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
102testing "sed embedded NUL" "-e 's/woo/bang/'" "\0bang\0woo\0" "" "\0woo\0woo\0" 101testing "sed embedded NUL" "sed -e 's/woo/bang/'" "\0bang\0woo\0" "" \
103testing "sed embedded NUL g" "-e 's/woo/bang/g'" "bang\0bang\0" "" "woo\0woo\0" 102 "\0woo\0woo\0"
103testing "sed embedded NUL g" "sed -e 's/woo/bang/g'" "bang\0bang\0" "" \
104 "woo\0woo\0"
104echo -e "/woo/a he\0llo" > sed.commands 105echo -e "/woo/a he\0llo" > sed.commands
105testing "sed NUL in command" "-f sed.commands" "woo\nhe\0llo\n" "" "woo" 106testing "sed NUL in command" "sed -f sed.commands" "woo\nhe\0llo\n" "" "woo"
106rm sed.commands 107rm 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
111testing "sed normal newlines" "-e 's/woo/bang/' input -" "bang\nbang\n" \ 112testing "sed normal newlines" "sed -e 's/woo/bang/' input -" "bang\nbang\n" \
112 "woo\n" "woo\n" 113 "woo\n" "woo\n"
113testing "sed leave off trailing newline" "-e 's/woo/bang/' input -" \ 114testing "sed leave off trailing newline" "sed -e 's/woo/bang/' input -" \
114 "bang\nbang" "woo\n" "woo" 115 "bang\nbang" "woo\n" "woo"
115testing "sed autoinsert newline" "-e 's/woo/bang/' input -" "bang\nbang" \ 116testing "sed autoinsert newline" "sed -e 's/woo/bang/' input -" "bang\nbang" \
116 "woo" "woo" 117 "woo" "woo"
117testing "sed empty file plus cat" "-e 's/nohit//' input -" "one\ntwo" \ 118testing "sed empty file plus cat" "sed -e 's/nohit//' input -" "one\ntwo" \
118 "" "one\ntwo" 119 "" "one\ntwo"
119testing "sed cat plus empty file" "-e 's/nohit//' input -" "one\ntwo" \ 120testing "sed cat plus empty file" "sed -e 's/nohit//' input -" "one\ntwo" \
120 "one\ntwo" "" 121 "one\ntwo" ""
121testing "sed append autoinserts newline" "-e '/woot/a woo' -" "woot\nwoo\n" \ 122testing "sed append autoinserts newline" "sed -e '/woot/a woo' -" \
122 "" "woot" 123 "woot\nwoo\n" "" "woot"
123testing "sed insert doesn't autoinsert newline" "-e '/woot/i woo' -" \ 124testing "sed insert doesn't autoinsert newline" "sed -e '/woot/i woo' -" \
124 "woo\nwoot" "" "woot" 125 "woo\nwoot" "" "woot"
125testing "sed print autoinsert newlines" "-e 'p' -" "one\none" "" "one" 126testing "sed print autoinsert newlines" "sed -e 'p' -" "one\none" "" "one"
126testing "sed print autoinsert newlines two files" "-e 'p' input -" \ 127testing "sed print autoinsert newlines two files" "sed -e 'p' input -" \
127 "one\none\ntwo\ntwo" "one" "two" 128 "one\none\ntwo\ntwo" "one" "two"
128testing "sed noprint, no match, no newline" "-ne 's/woo/bang/' input" \ 129testing "sed noprint, no match, no newline" "sed -ne 's/woo/bang/' input" \
129 "" "no\n" "" 130 "" "no\n" ""
130testing "sed selective matches with one nl" "-ne 's/woo/bang/p' input -" \ 131testing "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"
132testing "sed selective matches insert newline" "-ne 's/woo/bang/p' input -" \ 133testing "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" \
134testing "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" 136testing "sed selective matches noinsert newline" \
136testing "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"
139testing "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
141testing "sed match EOF" " -e '"'$p'"'" "hello\nthere\nthere" "" "hello\nthere" 145testing "sed match EOF" "sed -e '"'$p'"'" "hello\nthere\nthere" "" \
142testing "sed match EOF two files" " -e '"'$p'"' input -" \ 146 "hello\nthere"
147testing "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"
144echo -ne "three\nfour" > input2 149echo -ne "three\nfour" > input2
145testing "sed match EOF inline" \ 150testing "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" ""
148rm input2 153rm input2
149 154
150# Test lie-to-autoconf 155# Test lie-to-autoconf
151 156
152testing "sed lie-to-autoconf" "--version | grep -o 'GNU sed version '" \ 157testing "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
156testing "sed nonexistent label" "-e 'b walrus' 2> /dev/null || echo yes" \ 161testing "sed nonexistent label" "sed -e 'b walrus' 2> /dev/null || echo yes" \
157 "yes\n" "" "" 162 "yes\n" "" ""
158 163
159testing "sed backref from empty s uses range regex" \ 164testing "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
162testing "sed backref from empty s uses range regex with newline" \ 167testing "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
167touch ./- # Detect gnu failure mode here. 172touch ./- # Detect gnu failure mode here.
168testing "sed -i with no arg [GNUFAIL]" "-e '' -i 2> /dev/null || echo yes" \ 173testing "sed -i with no arg [GNUFAIL]" "sed -e '' -i 2> /dev/null || echo yes" \
169 "yes\n" "" "" 174 "yes\n" "" ""
170rm ./- # Clean up 175rm ./- # 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," \