2 # $NetBSD: sed.test,v 1.3 1997/01/09 20:21:37 tls Exp $
4 # Copyright (c) 1992 Diomidis Spinellis.
5 # Copyright (c) 1992, 1993
6 # The Regents of the University of California. All rights reserved.
8 # Redistribution and use in source and binary forms, with or without
9 # modification, are permitted provided that the following conditions
11 # 1. Redistributions of source code must retain the above copyright
12 # notice, this list of conditions and the following disclaimer.
13 # 2. Redistributions in binary form must reproduce the above copyright
14 # notice, this list of conditions and the following disclaimer in the
15 # documentation and/or other materials provided with the distribution.
16 # 3. All advertising materials mentioning features or use of this software
17 # must display the following acknowledgement:
18 # This product includes software developed by the University of
19 # California, Berkeley and its contributors.
20 # 4. Neither the name of the University nor the names of its contributors
21 # may be used to endorse or promote products derived from this software
22 # without specific prior written permission.
24 # THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
25 # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26 # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27 # ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
28 # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
29 # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
30 # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
31 # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32 # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
33 # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
36 # from: @(#)sed.test 8.1 (Berkeley) 6/6/93
37 # $NetBSD: sed.test,v 1.3 1997/01/09 20:21:37 tls Exp $
40 # sed Regression Tests
42 # The following files are created:
43 # lines[1-4], script1, script2
44 # Two directories *.out contain the test results
52 DICT
=/usr
/share
/dict
/words
56 awk 'END { for (i = 1; i < 15; i++) print "l1_" i}' </dev
/null
>lines1
57 awk 'END { for (i = 1; i < 10; i++) print "l2_" i}' </dev
/null
>lines2
61 # Set these flags to get messages about known problems
72 diff -c $BASELOG $TESTLOG |
more
98 exec >"$DIR/${MARK}_$1"
100 # Uncomment this line to match tests with sed error messages
101 echo "Test $1:$MARK" >&5
107 echo Testing argument parsing
109 if [ $SUN -eq 1 ] ; then
110 echo SunOS
sed prints only with
-n
112 $SED 's/^/e1_/p' lines1
114 mark
'1.2' ; $SED -n 's/^/e1_/p' lines1
116 if [ $SUN -eq 1 ] ; then
117 echo SunOS
sed prints only with
-n
119 $SED 's/^/e1_/p' <lines1
121 mark
'1.4' ; $SED -n 's/^/e1_/p' <lines1
124 if [ $SUN -eq 1 ] ; then
125 echo SunOS
sed fails this
128 echo 's/^/s1_/p' >script1
129 echo 's/^/s2_/p' >script2
131 if [ $SUN -eq 1 ] ; then
132 echo SunOS
sed prints only with
-n
134 $SED -f script1 lines1
137 if [ $SUN -eq 1 ] ; then
138 echo SunOS
sed prints only with
-n
140 $SED -f script1
<lines1
143 if [ $SUN -eq 1 ] ; then
144 echo SunOS
sed prints only with
-n
146 $SED -e 's/^/e1_/p' lines1
149 if [ $SUN -eq 1 ] ; then
150 echo SunOS
sed prints only with
-n
152 $SED -e 's/^/e1_/p' <lines1
154 mark
'1.9' ; $SED -n -f script1 lines1
155 mark
'1.10' ; $SED -n -f script1
<lines1
156 mark
'1.11' ; $SED -n -e 's/^/e1_/p' lines1
158 if [ $SUN -eq 1 ] ; then
159 echo SunOS
sed prints only with
-n
161 $SED -n -e 's/^/e1_/p' <lines1
164 if [ $SUN -eq 1 ] ; then
165 echo SunOS
sed prints only with
-n
167 $SED -e 's/^/e1_/p' -e 's/^/e2_/p' lines1
170 if [ $SUN -eq 1 ] ; then
171 echo SunOS
sed prints only with
-n
173 $SED -f script1
-f script2 lines1
176 if [ $GNU -eq 1 -o $SUN -eq 1 ] ; then
177 echo GNU and SunOS
sed fail this following older POSIX draft
179 $SED -e 's/^/e1_/p' -f script1 lines1
182 if [ $SUN -eq 1 ] ; then
183 echo SunOS
sed prints only with
-n
185 $SED -e 's/^/e1_/p' lines1 lines1
188 mark
'1.17' ; $SED p
<lines1 lines1
195 mark
'1.18' ; $SED -f script1
<lines1 lines1
200 echo Testing address ranges
201 mark
'2.1' ; $SED -n -e '4p' lines1
202 mark
'2.2' ; $SED -n -e '20p' lines1 lines2
203 mark
'2.3' ; $SED -n -e '$p' lines1
204 mark
'2.4' ; $SED -n -e '$p' lines1 lines2
205 mark
'2.5' ; $SED -n -e '$a\
207 mark
'2.6' ; $SED -n -e '$p' lines1
/dev
/null lines2
208 # Should not print anything
209 mark
'2.7' ; $SED -n -e '20p' lines1
210 mark
'2.8' ; $SED -n -e '0p' lines1
211 mark
'2.9' ; $SED -n '/l1_7/p' lines1
212 mark
'2.10' ; $SED -n ' /l1_7/ p' lines1
214 if [ $BSD -eq 1 ] ; then
215 echo BSD
sed fails this
test
217 if [ $GNU -eq 1 ] ; then
218 echo GNU
sed fails this
220 $SED -n '\_l1\_7_p' lines1
221 mark
'2.12' ; $SED -n '1,4p' lines1
222 mark
'2.13' ; $SED -n '1,$p' lines1 lines2
223 mark
'2.14' ; $SED -n '1,/l2_9/p' lines1 lines2
224 mark
'2.15' ; $SED -n '/4/,$p' lines1 lines2
225 mark
'2.16' ; $SED -n '/4/,20p' lines1 lines2
226 mark
'2.17' ; $SED -n '/4/,/10/p' lines1 lines2
227 mark
'2.18' ; $SED -n '/l2_3/,/l1_8/p' lines1 lines2
229 if [ $GNU -eq 1 ] ; then
230 echo GNU
sed fails this
232 $SED -n '12,3p' lines1 lines2
234 if [ $GNU -eq 1 ] ; then
235 echo GNU
sed fails this
237 $SED -n '/l1_7/,3p' lines1 lines2
242 echo Brace and other grouping
243 mark
'3.1' ; $SED -e '
249 mark
'3.2' ; $SED -e '
257 mark
'3.3' ; $SED -e '
265 mark
'3.4' ; $SED -e '4,12!s/^/^/' lines1
270 echo Testing a c d and i commands
271 mark
'4.1' ; $SED -n -e '
277 mark
'4.2' ; $SED -n -e '
285 if [ $GNU -eq 1 ] ; then
286 echo GNU
sed fails this
295 mark
'4.4' ; $SED -n -e '
299 mark
'4.5' ; $SED -n -e '
303 mark
'4.6' ; $SED -n -e '
307 # SunOS and GNU sed behave differently. We follow POSIX
308 # mark '4.7' ; $SED -n -e '
312 mark
'4.8' ; $SED d
<lines1
317 echo Testing labels and branching
318 mark
'5.1' ; $SED -n -e '
335 if [ $BSD -eq 1 ] ; then
336 echo BSD
sed fails this
test
345 # SunOS sed behaves differently here. Clarification needed.
346 # mark '5.3' ; $SED -n -e '
354 # Check that t clears the substitution done flag
355 mark
'5.4' ; $SED -n -e '
365 # Check that reading a line clears the substitution done flag
367 if [ $BSD -eq 1 ] ; then
368 echo BSD
sed fails this
test
378 mark
'5.6' ; $SED 5q lines1
379 mark
'5.7' ; $SED -e '
383 # Branch across block boundary
384 mark
'5.8' ; $SED -e '
394 echo Pattern space commands
395 # Check that the pattern space is deleted
396 mark
'6.1' ; $SED -n -e '
401 mark
'6.2' ; $SED -n -e '
405 # SunOS sed refused to print here
406 # mark '6.3' ; $SED -e '
414 mark
'6.4' ; $SED -e '
424 mark
'6.5' ; $SED -e '4n' lines1
425 mark
'6.6' ; $SED -n -e '4n' lines1
430 echo Testing print and
file routines
431 awk 'END {for (i = 1; i < 256; i++) printf("%c", i);print "\n"}' \
433 # GNU and SunOS sed behave differently here
435 if [ $BSD -eq 1 ] ; then
436 echo 'BSD sed drops core on this one; TEST SKIPPED'
440 mark
'7.2' ; $SED -e '/l2_/=' lines1 lines2
442 mark
'7.3' ; $SED -e '3,12w lines4' lines1
445 mark
'7.4' ; $SED -e '4r lines2' lines1
446 mark
'7.5' ; $SED -e '5r /dev/dds' lines1
447 mark
'7.6' ; $SED -e '6r /dev/null' lines1
449 if [ $BSD -eq 1 -o $GNU -eq 1 -o $SUN -eq 1 ] ; then
450 echo BSD
, GNU and SunOS cannot pass this one
452 sed '200q' $DICT |
sed 's$.*$s/^/&/w tmpdir/&$' >script1
455 $SED -f script1 lines1
460 if [ $BSD -eq 1 ] ; then
461 echo BSD
sed cannot pass
7.7
465 $SED -n -e '$p' lines3
/dev
/null
472 echo Testing substitution commands
473 mark
'8.1' ; $SED -e 's/./X/g' lines1
474 mark
'8.2' ; $SED -e 's,.,X,g' lines1
475 # GNU and SunOS sed thinks we are escaping . as wildcard, not as separator
476 # mark '8.3' ; $SED -e 's.\..X.g' lines1
477 # POSIX does not say that this should work
478 # mark '8.4' ; $SED -e 's/[/]/Q/' lines1
479 mark
'8.4' ; $SED -e 's/[\/]/Q/' lines1
480 mark
'8.5' ; $SED -e 's_\__X_' lines1
481 mark
'8.6' ; $SED -e 's/./(&)/g' lines1
482 mark
'8.7' ; $SED -e 's/./(\&)/g' lines1
483 mark
'8.8' ; $SED -e 's/\(.\)\(.\)\(.\)/x\3x\2x\1/g' lines1
484 mark
'8.9' ; $SED -e 's/_/u0\
488 if [ $BSD -eq 1 -o $GNU -eq 1 ] ; then
489 echo 'BSD/GNU sed do not understand digit flags on s commands'
491 $SED -e 's/./X/4' lines1
493 mark
'8.11' ; $SED -e 's/1/X/w lines4' lines1
496 mark
'8.12' ; $SED -e 's/[123]/X/g' lines1
497 mark
'8.13' ; $SED -e 'y/0123456789/9876543210/' lines1
499 if [ $BSD -eq 1 -o $GNU -eq 1 -o $SUN -eq 1 ] ; then
500 echo BSD
/GNU
/SUN
sed fail this
test
502 $SED -e 'y10\123456789198765432\101' lines1
504 mark
'8.15' ; $SED -e '1N;2y/\n/X/' lines1
506 if [ $BSD -eq 1 ] ; then
507 echo 'BSD sed does not handle branch defined REs'
509 echo 'eeefff' |
$SED -e 'p' -e 's/e/X/p' -e ':x' \
510 -e 's//Y/p' -e '/f/bx'
523 $TEST -f /dev
/dds
&& exit 1
524 $TEST p
/dev
/dds
&& exit 1
525 $TEST -f /bin
/sh
&& exit 1
528 $TEST '/hello/' && exit 1
529 $TEST '1,/hello/' && exit 1
530 $TEST -e '-5p' && exit 1
531 $TEST '/jj' && exit 1
532 $TEST 'a hello' && exit 1
533 $TEST 'a \ hello' && exit 1
534 $TEST 'b foo' && exit 1
535 $TEST 'd hello' && exit 1
536 $TEST 's/aa' && exit 1
537 $TEST 's/aa/' && exit 1
538 $TEST 's/a/b' && exit 1
539 $TEST 's/a/b/c/d' && exit 1
540 $TEST 's/a/b/ 1 2' && exit 1
541 $TEST 's/a/b/ 1 g' && exit 1
542 $TEST 's/a/b/w' && exit 1
543 $TEST 'y/aa' && exit 1
544 $TEST 'y/aa/b/' && exit 1
545 $TEST 'y/aa/' && exit 1
546 $TEST 'y/a/b' && exit 1
547 $TEST 'y/a/b/c/d' && exit 1
549 $TEST supercalifrangolisticexprialidociussupercalifrangolisticexcius