#!/bin/sh - # # Copyright (c) 1992 Diomidis Spinellis. # Copyright (c) 1992, 1993 # The Regents of the University of California. All rights reserved. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # 2. Redistributions in binary form must reproduce the above copyright # notice, this list of conditions and the following disclaimer in the # documentation and/or other materials provided with the distribution. # 4. Neither the name of the University nor the names of its contributors # may be used to endorse or promote products derived from this software # without specific prior written permission. # # THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE # ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF # SUCH DAMAGE. # # @(#)sed.test 8.1 (Berkeley) 6/6/93 # # $FreeBSD$ # # sed Regression Tests # # The directory regress.test.out contains the expected test results # # These are the regression tests created during the development of the # BSD sed. The reference file naming scheme used in this script can't # handle gracefully the insertion of new tests between existing ones. # Therefore, either use the new m4-based regress.t framework, or add # tests after the last existing test. main() { cd `dirname $0` REGRESS=regress.multitest.out DICT=/usr/share/dict/words awk 'END { for (i = 1; i < 15; i++) print "l1_" i}' lines1 awk 'END { for (i = 1; i < 10; i++) print "l2_" i}' lines2 echo "1..121" exec 4>&1 5>&2 tests exec 1>&4 2>&5 # Remove temporary files rm -f current.out lines[1-4] script[1-2] } tests() { SED=sed MARK=0 test_args test_addr test_group test_acid test_branch test_pattern test_print test_subst test_error # Handle the result of the last test result } # Display a test's result result() { if [ "$TODO" = '1' ] ; then TODO='TODO ' else TODO='' fi if ! [ -r $REGRESS/${MARK}_${TESTNAME} ] ; then echo "Seeding $REGRESS/${MARK}_${TESTNAME} with current result" 1>&2 cp current.out $REGRESS/${MARK}_${TESTNAME} fi if diff -c $REGRESS/${MARK}_${TESTNAME} current.out ; then echo "ok $MARK $TESTNAME # $TODO$COMMENT" else echo "not ok $MARK $TESTNAME # $TODO$COMMENT" fi 1>&4 2>&5 } # Mark the beginning of each test mark() { [ $MARK -gt 0 ] && result MARK=`expr $MARK + 1` TESTNAME=$1 exec 1>&4 2>&5 exec >"current.out" } test_args() { COMMENT='Argument parsing - first type' mark '1.1' $SED 's/^/e1_/p' lines1 mark '1.2' ; $SED -n 's/^/e1_/p' lines1 mark '1.3' $SED 's/^/e1_/p' script1 echo 's/^/s2_/p' >script2 mark '1.5' $SED -f script1 lines1 mark '1.6' $SED -f script1 script1 <lines3 # GNU and SunOS sed behave differently here mark '7.1' $SED -n l lines3 mark '7.2' ; $SED -e '/l2_/=' lines1 lines2 rm -f lines4 mark '7.3' ; $SED -e '3,12w lines4' lines1 COMMENT='w results' cat lines4 mark '7.4' ; $SED -e '4r lines2' lines1 mark '7.5' ; $SED -e '5r /dev/dds' lines1 mark '7.6' ; $SED -e '6r /dev/null' lines1 mark '7.7' sed '200q' $DICT | sed 's$.*$s/^/&/w tmpdir/&$' >script1 rm -rf tmpdir mkdir tmpdir $SED -f script1 lines1 cat tmpdir/* rm -rf tmpdir mark '7.8' echo line1 > lines3 echo "" >> lines3 TODO=1 $SED -n -e '$p' lines3 /dev/null } test_subst() { COMMENT='Substitution commands' mark '8.1' ; $SED -e 's/./X/g' lines1 mark '8.2' ; $SED -e 's,.,X,g' lines1 # SunOS sed thinks we are escaping . as wildcard, not as separator mark '8.3' $SED -e 's.\..X.g' lines1 mark '8.4' ; $SED -e 's/[\/]/Q/' lines1 mark '8.5' ; $SED -e 's_\__X_' lines1 mark '8.6' ; $SED -e 's/./(&)/g' lines1 mark '8.7' ; $SED -e 's/./(\&)/g' lines1 mark '8.8' ; $SED -e 's/\(.\)\(.\)\(.\)/x\3x\2x\1/g' lines1 mark '8.9' ; $SED -e 's/_/u0\ u1\ u2/g' lines1 mark '8.10' $SED -e 's/./X/4' lines1 rm -f lines4 mark '8.11' ; $SED -e 's/1/X/w lines4' lines1 COMMENT='s wfile results' cat lines4 mark '8.12' ; $SED -e 's/[123]/X/g' lines1 mark '8.13' ; $SED -e 'y/0123456789/9876543210/' lines1 mark '8.14' ; $SED -e 'y10\123456789198765432\101' lines1 mark '8.15' ; $SED -e '1N;2y/\n/X/' lines1 mark '8.16' echo 'eeefff' | $SED -e ' p s/e/X/p :x s//Y/p # Establish limit counter in the hold space # GNU sed version 3.02 enters into an infinite loop here x /.\{10\}/ { s/.*/ERROR/ b } s/.*/&./ x /f/bx ' # POSIX does not say that this should work, # but it does for GNU, BSD, and SunOS mark '8.17' ; $SED -e 's/[/]/Q/' lines1 } test_error() { COMMENT='Error cases' mark '9.1' ; $SED -x 2>/dev/null ; echo $? mark '9.2' ; $SED -f 2>/dev/null ; echo $? mark '9.3' ; $SED -e 2>/dev/null ; echo $? mark '9.4' ; $SED -f /dev/xyzzyxyzy 2>/dev/null ; echo $? mark '9.5' ; $SED p /dev/xyzzyxyzy 2>/dev/null ; echo $? mark '9.6' ; $SED -f /bin/sh 2>/dev/null ; echo $? mark '9.7' ; $SED '{' 2>/dev/null ; echo $? mark '9.8' ; $SED '{' 2>/dev/null ; echo $? mark '9.9' ; $SED '/hello/' 2>/dev/null ; echo $? mark '9.10' ; $SED '1,/hello/' 2>/dev/null ; echo $? mark '9.11' ; $SED -e '-5p' 2>/dev/null ; echo $? mark '9.12' ; $SED '/jj' 2>/dev/null ; echo $? mark '9.13' ; $SED 'a hello' 2>/dev/null ; echo $? mark '9.14' ; $SED 'a \ hello' 2>/dev/null ; echo $? mark '9.15' ; $SED 'b foo' 2>/dev/null ; echo $? mark '9.16' ; $SED 'd hello' 2>/dev/null ; echo $? mark '9.17' ; $SED 's/aa' 2>/dev/null ; echo $? mark '9.18' ; $SED 's/aa/' 2>/dev/null ; echo $? mark '9.19' ; $SED 's/a/b' 2>/dev/null ; echo $? mark '9.20' ; $SED 's/a/b/c/d' 2>/dev/null ; echo $? mark '9.21' ; $SED 's/a/b/ 1 2' 2>/dev/null ; echo $? mark '9.22' ; $SED 's/a/b/ 1 g' 2>/dev/null ; echo $? mark '9.23' ; $SED 's/a/b/w' 2>/dev/null ; echo $? mark '9.24' ; $SED 'y/aa' 2>/dev/null ; echo $? mark '9.25' ; $SED 'y/aa/b/' 2>/dev/null ; echo $? mark '9.26' ; $SED 'y/aa/' 2>/dev/null ; echo $? mark '9.27' ; $SED 'y/a/b' 2>/dev/null ; echo $? mark '9.28' ; $SED 'y/a/b/c/d' 2>/dev/null ; echo $? mark '9.29' ; $SED '!' 2>/dev/null ; echo $? mark '9.30' ; $SED supercalifrangolisticexprialidociussupercalifrangolisticexcius 2>/dev/null ; echo $? mark '9.31' ; $SED '' /dev/null 2>/dev/null ; echo $? } main