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 # 4. Neither the name of the University nor the names of its contributors
16 # may be used to endorse or promote products derived from this software
17 # without specific prior written permission.
19 # THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
20 # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 # ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
23 # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24 # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25 # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26 # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27 # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28 # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 # @(#)sed.test 8.1 (Berkeley) 6/6/93
36 # sed Regression Tests
38 # The following files are created:
39 # lines[1-4], script1, script2
40 # Two directories *.out contain the test results
46 TEST=`cd ..; make whereobj`/sed
48 DICT=/usr/share/dict/words
52 awk 'END { for (i = 1; i < 15; i++) print "l1_" i}' </dev/null >lines1
53 awk 'END { for (i = 1; i < 10; i++) print "l2_" i}' </dev/null >lines2
57 # Set these flags to get messages about known problems
68 diff -c $BASELOG $TESTLOG | more
94 exec >"$DIR/${MARK}_$1"
96 # Uncomment this line to match tests with sed error messages
97 echo "Test $1:$MARK" >&5
103 echo Testing argument parsing
105 if [ $SUN -eq 1 ] ; then
106 echo SunOS sed prints only with -n
108 $SED 's/^/e1_/p' lines1
110 mark '1.2' ; $SED -n 's/^/e1_/p' lines1
112 if [ $SUN -eq 1 ] ; then
113 echo SunOS sed prints only with -n
115 $SED 's/^/e1_/p' <lines1
117 mark '1.4' ; $SED -n 's/^/e1_/p' <lines1
120 if [ $SUN -eq 1 ] ; then
121 echo SunOS sed fails this
124 echo 's/^/s1_/p' >script1
125 echo 's/^/s2_/p' >script2
127 if [ $SUN -eq 1 ] ; then
128 echo SunOS sed prints only with -n
130 $SED -f script1 lines1
133 if [ $SUN -eq 1 ] ; then
134 echo SunOS sed prints only with -n
136 $SED -f script1 <lines1
139 if [ $SUN -eq 1 ] ; then
140 echo SunOS sed prints only with -n
142 $SED -e 's/^/e1_/p' lines1
145 if [ $SUN -eq 1 ] ; then
146 echo SunOS sed prints only with -n
148 $SED -e 's/^/e1_/p' <lines1
150 mark '1.9' ; $SED -n -f script1 lines1
151 mark '1.10' ; $SED -n -f script1 <lines1
152 mark '1.11' ; $SED -n -e 's/^/e1_/p' lines1
154 if [ $SUN -eq 1 ] ; then
155 echo SunOS sed prints only with -n
157 $SED -n -e 's/^/e1_/p' <lines1
160 if [ $SUN -eq 1 ] ; then
161 echo SunOS sed prints only with -n
163 $SED -e 's/^/e1_/p' -e 's/^/e2_/p' lines1
166 if [ $SUN -eq 1 ] ; then
167 echo SunOS sed prints only with -n
169 $SED -f script1 -f script2 lines1
172 if [ $GNU -eq 1 -o $SUN -eq 1 ] ; then
173 echo GNU and SunOS sed fail this following older POSIX draft
175 $SED -e 's/^/e1_/p' -f script1 lines1
178 if [ $SUN -eq 1 ] ; then
179 echo SunOS sed prints only with -n
181 $SED -e 's/^/e1_/p' lines1 lines1
184 mark '1.17' ; $SED p <lines1 lines1
191 mark '1.18' ; $SED -f script1 <lines1 lines1
196 echo Testing address ranges
197 mark '2.1' ; $SED -n -e '4p' lines1
198 mark '2.2' ; $SED -n -e '20p' lines1 lines2
199 mark '2.3' ; $SED -n -e '$p' lines1
200 mark '2.4' ; $SED -n -e '$p' lines1 lines2
201 mark '2.5' ; $SED -n -e '$a\
203 mark '2.6' ; $SED -n -e '$p' lines1 /dev/null lines2
204 # Should not print anything
205 mark '2.7' ; $SED -n -e '20p' lines1
206 mark '2.8' ; $SED -n -e '0p' lines1
207 mark '2.9' ; $SED -n '/l1_7/p' lines1
208 mark '2.10' ; $SED -n ' /l1_7/ p' lines1
210 if [ $BSD -eq 1 ] ; then
211 echo BSD sed fails this test
213 if [ $GNU -eq 1 ] ; then
214 echo GNU sed fails this
216 $SED -n '\_l1\_7_p' lines1
217 mark '2.12' ; $SED -n '1,4p' lines1
218 mark '2.13' ; $SED -n '1,$p' lines1 lines2
219 mark '2.14' ; $SED -n '1,/l2_9/p' lines1 lines2
220 mark '2.15' ; $SED -n '/4/,$p' lines1 lines2
221 mark '2.16' ; $SED -n '/4/,20p' lines1 lines2
222 mark '2.17' ; $SED -n '/4/,/10/p' lines1 lines2
223 mark '2.18' ; $SED -n '/l2_3/,/l1_8/p' lines1 lines2
225 if [ $GNU -eq 1 ] ; then
226 echo GNU sed fails this
228 $SED -n '12,3p' lines1 lines2
230 if [ $GNU -eq 1 ] ; then
231 echo GNU sed fails this
233 $SED -n '/l1_7/,3p' lines1 lines2
238 echo Brace and other grouping
239 mark '3.1' ; $SED -e '
245 mark '3.2' ; $SED -e '
253 mark '3.3' ; $SED -e '
261 mark '3.4' ; $SED -e '4,12!s/^/^/' lines1
266 echo Testing a c d and i commands
267 mark '4.1' ; $SED -n -e '
273 mark '4.2' ; $SED -n -e '
281 if [ $GNU -eq 1 ] ; then
282 echo GNU sed fails this
291 mark '4.4' ; $SED -n -e '
295 mark '4.5' ; $SED -n -e '
299 mark '4.6' ; $SED -n -e '
303 # SunOS and GNU sed behave differently. We follow POSIX
304 # mark '4.7' ; $SED -n -e '
308 mark '4.8' ; $SED d <lines1
313 echo Testing labels and branching
314 mark '5.1' ; $SED -n -e '
331 if [ $BSD -eq 1 ] ; then
332 echo BSD sed fails this test
341 # SunOS sed behaves differently here. Clarification needed.
342 # mark '5.3' ; $SED -n -e '
350 # Check that t clears the substitution done flag
351 mark '5.4' ; $SED -n -e '
361 # Check that reading a line clears the substitution done flag
363 if [ $BSD -eq 1 ] ; then
364 echo BSD sed fails this test
374 mark '5.6' ; $SED 5q lines1
375 mark '5.7' ; $SED -e '
379 # Branch across block boundary
380 mark '5.8' ; $SED -e '
390 echo Pattern space commands
391 # Check that the pattern space is deleted
392 mark '6.1' ; $SED -n -e '
397 mark '6.2' ; $SED -n -e '
401 # SunOS sed refused to print here
402 # mark '6.3' ; $SED -e '
410 mark '6.4' ; $SED -e '
420 mark '6.5' ; $SED -e '4n' lines1
421 mark '6.6' ; $SED -n -e '4n' lines1
426 echo Testing print and file routines
427 awk 'END {for (i = 1; i < 256; i++) printf("%c", i);print "\n"}' \
429 # GNU and SunOS sed behave differently here
432 mark '7.2' ; $SED -e '/l2_/=' lines1 lines2
434 mark '7.3' ; $SED -e '3,12w lines4' lines1
437 mark '7.4' ; $SED -e '4r lines2' lines1
438 mark '7.5' ; $SED -e '5r /dev/dds' lines1
439 mark '7.6' ; $SED -e '6r /dev/null' lines1
441 if [ $BSD -eq 1 -o $GNU -eq 1 -o $SUN -eq 1 ] ; then
442 echo BSD, GNU and SunOS cannot pass this one
444 sed '200q' $DICT | sed 's$.*$s/^/&/w tmpdir/&$' >script1
447 $SED -f script1 lines1
452 if [ $BSD -eq 1 ] ; then
453 echo BSD sed cannot pass 7.7
457 $SED -n -e '$p' lines3 /dev/null
464 echo Testing substitution commands
465 mark '8.1' ; $SED -e 's/./X/g' lines1
466 mark '8.2' ; $SED -e 's,.,X,g' lines1
467 # GNU and SunOS sed thinks we are escaping . as wildcard, not as separator
468 # mark '8.3' ; $SED -e 's.\..X.g' lines1
469 # POSIX does not say that this should work
470 # mark '8.4' ; $SED -e 's/[/]/Q/' lines1
471 mark '8.4' ; $SED -e 's/[\/]/Q/' lines1
472 mark '8.5' ; $SED -e 's_\__X_' lines1
473 mark '8.6' ; $SED -e 's/./(&)/g' lines1
474 mark '8.7' ; $SED -e 's/./(\&)/g' lines1
475 mark '8.8' ; $SED -e 's/\(.\)\(.\)\(.\)/x\3x\2x\1/g' lines1
476 mark '8.9' ; $SED -e 's/_/u0\
480 if [ $BSD -eq 1 -o $GNU -eq 1 ] ; then
481 echo 'BSD/GNU sed do not understand digit flags on s commands'
483 $SED -e 's/./X/4' lines1
485 mark '8.11' ; $SED -e 's/1/X/w lines4' lines1
488 mark '8.12' ; $SED -e 's/[123]/X/g' lines1
489 mark '8.13' ; $SED -e 'y/0123456789/9876543210/' lines1
491 if [ $BSD -eq 1 -o $GNU -eq 1 -o $SUN -eq 1 ] ; then
492 echo BSD/GNU/SUN sed fail this test
494 $SED -e 'y10\123456789198765432\101' lines1
496 mark '8.15' ; $SED -e '1N;2y/\n/X/' lines1
498 echo 'eeefff' | $SED -e '
503 # Establish limit counter in the hold space
504 # GNU sed version 3.02 enters into an infinite loop here
525 $TEST -f /dev/dds && exit 1
526 $TEST p /dev/dds && exit 1
527 $TEST -f /bin/sh && exit 1
530 $TEST '/hello/' && exit 1
531 $TEST '1,/hello/' && exit 1
532 $TEST -e '-5p' && exit 1
533 $TEST '/jj' && exit 1
534 $TEST 'a hello' && exit 1
535 $TEST 'a \ hello' && exit 1
536 $TEST 'b foo' && exit 1
537 $TEST 'd hello' && exit 1
538 $TEST 's/aa' && exit 1
539 $TEST 's/aa/' && exit 1
540 $TEST 's/a/b' && exit 1
541 $TEST 's/a/b/c/d' && exit 1
542 $TEST 's/a/b/ 1 2' && exit 1
543 $TEST 's/a/b/ 1 g' && exit 1
544 $TEST 's/a/b/w' && exit 1
545 $TEST 'y/aa' && exit 1
546 $TEST 'y/aa/b/' && exit 1
547 $TEST 'y/aa/' && exit 1
548 $TEST 'y/a/b' && exit 1
549 $TEST 'y/a/b/c/d' && exit 1
551 $TEST supercalifrangolisticexprialidociussupercalifrangolisticexcius