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 directory regress.test.out contains the expected test results
40 # These are the regression tests created during the development of the
41 # BSD sed. The reference file naming scheme used in this script can't
42 # handle gracefully the insertion of new tests between existing ones.
43 # Therefore, either use the new m4-based regress.t framework, or add
44 # tests after the last existing test.
48 REGRESS=regress.multitest.out
49 DICT=/usr/share/dict/words
51 awk 'END { for (i = 1; i < 15; i++) print "l1_" i}' </dev/null >lines1
52 awk 'END { for (i = 1; i < 10; i++) print "l2_" i}' </dev/null >lines2
60 # Remove temporary files
61 rm -f current.out lines[1-4] script[1-2]
78 # Handle the result of the last test
82 # Display a test's result
85 if [ "$TODO" = '1' ] ; then
90 if ! [ -r $REGRESS/${MARK}_${TESTNAME} ] ; then
91 echo "Seeding $REGRESS/${MARK}_${TESTNAME} with current result" 1>&2
92 cp current.out $REGRESS/${MARK}_${TESTNAME}
94 if diff -c $REGRESS/${MARK}_${TESTNAME} current.out ; then
95 echo "ok $MARK $TESTNAME # $TODO$COMMENT"
97 echo "not ok $MARK $TESTNAME # $TODO$COMMENT"
101 # Mark the beginning of each test
104 [ $MARK -gt 0 ] && result
105 MARK=`expr $MARK + 1`
113 COMMENT='Argument parsing - first type'
115 $SED 's/^/e1_/p' lines1
116 mark '1.2' ; $SED -n 's/^/e1_/p' lines1
118 $SED 's/^/e1_/p' <lines1
119 mark '1.4' ; $SED -n 's/^/e1_/p' <lines1
120 COMMENT='Argument parsing - second type'
123 echo 's/^/s1_/p' >script1
124 echo 's/^/s2_/p' >script2
126 $SED -f script1 lines1
128 $SED -f script1 <lines1
130 $SED -e 's/^/e1_/p' lines1
132 $SED -e 's/^/e1_/p' <lines1
133 mark '1.9' ; $SED -n -f script1 lines1
134 mark '1.10' ; $SED -n -f script1 <lines1
135 mark '1.11' ; $SED -n -e 's/^/e1_/p' lines1
137 $SED -n -e 's/^/e1_/p' <lines1
139 $SED -e 's/^/e1_/p' -e 's/^/e2_/p' lines1
141 $SED -f script1 -f script2 lines1
143 $SED -e 's/^/e1_/p' -f script1 lines1
145 $SED -e 's/^/e1_/p' lines1 lines1
147 mark '1.17' ; $SED p <lines1 lines1
154 mark '1.18' ; $SED -f script1 <lines1 lines1
159 COMMENT='Address ranges'
160 mark '2.1' ; $SED -n -e '4p' lines1
161 mark '2.2' ; $SED -n -e '20p' lines1 lines2
162 mark '2.3' ; $SED -n -e '$p' lines1
163 mark '2.4' ; $SED -n -e '$p' lines1 lines2
164 mark '2.5' ; $SED -n -e '$a\
166 mark '2.6' ; $SED -n -e '$p' lines1 /dev/null lines2
167 # Should not print anything
168 mark '2.7' ; $SED -n -e '20p' lines1
169 mark '2.8' ; $SED -n -e '/NOTFOUND/p' lines1
170 mark '2.9' ; $SED -n '/l1_7/p' lines1
171 mark '2.10' ; $SED -n ' /l1_7/ p' lines1
172 mark '2.11' ; $SED -n '\_l1\_7_p' lines1
173 mark '2.12' ; $SED -n '1,4p' lines1
174 mark '2.13' ; $SED -n '1,$p' lines1 lines2
175 mark '2.14' ; $SED -n '1,/l2_9/p' lines1 lines2
176 mark '2.15' ; $SED -n '/4/,$p' lines1 lines2
177 mark '2.16' ; $SED -n '/4/,20p' lines1 lines2
178 mark '2.17' ; $SED -n '/4/,/10/p' lines1 lines2
179 mark '2.18' ; $SED -n '/l2_3/,/l1_8/p' lines1 lines2
180 mark '2.19' ; $SED -n '12,3p' lines1 lines2
181 mark '2.20' ; $SED -n '/l1_7/,3p' lines1 lines2
186 COMMENT='Brace and other grouping'
187 mark '3.1' ; $SED -e '
193 mark '3.2' ; $SED -e '
201 mark '3.3' ; $SED -e '
209 mark '3.4' ; $SED -e '4,12!s/^/^/' lines1
214 COMMENT='Commands a c d and i'
215 mark '4.1' ; $SED -n -e '
221 mark '4.2' ; $SED -n -e '
236 mark '4.4' ; $SED -n -e '
240 mark '4.5' ; $SED -n -e '
244 mark '4.6' ; $SED -n -e '
248 # SunOS and GNU sed behave differently. We follow POSIX
249 mark '4.7' ; $SED -n -e '
253 mark '4.8' ; $SED d <lines1
258 COMMENT='Labels and branching'
259 mark '5.1' ; $SED -n -e '
283 # SunOS and GNU sed behave as follows: lines 9-$ aren't printed at all
284 mark '5.3' ; $SED -n -e '
292 # Check that t clears the substitution done flag
293 mark '5.4' ; $SED -n -e '
303 # Check that reading a line clears the substitution done flag
313 mark '5.6' ; $SED 5q lines1
314 mark '5.7' ; $SED -e '
318 # Branch across block boundary
319 mark '5.8' ; $SED -e '
329 COMMENT='Pattern space commands'
330 # Check that the pattern space is deleted
331 mark '6.1' ; $SED -n -e '
336 mark '6.2' ; $SED -n -e '
341 $SED -e 'N;N;N;D' lines1
342 mark '6.4' ; $SED -e '
352 mark '6.5' ; $SED -e '4n' lines1
353 mark '6.6' ; $SED -n -e '4n' lines1
358 COMMENT='Print and file routines'
359 awk 'END {for (i = 1; i < 256; i++) printf("%c", i);print "\n"}' \
361 # GNU and SunOS sed behave differently here
364 mark '7.2' ; $SED -e '/l2_/=' lines1 lines2
366 mark '7.3' ; $SED -e '3,12w lines4' lines1
369 mark '7.4' ; $SED -e '4r lines2' lines1
370 mark '7.5' ; $SED -e '5r /dev/dds' lines1
371 mark '7.6' ; $SED -e '6r /dev/null' lines1
373 sed '200q' $DICT | sed 's$.*$s/^/&/w tmpdir/&$' >script1
376 $SED -f script1 lines1
383 $SED -n -e '$p' lines3 /dev/null
389 COMMENT='Substitution commands'
390 mark '8.1' ; $SED -e 's/./X/g' lines1
391 mark '8.2' ; $SED -e 's,.,X,g' lines1
392 # SunOS sed thinks we are escaping . as wildcard, not as separator
394 $SED -e 's.\..X.g' lines1
395 mark '8.4' ; $SED -e 's/[\/]/Q/' lines1
396 mark '8.5' ; $SED -e 's_\__X_' lines1
397 mark '8.6' ; $SED -e 's/./(&)/g' lines1
398 mark '8.7' ; $SED -e 's/./(\&)/g' lines1
399 mark '8.8' ; $SED -e 's/\(.\)\(.\)\(.\)/x\3x\2x\1/g' lines1
400 mark '8.9' ; $SED -e 's/_/u0\
404 $SED -e 's/./X/4' lines1
406 mark '8.11' ; $SED -e 's/1/X/w lines4' lines1
407 COMMENT='s wfile results'
409 mark '8.12' ; $SED -e 's/[123]/X/g' lines1
410 mark '8.13' ; $SED -e 'y/0123456789/9876543210/' lines1
412 $SED -e 'y10\123456789198765432\101' lines1
413 mark '8.15' ; $SED -e '1N;2y/\n/X/' lines1
415 echo 'eeefff' | $SED -e '
420 # Establish limit counter in the hold space
421 # GNU sed version 3.02 enters into an infinite loop here
431 # POSIX does not say that this should work,
432 # but it does for GNU, BSD, and SunOS
433 mark '8.17' ; $SED -e 's/[/]/Q/' lines1
438 COMMENT='Error cases'
439 mark '9.1' ; $SED -x 2>/dev/null ; echo $?
440 mark '9.2' ; $SED -f 2>/dev/null ; echo $?
441 mark '9.3' ; $SED -e 2>/dev/null ; echo $?
442 mark '9.4' ; $SED -f /dev/xyzzyxyzy 2>/dev/null ; echo $?
443 mark '9.5' ; $SED p /dev/xyzzyxyzy 2>/dev/null ; echo $?
444 mark '9.6' ; $SED -f /bin/sh 2>/dev/null ; echo $?
445 mark '9.7' ; $SED '{' 2>/dev/null ; echo $?
446 mark '9.8' ; $SED '{' 2>/dev/null ; echo $?
447 mark '9.9' ; $SED '/hello/' 2>/dev/null ; echo $?
448 mark '9.10' ; $SED '1,/hello/' 2>/dev/null ; echo $?
449 mark '9.11' ; $SED -e '-5p' 2>/dev/null ; echo $?
450 mark '9.12' ; $SED '/jj' 2>/dev/null ; echo $?
451 mark '9.13' ; $SED 'a hello' 2>/dev/null ; echo $?
452 mark '9.14' ; $SED 'a \ hello' 2>/dev/null ; echo $?
453 mark '9.15' ; $SED 'b foo' 2>/dev/null ; echo $?
454 mark '9.16' ; $SED 'd hello' 2>/dev/null ; echo $?
455 mark '9.17' ; $SED 's/aa' 2>/dev/null ; echo $?
456 mark '9.18' ; $SED 's/aa/' 2>/dev/null ; echo $?
457 mark '9.19' ; $SED 's/a/b' 2>/dev/null ; echo $?
458 mark '9.20' ; $SED 's/a/b/c/d' 2>/dev/null ; echo $?
459 mark '9.21' ; $SED 's/a/b/ 1 2' 2>/dev/null ; echo $?
460 mark '9.22' ; $SED 's/a/b/ 1 g' 2>/dev/null ; echo $?
461 mark '9.23' ; $SED 's/a/b/w' 2>/dev/null ; echo $?
462 mark '9.24' ; $SED 'y/aa' 2>/dev/null ; echo $?
463 mark '9.25' ; $SED 'y/aa/b/' 2>/dev/null ; echo $?
464 mark '9.26' ; $SED 'y/aa/' 2>/dev/null ; echo $?
465 mark '9.27' ; $SED 'y/a/b' 2>/dev/null ; echo $?
466 mark '9.28' ; $SED 'y/a/b/c/d' 2>/dev/null ; echo $?
467 mark '9.29' ; $SED '!' 2>/dev/null ; echo $?
468 mark '9.30' ; $SED supercalifrangolisticexprialidociussupercalifrangolisticexcius 2>/dev/null ; echo $?
469 mark '9.31' ; $SED '' /dev/null 2>/dev/null ; echo $?