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 167549 2007-03-14 11:03:00Z dds $
34#
35
36# sed Regression Tests
37#
38# The following files are created:
39# lines[1-4], script1, script2
40# Two directories *.out contain the test results
41
42main()
43{
44 #BASE=/usr/bin/sed
45 BASE=/usr/ports/textproc/gsed/work/sed-4.1.5/sed/sed
46 BASELOG=sed.out
47 #TEST=`cd ..; make whereobj`/sed
48 TEST=/home/dds/src/fbsd-head/sed/sed
49 TESTLOG=nsed.out
50 DICT=/usr/share/dict/words
51
52 #test_error | more
53
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
56
57 exec 4>&1 5>&2
58
59 # Set these flags to get messages about known problems
60 BSD=0
61 GNU=1
62 SUN=0
63 tests $BASE $BASELOG
64
65 BSD=1
66 GNU=0
67 SUN=0
68 tests $TEST $TESTLOG
69 exec 1>&4 2>&5
70 diff -c $BASELOG $TESTLOG | more
71}
72
73tests()
74{
75 SED=$1
76 DIR=$2
77 rm -rf $DIR
78 mkdir $DIR
79 MARK=100
80
81 test_args
82 test_addr
83 echo Testing commands
84 test_group
85 test_acid
86 test_branch
87 test_pattern
88 test_print
89 test_subst
90}
91
92mark()
93{
94 MARK=`expr $MARK + 1`
95 exec 1>&4 2>&5
96 exec >"$DIR/${MARK}_$1"
97 echo "Test $1:$MARK"
98 # Uncomment this line to match tests with sed error messages
99 echo "Test $1:$MARK" >&5
100}
101
102test_args()
103{
104 mark '1.1'
105 echo Testing argument parsing
106 echo First type
107 $SED 's/^/e1_/p' lines1
108 mark '1.2' ; $SED -n 's/^/e1_/p' lines1
109 mark '1.3'
110 $SED 's/^/e1_/p' <lines1
111 mark '1.4' ; $SED -n 's/^/e1_/p' <lines1
112 echo Second type
113 mark '1.4.1'
114 $SED -e '' <lines1
115 echo 's/^/s1_/p' >script1
116 echo 's/^/s2_/p' >script2
117 mark '1.5'
118 $SED -f script1 lines1
119 mark '1.6'
120 $SED -f script1 <lines1
--- 6 unchanged lines hidden (view full) ---
127 mark '1.11' ; $SED -n -e 's/^/e1_/p' lines1
128 mark '1.12'
129 $SED -n -e 's/^/e1_/p' <lines1
130 mark '1.13'
131 $SED -e 's/^/e1_/p' -e 's/^/e2_/p' lines1
132 mark '1.14'
133 $SED -f script1 -f script2 lines1
134 mark '1.15'
135 if [ $SUN -eq 1 ] ; then
136 echo SunOS sed fails this following older POSIX draft
137 else
138 $SED -e 's/^/e1_/p' -f script1 lines1
139 fi
140 mark '1.16'
141 $SED -e 's/^/e1_/p' lines1 lines1
142 # POSIX D11.2:11251
143 mark '1.17' ; $SED p <lines1 lines1
144cat >script1 <<EOF
145#n
146# A comment
147
148p
149EOF
150 mark '1.18' ; $SED -f script1 <lines1 lines1
151}
152
153test_addr()
154{
155 echo Testing address ranges
156 mark '2.1' ; $SED -n -e '4p' lines1
157 mark '2.2' ; $SED -n -e '20p' lines1 lines2
158 mark '2.3' ; $SED -n -e '$p' lines1
159 mark '2.4' ; $SED -n -e '$p' lines1 lines2
160 mark '2.5' ; $SED -n -e '$a\
161hello' /dev/null
162 mark '2.6' ; $SED -n -e '$p' lines1 /dev/null lines2
163 # Should not print anything
--- 10 unchanged lines hidden (view full) ---
174 mark '2.17' ; $SED -n '/4/,/10/p' lines1 lines2
175 mark '2.18' ; $SED -n '/l2_3/,/l1_8/p' lines1 lines2
176 mark '2.19' ; $SED -n '12,3p' lines1 lines2
177 mark '2.20' ; $SED -n '/l1_7/,3p' lines1 lines2
178}
179
180test_group()
181{
182 echo Brace and other grouping
183 mark '3.1' ; $SED -e '
1844,12 {
185 s/^/^/
186 s/$/$/
187 s/_/T/
188}' lines1
189 mark '3.2' ; $SED -e '
1904,12 {
--- 11 unchanged lines hidden (view full) ---
202 /8/ !s/_/T/
203 }
204}' lines1
205 mark '3.4' ; $SED -e '4,12!s/^/^/' lines1
206}
207
208test_acid()
209{
210 echo Testing a c d and i commands
211 mark '4.1' ; $SED -n -e '
212s/^/before_i/p
21320i\
214inserted
215s/^/after_i/p
216' lines1 lines2
217 mark '4.2' ; $SED -n -e '
2185,12s/^/5-12/
--- 27 unchanged lines hidden (view full) ---
2468,3c\
247hello
248' lines1
249 mark '4.8' ; $SED d <lines1
250}
251
252test_branch()
253{
254 echo Testing labels and branching
255 mark '5.1' ; $SED -n -e '
256b label4
257:label3
258s/^/label3_/p
259b end
260:label4
2612,12b label1
262b label2
--- 54 unchanged lines hidden (view full) ---
317:b
318}
319s/l/m/
320tb' lines1
321}
322
323test_pattern()
324{
325echo Pattern space commands
326# Check that the pattern space is deleted
327 mark '6.1' ; $SED -n -e '
328c\
329changed
330p
331' lines1
332 mark '6.2' ; $SED -n -e '
3334d
334p
335' lines1
336 mark '6.3'
337 if [ $GNU -eq 1 ] ; then
338 echo GNU sed cannot pass 6.3
339 else
340 $SED -e 'N;N;N;D' lines1
341 fi
342 mark '6.4' ; $SED -e '
3432h
3443H
3454g
3465G
3476x
3486p
3496x
3506p
351' lines1
352 mark '6.5' ; $SED -e '4n' lines1
353 mark '6.6' ; $SED -n -e '4n' lines1
354}
355
356test_print()
357{
358 echo Testing print and file routines
359 awk 'END {for (i = 1; i < 256; i++) printf("%c", i);print "\n"}' \
360 </dev/null >lines3
361 # GNU and SunOS sed behave differently here
362 mark '7.1'
363 $SED -n l lines3
364 mark '7.2' ; $SED -e '/l2_/=' lines1 lines2
365 rm -f lines4
366 mark '7.3' ; $SED -e '3,12w lines4' lines1
367 echo w results
368 cat lines4
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
372 mark '7.7'
373 sed '200q' $DICT | sed 's$.*$s/^/&/w tmpdir/&$' >script1
374 rm -rf tmpdir
375 mkdir tmpdir
376 $SED -f script1 lines1
377 cat tmpdir/*
378 rm -rf tmpdir
379 mark '7.8'
380 if [ $BSD -eq 1 ] ; then
381 echo BSD sed cannot pass 7.8
382 else
383 echo line1 > lines3
384 echo "" >> lines3
385 $SED -n -e '$p' lines3 /dev/null
386 fi
387
388}
389
390test_subst()
391{
392 echo Testing substitution commands
393 mark '8.1' ; $SED -e 's/./X/g' lines1
394 mark '8.2' ; $SED -e 's,.,X,g' lines1
395# SunOS sed thinks we are escaping . as wildcard, not as separator
396 mark '8.3'
397 if [ $SUN -eq 1 ] ; then
398 echo SUN sed fails test 8.3
399 else
400 $SED -e 's.\..X.g' lines1
401 fi
402 mark '8.4' ; $SED -e 's/[\/]/Q/' lines1
403 mark '8.5' ; $SED -e 's_\__X_' lines1
404 mark '8.6' ; $SED -e 's/./(&)/g' lines1
405 mark '8.7' ; $SED -e 's/./(\&)/g' lines1
406 mark '8.8' ; $SED -e 's/\(.\)\(.\)\(.\)/x\3x\2x\1/g' lines1
407 mark '8.9' ; $SED -e 's/_/u0\
408u1\
409u2/g' lines1
410 mark '8.10'
411 $SED -e 's/./X/4' lines1
412 rm -f lines4
413 mark '8.11' ; $SED -e 's/1/X/w lines4' lines1
414 echo s wfile results
415 cat lines4
416 mark '8.12' ; $SED -e 's/[123]/X/g' lines1
417 mark '8.13' ; $SED -e 'y/0123456789/9876543210/' lines1
418 mark '8.14' ;
419 $SED -e 'y10\123456789198765432\101' lines1
420 mark '8.15' ; $SED -e '1N;2y/\n/X/' lines1
421 mark '8.16'
422 echo 'eeefff' | $SED -e '
--- 61 unchanged lines hidden ---
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 167549 2007-03-14 11:03:00Z dds $
34#
35
36# sed Regression Tests
37#
38# The following files are created:
39# lines[1-4], script1, script2
40# Two directories *.out contain the test results
41
42main()
43{
44 #BASE=/usr/bin/sed
45 BASE=/usr/ports/textproc/gsed/work/sed-4.1.5/sed/sed
46 BASELOG=sed.out
47 #TEST=`cd ..; make whereobj`/sed
48 TEST=/home/dds/src/fbsd-head/sed/sed
49 TESTLOG=nsed.out
50 DICT=/usr/share/dict/words
51
52 #test_error | more
53
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
56
57 exec 4>&1 5>&2
58
59 # Set these flags to get messages about known problems
60 BSD=0
61 GNU=1
62 SUN=0
63 tests $BASE $BASELOG
64
65 BSD=1
66 GNU=0
67 SUN=0
68 tests $TEST $TESTLOG
69 exec 1>&4 2>&5
70 diff -c $BASELOG $TESTLOG | more
71}
72
73tests()
74{
75 SED=$1
76 DIR=$2
77 rm -rf $DIR
78 mkdir $DIR
79 MARK=100
80
81 test_args
82 test_addr
83 echo Testing commands
84 test_group
85 test_acid
86 test_branch
87 test_pattern
88 test_print
89 test_subst
90}
91
92mark()
93{
94 MARK=`expr $MARK + 1`
95 exec 1>&4 2>&5
96 exec >"$DIR/${MARK}_$1"
97 echo "Test $1:$MARK"
98 # Uncomment this line to match tests with sed error messages
99 echo "Test $1:$MARK" >&5
100}
101
102test_args()
103{
104 mark '1.1'
105 echo Testing argument parsing
106 echo First type
107 $SED 's/^/e1_/p' lines1
108 mark '1.2' ; $SED -n 's/^/e1_/p' lines1
109 mark '1.3'
110 $SED 's/^/e1_/p' <lines1
111 mark '1.4' ; $SED -n 's/^/e1_/p' <lines1
112 echo Second type
113 mark '1.4.1'
114 $SED -e '' <lines1
115 echo 's/^/s1_/p' >script1
116 echo 's/^/s2_/p' >script2
117 mark '1.5'
118 $SED -f script1 lines1
119 mark '1.6'
120 $SED -f script1 <lines1
--- 6 unchanged lines hidden (view full) ---
127 mark '1.11' ; $SED -n -e 's/^/e1_/p' lines1
128 mark '1.12'
129 $SED -n -e 's/^/e1_/p' <lines1
130 mark '1.13'
131 $SED -e 's/^/e1_/p' -e 's/^/e2_/p' lines1
132 mark '1.14'
133 $SED -f script1 -f script2 lines1
134 mark '1.15'
135 if [ $SUN -eq 1 ] ; then
136 echo SunOS sed fails this following older POSIX draft
137 else
138 $SED -e 's/^/e1_/p' -f script1 lines1
139 fi
140 mark '1.16'
141 $SED -e 's/^/e1_/p' lines1 lines1
142 # POSIX D11.2:11251
143 mark '1.17' ; $SED p <lines1 lines1
144cat >script1 <<EOF
145#n
146# A comment
147
148p
149EOF
150 mark '1.18' ; $SED -f script1 <lines1 lines1
151}
152
153test_addr()
154{
155 echo Testing address ranges
156 mark '2.1' ; $SED -n -e '4p' lines1
157 mark '2.2' ; $SED -n -e '20p' lines1 lines2
158 mark '2.3' ; $SED -n -e '$p' lines1
159 mark '2.4' ; $SED -n -e '$p' lines1 lines2
160 mark '2.5' ; $SED -n -e '$a\
161hello' /dev/null
162 mark '2.6' ; $SED -n -e '$p' lines1 /dev/null lines2
163 # Should not print anything
--- 10 unchanged lines hidden (view full) ---
174 mark '2.17' ; $SED -n '/4/,/10/p' lines1 lines2
175 mark '2.18' ; $SED -n '/l2_3/,/l1_8/p' lines1 lines2
176 mark '2.19' ; $SED -n '12,3p' lines1 lines2
177 mark '2.20' ; $SED -n '/l1_7/,3p' lines1 lines2
178}
179
180test_group()
181{
182 echo Brace and other grouping
183 mark '3.1' ; $SED -e '
1844,12 {
185 s/^/^/
186 s/$/$/
187 s/_/T/
188}' lines1
189 mark '3.2' ; $SED -e '
1904,12 {
--- 11 unchanged lines hidden (view full) ---
202 /8/ !s/_/T/
203 }
204}' lines1
205 mark '3.4' ; $SED -e '4,12!s/^/^/' lines1
206}
207
208test_acid()
209{
210 echo Testing a c d and i commands
211 mark '4.1' ; $SED -n -e '
212s/^/before_i/p
21320i\
214inserted
215s/^/after_i/p
216' lines1 lines2
217 mark '4.2' ; $SED -n -e '
2185,12s/^/5-12/
--- 27 unchanged lines hidden (view full) ---
2468,3c\
247hello
248' lines1
249 mark '4.8' ; $SED d <lines1
250}
251
252test_branch()
253{
254 echo Testing labels and branching
255 mark '5.1' ; $SED -n -e '
256b label4
257:label3
258s/^/label3_/p
259b end
260:label4
2612,12b label1
262b label2
--- 54 unchanged lines hidden (view full) ---
317:b
318}
319s/l/m/
320tb' lines1
321}
322
323test_pattern()
324{
325echo Pattern space commands
326# Check that the pattern space is deleted
327 mark '6.1' ; $SED -n -e '
328c\
329changed
330p
331' lines1
332 mark '6.2' ; $SED -n -e '
3334d
334p
335' lines1
336 mark '6.3'
337 if [ $GNU -eq 1 ] ; then
338 echo GNU sed cannot pass 6.3
339 else
340 $SED -e 'N;N;N;D' lines1
341 fi
342 mark '6.4' ; $SED -e '
3432h
3443H
3454g
3465G
3476x
3486p
3496x
3506p
351' lines1
352 mark '6.5' ; $SED -e '4n' lines1
353 mark '6.6' ; $SED -n -e '4n' lines1
354}
355
356test_print()
357{
358 echo Testing print and file routines
359 awk 'END {for (i = 1; i < 256; i++) printf("%c", i);print "\n"}' \
360 </dev/null >lines3
361 # GNU and SunOS sed behave differently here
362 mark '7.1'
363 $SED -n l lines3
364 mark '7.2' ; $SED -e '/l2_/=' lines1 lines2
365 rm -f lines4
366 mark '7.3' ; $SED -e '3,12w lines4' lines1
367 echo w results
368 cat lines4
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
372 mark '7.7'
373 sed '200q' $DICT | sed 's$.*$s/^/&/w tmpdir/&$' >script1
374 rm -rf tmpdir
375 mkdir tmpdir
376 $SED -f script1 lines1
377 cat tmpdir/*
378 rm -rf tmpdir
379 mark '7.8'
380 if [ $BSD -eq 1 ] ; then
381 echo BSD sed cannot pass 7.8
382 else
383 echo line1 > lines3
384 echo "" >> lines3
385 $SED -n -e '$p' lines3 /dev/null
386 fi
387
388}
389
390test_subst()
391{
392 echo Testing substitution commands
393 mark '8.1' ; $SED -e 's/./X/g' lines1
394 mark '8.2' ; $SED -e 's,.,X,g' lines1
395# SunOS sed thinks we are escaping . as wildcard, not as separator
396 mark '8.3'
397 if [ $SUN -eq 1 ] ; then
398 echo SUN sed fails test 8.3
399 else
400 $SED -e 's.\..X.g' lines1
401 fi
402 mark '8.4' ; $SED -e 's/[\/]/Q/' lines1
403 mark '8.5' ; $SED -e 's_\__X_' lines1
404 mark '8.6' ; $SED -e 's/./(&)/g' lines1
405 mark '8.7' ; $SED -e 's/./(\&)/g' lines1
406 mark '8.8' ; $SED -e 's/\(.\)\(.\)\(.\)/x\3x\2x\1/g' lines1
407 mark '8.9' ; $SED -e 's/_/u0\
408u1\
409u2/g' lines1
410 mark '8.10'
411 $SED -e 's/./X/4' lines1
412 rm -f lines4
413 mark '8.11' ; $SED -e 's/1/X/w lines4' lines1
414 echo s wfile results
415 cat lines4
416 mark '8.12' ; $SED -e 's/[123]/X/g' lines1
417 mark '8.13' ; $SED -e 'y/0123456789/9876543210/' lines1
418 mark '8.14' ;
419 $SED -e 'y10\123456789198765432\101' lines1
420 mark '8.15' ; $SED -e '1N;2y/\n/X/' lines1
421 mark '8.16'
422 echo 'eeefff' | $SED -e '
--- 61 unchanged lines hidden ---