3 # Copyright (c) 1992 Diomidis Spinellis.
4 # Copyright (c) 1992, 1993
5 # The Regents of the University of California. All rights reserved.
7 # Redistribution and use in source and binary forms, with or without
8 # modification, are permitted provided that the following conditions
10 # 1. Redistributions of source code must retain the above copyright
11 # notice, this list of conditions and the following disclaimer.
12 # 2. Redistributions in binary form must reproduce the above copyright
13 # notice, this list of conditions and the following disclaimer in the
14 # documentation and/or other materials provided with the distribution.
15 # 3. All advertising materials mentioning features or use of this software
16 # must display the following acknowledgement:
17 # This product includes software developed by the University of
18 # California, Berkeley and its contributors.
19 # 4. Neither the name of the University nor the names of its contributors
20 # may be used to endorse or promote products derived from this software
21 # without specific prior written permission.
23 # THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
24 # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25 # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26 # ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
27 # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28 # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
29 # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30 # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31 # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
32 # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
35 # @(#)sed.test 8.1 (Berkeley) 6/6/93
38 # sed Regression Tests
40 # The following files are created:
41 # lines[1-4], script1, script2
42 # Two directories *.out contain the test results
48 TEST=`cd ..; make whereobj`/sed
50 DICT=/usr/share/dict/words
54 awk 'END { for (i = 1; i < 15; i++) print "l1_" i}' </dev/null >lines1
55 awk 'END { for (i = 1; i < 10; i++) print "l2_" i}' </dev/null >lines2
59 # Set these flags to get messages about known problems
70 diff -c $BASELOG $TESTLOG | more
96 exec >"$DIR/${MARK}_$1"
98 # Uncomment this line to match tests with sed error messages
99 echo "Test $1:$MARK" >&5
105 echo Testing argument parsing
107 if [ $SUN -eq 1 ] ; then
108 echo SunOS sed prints only with -n
110 $SED 's/^/e1_/p' lines1
112 mark '1.2' ; $SED -n 's/^/e1_/p' lines1
114 if [ $SUN -eq 1 ] ; then
115 echo SunOS sed prints only with -n
117 $SED 's/^/e1_/p' <lines1
119 mark '1.4' ; $SED -n 's/^/e1_/p' <lines1
122 if [ $SUN -eq 1 ] ; then
123 echo SunOS sed fails this
126 echo 's/^/s1_/p' >script1
127 echo 's/^/s2_/p' >script2
129 if [ $SUN -eq 1 ] ; then
130 echo SunOS sed prints only with -n
132 $SED -f script1 lines1
135 if [ $SUN -eq 1 ] ; then
136 echo SunOS sed prints only with -n
138 $SED -f script1 <lines1
141 if [ $SUN -eq 1 ] ; then
142 echo SunOS sed prints only with -n
144 $SED -e 's/^/e1_/p' lines1
147 if [ $SUN -eq 1 ] ; then
148 echo SunOS sed prints only with -n
150 $SED -e 's/^/e1_/p' <lines1
152 mark '1.9' ; $SED -n -f script1 lines1
153 mark '1.10' ; $SED -n -f script1 <lines1
154 mark '1.11' ; $SED -n -e 's/^/e1_/p' lines1
156 if [ $SUN -eq 1 ] ; then
157 echo SunOS sed prints only with -n
159 $SED -n -e 's/^/e1_/p' <lines1
162 if [ $SUN -eq 1 ] ; then
163 echo SunOS sed prints only with -n
165 $SED -e 's/^/e1_/p' -e 's/^/e2_/p' lines1
168 if [ $SUN -eq 1 ] ; then
169 echo SunOS sed prints only with -n
171 $SED -f script1 -f script2 lines1
174 if [ $GNU -eq 1 -o $SUN -eq 1 ] ; then
175 echo GNU and SunOS sed fail this following older POSIX draft
177 $SED -e 's/^/e1_/p' -f script1 lines1
180 if [ $SUN -eq 1 ] ; then
181 echo SunOS sed prints only with -n
183 $SED -e 's/^/e1_/p' lines1 lines1
186 mark '1.17' ; $SED p <lines1 lines1
193 mark '1.18' ; $SED -f script1 <lines1 lines1
198 echo Testing address ranges
199 mark '2.1' ; $SED -n -e '4p' lines1
200 mark '2.2' ; $SED -n -e '20p' lines1 lines2
201 mark '2.3' ; $SED -n -e '$p' lines1
202 mark '2.4' ; $SED -n -e '$p' lines1 lines2
203 mark '2.5' ; $SED -n -e '$a\
205 mark '2.6' ; $SED -n -e '$p' lines1 /dev/null lines2
206 # Should not print anything
207 mark '2.7' ; $SED -n -e '20p' lines1
208 mark '2.8' ; $SED -n -e '0p' lines1
209 mark '2.9' ; $SED -n '/l1_7/p' lines1
210 mark '2.10' ; $SED -n ' /l1_7/ p' lines1
212 if [ $BSD -eq 1 ] ; then
213 echo BSD sed fails this test
215 if [ $GNU -eq 1 ] ; then
216 echo GNU sed fails this
218 $SED -n '\_l1\_7_p' lines1
219 mark '2.12' ; $SED -n '1,4p' lines1
220 mark '2.13' ; $SED -n '1,$p' lines1 lines2
221 mark '2.14' ; $SED -n '1,/l2_9/p' lines1 lines2
222 mark '2.15' ; $SED -n '/4/,$p' lines1 lines2
223 mark '2.16' ; $SED -n '/4/,20p' lines1 lines2
224 mark '2.17' ; $SED -n '/4/,/10/p' lines1 lines2
225 mark '2.18' ; $SED -n '/l2_3/,/l1_8/p' lines1 lines2
227 if [ $GNU -eq 1 ] ; then
228 echo GNU sed fails this
230 $SED -n '12,3p' lines1 lines2
232 if [ $GNU -eq 1 ] ; then
233 echo GNU sed fails this
235 $SED -n '/l1_7/,3p' lines1 lines2
240 echo Brace and other grouping
241 mark '3.1' ; $SED -e '
247 mark '3.2' ; $SED -e '
255 mark '3.3' ; $SED -e '
263 mark '3.4' ; $SED -e '4,12!s/^/^/' lines1
268 echo Testing a c d and i commands
269 mark '4.1' ; $SED -n -e '
275 mark '4.2' ; $SED -n -e '
283 if [ $GNU -eq 1 ] ; then
284 echo GNU sed fails this
293 mark '4.4' ; $SED -n -e '
297 mark '4.5' ; $SED -n -e '
301 mark '4.6' ; $SED -n -e '
305 # SunOS and GNU sed behave differently. We follow POSIX
306 # mark '4.7' ; $SED -n -e '
310 mark '4.8' ; $SED d <lines1
315 echo Testing labels and branching
316 mark '5.1' ; $SED -n -e '
333 if [ $BSD -eq 1 ] ; then
334 echo BSD sed fails this test
343 # SunOS sed behaves differently here. Clarification needed.
344 # mark '5.3' ; $SED -n -e '
352 # Check that t clears the substitution done flag
353 mark '5.4' ; $SED -n -e '
363 # Check that reading a line clears the substitution done flag
365 if [ $BSD -eq 1 ] ; then
366 echo BSD sed fails this test
376 mark '5.6' ; $SED 5q lines1
377 mark '5.7' ; $SED -e '
381 # Branch across block boundary
382 mark '5.8' ; $SED -e '
392 echo Pattern space commands
393 # Check that the pattern space is deleted
394 mark '6.1' ; $SED -n -e '
399 mark '6.2' ; $SED -n -e '
403 # SunOS sed refused to print here
404 # mark '6.3' ; $SED -e '
412 mark '6.4' ; $SED -e '
422 mark '6.5' ; $SED -e '4n' lines1
423 mark '6.6' ; $SED -n -e '4n' lines1
428 echo Testing print and file routines
429 awk 'END {for (i = 1; i < 256; i++) printf("%c", i);print "\n"}' \
431 # GNU and SunOS sed behave differently here
433 if [ $BSD -eq 1 ] ; then
434 echo 'BSD sed drops core on this one; TEST SKIPPED'
438 mark '7.2' ; $SED -e '/l2_/=' lines1 lines2
440 mark '7.3' ; $SED -e '3,12w lines4' lines1
443 mark '7.4' ; $SED -e '4r lines2' lines1
444 mark '7.5' ; $SED -e '5r /dev/dds' lines1
445 mark '7.6' ; $SED -e '6r /dev/null' lines1
447 if [ $BSD -eq 1 -o $GNU -eq 1 -o $SUN -eq 1 ] ; then
448 echo BSD, GNU and SunOS cannot pass this one
450 sed '200q' $DICT | sed 's$.*$s/^/&/w tmpdir/&$' >script1
453 $SED -f script1 lines1
458 if [ $BSD -eq 1 ] ; then
459 echo BSD sed cannot pass 7.7
463 $SED -n -e '$p' lines3 /dev/null
470 echo Testing substitution commands
471 mark '8.1' ; $SED -e 's/./X/g' lines1
472 mark '8.2' ; $SED -e 's,.,X,g' lines1
473 # GNU and SunOS sed thinks we are escaping . as wildcard, not as separator
474 # mark '8.3' ; $SED -e 's.\..X.g' lines1
475 # POSIX does not say that this should work
476 # mark '8.4' ; $SED -e 's/[/]/Q/' lines1
477 mark '8.4' ; $SED -e 's/[\/]/Q/' lines1
478 mark '8.5' ; $SED -e 's_\__X_' lines1
479 mark '8.6' ; $SED -e 's/./(&)/g' lines1
480 mark '8.7' ; $SED -e 's/./(\&)/g' lines1
481 mark '8.8' ; $SED -e 's/\(.\)\(.\)\(.\)/x\3x\2x\1/g' lines1
482 mark '8.9' ; $SED -e 's/_/u0\
486 if [ $BSD -eq 1 -o $GNU -eq 1 ] ; then
487 echo 'BSD/GNU sed do not understand digit flags on s commands'
489 $SED -e 's/./X/4' lines1
491 mark '8.11' ; $SED -e 's/1/X/w lines4' lines1
494 mark '8.12' ; $SED -e 's/[123]/X/g' lines1
495 mark '8.13' ; $SED -e 'y/0123456789/9876543210/' lines1
497 if [ $BSD -eq 1 -o $GNU -eq 1 -o $SUN -eq 1 ] ; then
498 echo BSD/GNU/SUN sed fail this test
500 $SED -e 'y10\123456789198765432\101' lines1
502 mark '8.15' ; $SED -e '1N;2y/\n/X/' lines1
504 if [ $BSD -eq 1 ] ; then
505 echo 'BSD sed does not handle branch defined REs'
507 echo 'eeefff' | $SED -e 'p' -e 's/e/X/p' -e ':x' \
508 -e 's//Y/p' -e '/f/bx'
521 $TEST -f /dev/dds && exit 1
522 $TEST p /dev/dds && exit 1
523 $TEST -f /bin/sh && exit 1
526 $TEST '/hello/' && exit 1
527 $TEST '1,/hello/' && exit 1
528 $TEST -e '-5p' && exit 1
529 $TEST '/jj' && exit 1
530 $TEST 'a hello' && exit 1
531 $TEST 'a \ hello' && exit 1
532 $TEST 'b foo' && exit 1
533 $TEST 'd hello' && exit 1
534 $TEST 's/aa' && exit 1
535 $TEST 's/aa/' && exit 1
536 $TEST 's/a/b' && exit 1
537 $TEST 's/a/b/c/d' && exit 1
538 $TEST 's/a/b/ 1 2' && exit 1
539 $TEST 's/a/b/ 1 g' && exit 1
540 $TEST 's/a/b/w' && exit 1
541 $TEST 'y/aa' && exit 1
542 $TEST 'y/aa/b/' && exit 1
543 $TEST 'y/aa/' && exit 1
544 $TEST 'y/a/b' && exit 1
545 $TEST 'y/a/b/c/d' && exit 1
547 $TEST supercalifrangolisticexprialidociussupercalifrangolisticexcius