1#!/bin/sh - 2# 3# Copyright (c) 1992 Diomidis Spinellis. 4# Copyright (c) 1992, 1993 5# The Regents of the University of California. All rights reserved. 6# 7# Redistribution and use in source and binary forms, with or without 8# modification, are permitted provided that the following conditions --- 16 unchanged lines hidden (view full) --- 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 29# SUCH DAMAGE. 30# 31# @(#)sed.test 8.1 (Berkeley) 6/6/93 32# |
33# $FreeBSD: head/tools/regression/usr.bin/sed/multitest.t 167552 2007-03-14 13:05:45Z dds $ |
34# 35 36# sed Regression Tests 37# |
38# The directory regress.test.out contains the expected test results 39# 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. |
45 46main() 47{ |
48 REGRESS=regress.multitest.out |
49 DICT=/usr/share/dict/words 50 51 #test_error | more 52 53 awk 'END { for (i = 1; i < 15; i++) print "l1_" i}' </dev/null >lines1 54 awk 'END { for (i = 1; i < 10; i++) print "l2_" i}' </dev/null >lines2 55 |
56 echo "1..90" |
57 |
58 exec 4>&1 5>&2 59 tests |
60 exec 1>&4 2>&5 |
61 62 # Remove temporary files 63 rm -f current.out lines[1-4] script[1-2] |
64} 65 66tests() 67{ |
68 SED=sed 69 MARK=0 |
70 71 test_args 72 test_addr |
73 test_group 74 test_acid 75 test_branch 76 test_pattern 77 test_print 78 test_subst |
79 # Handle the result of the last test 80 result |
81} 82 |
83# Display a test's result 84result() 85{ 86 if [ "$TODO" = '1' ] ; then 87 TODO='TODO ' 88 else 89 TODO='' 90 fi 91 if diff -c $REGRESS/${MARK}_${TESTNAME} current.out ; then 92 echo "ok $MARK $TESTNAME # $TODO$COMMENT" 93 else 94 echo "not ok $MARK $TESTNAME # $TODO$COMMENT" 95 fi 1>&4 2>&5 96} 97 98# Mark the beginning of each test |
99mark() 100{ |
101 [ $MARK -gt 0 ] && result |
102 MARK=`expr $MARK + 1` |
103 TESTNAME=$1 |
104 exec 1>&4 2>&5 |
105 exec >"current.out" |
106} 107 108test_args() 109{ |
110 COMMENT='Argument parsing - first type' |
111 mark '1.1' |
112 $SED 's/^/e1_/p' lines1 113 mark '1.2' ; $SED -n 's/^/e1_/p' lines1 114 mark '1.3' 115 $SED 's/^/e1_/p' <lines1 116 mark '1.4' ; $SED -n 's/^/e1_/p' <lines1 |
117 COMMENT='Argument parsing - second type' |
118 mark '1.4.1' 119 $SED -e '' <lines1 120 echo 's/^/s1_/p' >script1 121 echo 's/^/s2_/p' >script2 122 mark '1.5' 123 $SED -f script1 lines1 124 mark '1.6' 125 $SED -f script1 <lines1 --- 6 unchanged lines hidden (view full) --- 132 mark '1.11' ; $SED -n -e 's/^/e1_/p' lines1 133 mark '1.12' 134 $SED -n -e 's/^/e1_/p' <lines1 135 mark '1.13' 136 $SED -e 's/^/e1_/p' -e 's/^/e2_/p' lines1 137 mark '1.14' 138 $SED -f script1 -f script2 lines1 139 mark '1.15' |
140 $SED -e 's/^/e1_/p' -f script1 lines1 |
141 mark '1.16' 142 $SED -e 's/^/e1_/p' lines1 lines1 143 # POSIX D11.2:11251 144 mark '1.17' ; $SED p <lines1 lines1 145cat >script1 <<EOF 146#n 147# A comment 148 149p 150EOF 151 mark '1.18' ; $SED -f script1 <lines1 lines1 152} 153 154test_addr() 155{ |
156 COMMENT='Address ranges' |
157 mark '2.1' ; $SED -n -e '4p' lines1 158 mark '2.2' ; $SED -n -e '20p' lines1 lines2 159 mark '2.3' ; $SED -n -e '$p' lines1 160 mark '2.4' ; $SED -n -e '$p' lines1 lines2 161 mark '2.5' ; $SED -n -e '$a\ 162hello' /dev/null 163 mark '2.6' ; $SED -n -e '$p' lines1 /dev/null lines2 164 # Should not print anything --- 10 unchanged lines hidden (view full) --- 175 mark '2.17' ; $SED -n '/4/,/10/p' lines1 lines2 176 mark '2.18' ; $SED -n '/l2_3/,/l1_8/p' lines1 lines2 177 mark '2.19' ; $SED -n '12,3p' lines1 lines2 178 mark '2.20' ; $SED -n '/l1_7/,3p' lines1 lines2 179} 180 181test_group() 182{ |
183 COMMENT='Brace and other grouping' |
184 mark '3.1' ; $SED -e ' 1854,12 { 186 s/^/^/ 187 s/$/$/ 188 s/_/T/ 189}' lines1 190 mark '3.2' ; $SED -e ' 1914,12 { --- 11 unchanged lines hidden (view full) --- 203 /8/ !s/_/T/ 204 } 205}' lines1 206 mark '3.4' ; $SED -e '4,12!s/^/^/' lines1 207} 208 209test_acid() 210{ |
211 COMMENT='Commands a c d and i' |
212 mark '4.1' ; $SED -n -e ' 213s/^/before_i/p 21420i\ 215inserted 216s/^/after_i/p 217' lines1 lines2 218 mark '4.2' ; $SED -n -e ' 2195,12s/^/5-12/ --- 27 unchanged lines hidden (view full) --- 2478,3c\ 248hello 249' lines1 250 mark '4.8' ; $SED d <lines1 251} 252 253test_branch() 254{ |
255 COMMENT='Labels and branching' |
256 mark '5.1' ; $SED -n -e ' 257b label4 258:label3 259s/^/label3_/p 260b end 261:label4 2622,12b label1 263b label2 --- 54 unchanged lines hidden (view full) --- 318:b 319} 320s/l/m/ 321tb' lines1 322} 323 324test_pattern() 325{ |
326COMMENT='Pattern space commands' |
327# Check that the pattern space is deleted 328 mark '6.1' ; $SED -n -e ' 329c\ 330changed 331p 332' lines1 333 mark '6.2' ; $SED -n -e ' 3344d 335p 336' lines1 337 mark '6.3' |
338 $SED -e 'N;N;N;D' lines1 |
339 mark '6.4' ; $SED -e ' 3402h 3413H 3424g 3435G 3446x 3456p 3466x 3476p 348' lines1 349 mark '6.5' ; $SED -e '4n' lines1 350 mark '6.6' ; $SED -n -e '4n' lines1 351} 352 353test_print() 354{ |
355 COMMENT='Print and file routines' |
356 awk 'END {for (i = 1; i < 256; i++) printf("%c", i);print "\n"}' \ 357 </dev/null >lines3 358 # GNU and SunOS sed behave differently here 359 mark '7.1' 360 $SED -n l lines3 361 mark '7.2' ; $SED -e '/l2_/=' lines1 lines2 362 rm -f lines4 363 mark '7.3' ; $SED -e '3,12w lines4' lines1 |
364 COMMENT='w results' |
365 cat lines4 366 mark '7.4' ; $SED -e '4r lines2' lines1 367 mark '7.5' ; $SED -e '5r /dev/dds' lines1 368 mark '7.6' ; $SED -e '6r /dev/null' lines1 369 mark '7.7' 370 sed '200q' $DICT | sed 's$.*$s/^/&/w tmpdir/&$' >script1 371 rm -rf tmpdir 372 mkdir tmpdir 373 $SED -f script1 lines1 374 cat tmpdir/* 375 rm -rf tmpdir 376 mark '7.8' |
377 echo line1 > lines3 378 echo "" >> lines3 379 TODO=1 380 $SED -n -e '$p' lines3 /dev/null |
381 382} 383 384test_subst() 385{ |
386 COMMENT='Substitution commands' |
387 mark '8.1' ; $SED -e 's/./X/g' lines1 388 mark '8.2' ; $SED -e 's,.,X,g' lines1 389# SunOS sed thinks we are escaping . as wildcard, not as separator 390 mark '8.3' |
391 $SED -e 's.\..X.g' lines1 |
392 mark '8.4' ; $SED -e 's/[\/]/Q/' lines1 393 mark '8.5' ; $SED -e 's_\__X_' lines1 394 mark '8.6' ; $SED -e 's/./(&)/g' lines1 395 mark '8.7' ; $SED -e 's/./(\&)/g' lines1 396 mark '8.8' ; $SED -e 's/\(.\)\(.\)\(.\)/x\3x\2x\1/g' lines1 397 mark '8.9' ; $SED -e 's/_/u0\ 398u1\ 399u2/g' lines1 400 mark '8.10' 401 $SED -e 's/./X/4' lines1 402 rm -f lines4 403 mark '8.11' ; $SED -e 's/1/X/w lines4' lines1 |
404 COMMENT='s wfile results' |
405 cat lines4 406 mark '8.12' ; $SED -e 's/[123]/X/g' lines1 407 mark '8.13' ; $SED -e 'y/0123456789/9876543210/' lines1 408 mark '8.14' ; 409 $SED -e 'y10\123456789198765432\101' lines1 410 mark '8.15' ; $SED -e '1N;2y/\n/X/' lines1 411 mark '8.16' 412 echo 'eeefff' | $SED -e ' --- 61 unchanged lines hidden --- |