Deleted Added
full compact
multi_test.sh (197357) multi_test.sh (197361)
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
9# are met:
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.
18#
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
29# SUCH DAMAGE.
30#
31# @(#)sed.test 8.1 (Berkeley) 6/6/93
32#
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
9# are met:
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.
18#
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
29# SUCH DAMAGE.
30#
31# @(#)sed.test 8.1 (Berkeley) 6/6/93
32#
33# $FreeBSD: head/tools/regression/usr.bin/sed/multitest.t 197357 2009-09-20 14:20:00Z dds $
33# $FreeBSD: head/tools/regression/usr.bin/sed/multitest.t 197361 2009-09-20 15:17:40Z 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 mostly created during the development
41# of the BSD sed. Each test should have a unique mark name, which is
42# used for naming the corresponding file in regress.multitest.out.
43
44main()
45{
46 cd `dirname $0`
47 REGRESS=regress.multitest.out
48 DICT=/usr/share/dict/words
49
50 awk 'END { for (i = 1; i < 15; i++) print "l1_" i}' </dev/null >lines1
51 awk 'END { for (i = 1; i < 10; i++) print "l2_" i}' </dev/null >lines2
52
53 echo "1..121"
54
55 exec 4>&1 5>&2
56 tests
57 exec 1>&4 2>&5
58
59 # Remove temporary files
60 rm -f current.out lines[1-4] script[1-2]
61}
62
63tests()
64{
65 SED=sed
66 MARK=0
67
68 test_args
69 test_addr
70 test_group
71 test_acid
72 test_branch
73 test_pattern
74 test_print
75 test_subst
76 test_error
77 # Handle the result of the last test
78 result
79}
80
81# Display a test's result
82result()
83{
84 if [ "$TODO" = '1' ] ; then
85 TODO='TODO '
86 else
87 TODO=''
88 fi
89 if ! [ -r $REGRESS/${TESTNAME} ] ; then
90 echo "Seeding $REGRESS/${TESTNAME} with current result" 1>&2
91 cp current.out $REGRESS/${TESTNAME}
92 fi
93 if diff -c $REGRESS/${TESTNAME} current.out ; then
94 echo "ok $MARK $TESTNAME # $TODO$COMMENT"
95 else
96 echo "not ok $MARK $TESTNAME # $TODO$COMMENT"
97 fi 1>&4 2>&5
98}
99
100# Mark the beginning of each test
101mark()
102{
103 [ $MARK -gt 0 ] && result
104 MARK=`expr $MARK + 1`
105 TESTNAME=$1
106 exec 1>&4 2>&5
107 exec >"current.out"
108}
109
110test_args()
111{
112 COMMENT='Argument parsing - first type'
113 mark '1.1'
114 $SED 's/^/e1_/p' lines1
115 mark '1.2' ; $SED -n 's/^/e1_/p' lines1
116 mark '1.3'
117 $SED 's/^/e1_/p' <lines1
118 mark '1.4' ; $SED -n 's/^/e1_/p' <lines1
119 COMMENT='Argument parsing - second type'
120 mark '1.4.1'
121 $SED -e '' <lines1
122 echo 's/^/s1_/p' >script1
123 echo 's/^/s2_/p' >script2
124 mark '1.5'
125 $SED -f script1 lines1
126 mark '1.6'
127 $SED -f script1 <lines1
128 mark '1.7'
129 $SED -e 's/^/e1_/p' lines1
130 mark '1.8'
131 $SED -e 's/^/e1_/p' <lines1
132 mark '1.9' ; $SED -n -f script1 lines1
133 mark '1.10' ; $SED -n -f script1 <lines1
134 mark '1.11' ; $SED -n -e 's/^/e1_/p' lines1
135 mark '1.12'
136 $SED -n -e 's/^/e1_/p' <lines1
137 mark '1.13'
138 $SED -e 's/^/e1_/p' -e 's/^/e2_/p' lines1
139 mark '1.14'
140 $SED -f script1 -f script2 lines1
141 mark '1.15'
142 $SED -e 's/^/e1_/p' -f script1 lines1
143 mark '1.16'
144 $SED -e 's/^/e1_/p' lines1 lines1
145 # POSIX D11.2:11251
146 mark '1.17' ; $SED p <lines1 lines1
147cat >script1 <<EOF
148#n
149# A comment
150
151p
152EOF
153 mark '1.18' ; $SED -f script1 <lines1 lines1
154}
155
156test_addr()
157{
158 COMMENT='Address ranges'
159 mark '2.1' ; $SED -n -e '4p' lines1
160 mark '2.2' ; $SED -n -e '20p' lines1 lines2
161 mark '2.3' ; $SED -n -e '$p' lines1
162 mark '2.4' ; $SED -n -e '$p' lines1 lines2
163 mark '2.5' ; $SED -n -e '$a\
164hello' /dev/null
165 mark '2.6' ; $SED -n -e '$p' lines1 /dev/null lines2
166 # Should not print anything
167 mark '2.7' ; $SED -n -e '20p' lines1
168 mark '2.8' ; $SED -n -e '/NOTFOUND/p' lines1
169 mark '2.9' ; $SED -n '/l1_7/p' lines1
170 mark '2.10' ; $SED -n ' /l1_7/ p' lines1
171 mark '2.11' ; $SED -n '\_l1\_7_p' lines1
172 mark '2.12' ; $SED -n '1,4p' lines1
173 mark '2.13' ; $SED -n '1,$p' lines1 lines2
174 mark '2.14' ; $SED -n '1,/l2_9/p' lines1 lines2
175 mark '2.15' ; $SED -n '/4/,$p' lines1 lines2
176 mark '2.16' ; $SED -n '/4/,20p' lines1 lines2
177 mark '2.17' ; $SED -n '/4/,/10/p' lines1 lines2
178 mark '2.18' ; $SED -n '/l2_3/,/l1_8/p' lines1 lines2
179 mark '2.19' ; $SED -n '12,3p' lines1 lines2
180 mark '2.20' ; $SED -n '/l1_7/,3p' lines1 lines2
181 mark '2.21' ; $SED -n '13,+4p' lines1 lines2
182 mark '2.22' ; $SED -n '/l1_6/,+2p' lines1 lines2
183}
184
185test_group()
186{
187 COMMENT='Brace and other grouping'
188 mark '3.1' ; $SED -e '
1894,12 {
190 s/^/^/
191 s/$/$/
192 s/_/T/
193}' lines1
194 mark '3.2' ; $SED -e '
1954,12 {
196 s/^/^/
197 /6/,/10/ {
198 s/$/$/
199 /8/ s/_/T/
200 }
201}' lines1
202 mark '3.3' ; $SED -e '
2034,12 !{
204 s/^/^/
205 /6/,/10/ !{
206 s/$/$/
207 /8/ !s/_/T/
208 }
209}' lines1
210 mark '3.4' ; $SED -e '4,12!s/^/^/' lines1
211}
212
213test_acid()
214{
215 COMMENT='Commands a c d and i'
216 mark '4.1' ; $SED -n -e '
217s/^/before_i/p
21820i\
219inserted
220s/^/after_i/p
221' lines1 lines2
222 mark '4.2' ; $SED -n -e '
2235,12s/^/5-12/
224s/^/before_a/p
225/5-12/a\
226appended
227s/^/after_a/p
228' lines1 lines2
229 mark '4.3'
230 $SED -n -e '
231s/^/^/p
232/l1_/a\
233appended
2348,10N
235s/$/$/p
236' lines1 lines2
237 mark '4.4' ; $SED -n -e '
238c\
239hello
240' lines1
241 mark '4.5' ; $SED -n -e '
2428c\
243hello
244' lines1
245 mark '4.6' ; $SED -n -e '
2463,14c\
247hello
248' lines1
249# SunOS and GNU sed behave differently. We follow POSIX
250 mark '4.7' ; $SED -n -e '
2518,3c\
252hello
253' lines1
254 mark '4.8' ; $SED d <lines1
255}
256
257test_branch()
258{
259 COMMENT='Labels and branching'
260 mark '5.1' ; $SED -n -e '
261b label4
262:label3
263s/^/label3_/p
264b end
265:label4
2662,12b label1
267b label2
268:label1
269s/^/label1_/p
270b
271:label2
272s/^/label2_/p
273b label3
274:end
275' lines1
276 mark '5.2'
277 $SED -n -e '
278s/l1_/l2_/
279t ok
280b
281:ok
282s/^/tested /p
283' lines1 lines2
284# SunOS and GNU sed behave as follows: lines 9-$ aren't printed at all
285 mark '5.3' ; $SED -n -e '
2865,8b inside
2871,5 {
288 s/^/^/p
289 :inside
290 s/$/$/p
291}
292' lines1
293# Check that t clears the substitution done flag
294 mark '5.4' ; $SED -n -e '
2951,8s/^/^/
296t l1
297:l1
298t l2
299s/$/$/p
300b
301:l2
302s/^/ERROR/
303' lines1
304# Check that reading a line clears the substitution done flag
305 mark '5.5'
306 $SED -n -e '
307t l2
3081,8s/^/^/p
3092,7N
310b
311:l2
312s/^/ERROR/p
313' lines1
314 mark '5.6' ; $SED 5q lines1
315 mark '5.7' ; $SED -e '
3165i\
317hello
3185q' lines1
319# Branch across block boundary
320 mark '5.8' ; $SED -e '
321{
322:b
323}
324s/l/m/
325tb' lines1
326}
327
328test_pattern()
329{
330COMMENT='Pattern space commands'
331# Check that the pattern space is deleted
332 mark '6.1' ; $SED -n -e '
333c\
334changed
335p
336' lines1
337 mark '6.2' ; $SED -n -e '
3384d
339p
340' lines1
341 mark '6.3'
342 $SED -e 'N;N;N;D' lines1
343 mark '6.4' ; $SED -e '
3442h
3453H
3464g
3475G
3486x
3496p
3506x
3516p
352' lines1
353 mark '6.5' ; $SED -e '4n' lines1
354 mark '6.6' ; $SED -n -e '4n' lines1
355}
356
357test_print()
358{
359 COMMENT='Print and file routines'
360 awk 'END {for (i = 1; i < 256; i++) printf("%c", i);print "\n"}' \
361 </dev/null >lines3
362 # GNU and SunOS sed behave differently here
363 mark '7.1'
364 $SED -n l lines3
365 mark '7.2' ; $SED -e '/l2_/=' lines1 lines2
366 rm -f lines4
367 mark '7.3' ; $SED -e '3,12w lines4' lines1
368 COMMENT='w results'
369 cat lines4
370 mark '7.4' ; $SED -e '4r lines2' lines1
371 mark '7.5' ; $SED -e '5r /dev/dds' lines1
372 mark '7.6' ; $SED -e '6r /dev/null' lines1
373 mark '7.7'
374 sed '200q' $DICT | sed 's$.*$s/^/&/w tmpdir/&$' >script1
375 rm -rf tmpdir
376 mkdir tmpdir
377 $SED -f script1 lines1
378 cat tmpdir/*
379 rm -rf tmpdir
380 mark '7.8'
381 echo line1 > lines3
382 echo "" >> lines3
383 TODO=1
384 $SED -n -e '$p' lines3 /dev/null
385
386}
387
388test_subst()
389{
390 COMMENT='Substitution commands'
391 mark '8.1' ; $SED -e 's/./X/g' lines1
392 mark '8.2' ; $SED -e 's,.,X,g' lines1
393# SunOS sed thinks we are escaping . as wildcard, not as separator
394 mark '8.3'
395 $SED -e 's.\..X.g' lines1
396 mark '8.4' ; $SED -e 's/[\/]/Q/' lines1
397 mark '8.5' ; $SED -e 's_\__X_' lines1
398 mark '8.6' ; $SED -e 's/./(&)/g' lines1
399 mark '8.7' ; $SED -e 's/./(\&)/g' lines1
400 mark '8.8' ; $SED -e 's/\(.\)\(.\)\(.\)/x\3x\2x\1/g' lines1
401 mark '8.9' ; $SED -e 's/_/u0\
402u1\
403u2/g' lines1
404 mark '8.10'
405 $SED -e 's/./X/4' lines1
406 rm -f lines4
407 mark '8.11' ; $SED -e 's/1/X/w lines4' lines1
408 COMMENT='s wfile results'
409 cat lines4
410 mark '8.12' ; $SED -e 's/[123]/X/g' lines1
411 mark '8.13' ; $SED -e 'y/0123456789/9876543210/' lines1
412 mark '8.14' ;
413 $SED -e 'y10\123456789198765432\101' lines1
414 mark '8.15' ; $SED -e '1N;2y/\n/X/' lines1
415 mark '8.16'
416 echo 'eeefff' | $SED -e '
417 p
418 s/e/X/p
419 :x
420 s//Y/p
421 # Establish limit counter in the hold space
422 # GNU sed version 3.02 enters into an infinite loop here
423 x
424 /.\{10\}/ {
425 s/.*/ERROR/
426 b
427 }
428 s/.*/&./
429 x
430 /f/bx
431 '
432 # POSIX does not say that this should work,
433 # but it does for GNU, BSD, and SunOS
434 mark '8.17' ; $SED -e 's/[/]/Q/' lines1
435
436 COMMENT='[ as an s delimiter and its escapes'
437 mark '8.18' ; $SED -e 's[_[X[' lines1
438 # This is a matter of interpretation
439 # POSIX 1003.1, 2004 says "Within the BRE and the replacement,
440 # the BRE delimiter itself can be used as a *literal* character
441 # if it is preceded by a backslash"
442 # SunOS 5.1 /usr/bin/sed and Mac OS X follow the literal POSIX
443 # interpretation.
444 # GNU sed version 4.1.5 treats \[ as the beginning of a character
445 # set specification (both with --posix and without).
446 mark '8.19' ; sed 's/l/[/' lines1 | $SED -e 's[\[.[X['
447 mark '8.20' ; sed 's/l/[/' lines1 | $SED -e 's[\[.[X\[['
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 mostly created during the development
41# of the BSD sed. Each test should have a unique mark name, which is
42# used for naming the corresponding file in regress.multitest.out.
43
44main()
45{
46 cd `dirname $0`
47 REGRESS=regress.multitest.out
48 DICT=/usr/share/dict/words
49
50 awk 'END { for (i = 1; i < 15; i++) print "l1_" i}' </dev/null >lines1
51 awk 'END { for (i = 1; i < 10; i++) print "l2_" i}' </dev/null >lines2
52
53 echo "1..121"
54
55 exec 4>&1 5>&2
56 tests
57 exec 1>&4 2>&5
58
59 # Remove temporary files
60 rm -f current.out lines[1-4] script[1-2]
61}
62
63tests()
64{
65 SED=sed
66 MARK=0
67
68 test_args
69 test_addr
70 test_group
71 test_acid
72 test_branch
73 test_pattern
74 test_print
75 test_subst
76 test_error
77 # Handle the result of the last test
78 result
79}
80
81# Display a test's result
82result()
83{
84 if [ "$TODO" = '1' ] ; then
85 TODO='TODO '
86 else
87 TODO=''
88 fi
89 if ! [ -r $REGRESS/${TESTNAME} ] ; then
90 echo "Seeding $REGRESS/${TESTNAME} with current result" 1>&2
91 cp current.out $REGRESS/${TESTNAME}
92 fi
93 if diff -c $REGRESS/${TESTNAME} current.out ; then
94 echo "ok $MARK $TESTNAME # $TODO$COMMENT"
95 else
96 echo "not ok $MARK $TESTNAME # $TODO$COMMENT"
97 fi 1>&4 2>&5
98}
99
100# Mark the beginning of each test
101mark()
102{
103 [ $MARK -gt 0 ] && result
104 MARK=`expr $MARK + 1`
105 TESTNAME=$1
106 exec 1>&4 2>&5
107 exec >"current.out"
108}
109
110test_args()
111{
112 COMMENT='Argument parsing - first type'
113 mark '1.1'
114 $SED 's/^/e1_/p' lines1
115 mark '1.2' ; $SED -n 's/^/e1_/p' lines1
116 mark '1.3'
117 $SED 's/^/e1_/p' <lines1
118 mark '1.4' ; $SED -n 's/^/e1_/p' <lines1
119 COMMENT='Argument parsing - second type'
120 mark '1.4.1'
121 $SED -e '' <lines1
122 echo 's/^/s1_/p' >script1
123 echo 's/^/s2_/p' >script2
124 mark '1.5'
125 $SED -f script1 lines1
126 mark '1.6'
127 $SED -f script1 <lines1
128 mark '1.7'
129 $SED -e 's/^/e1_/p' lines1
130 mark '1.8'
131 $SED -e 's/^/e1_/p' <lines1
132 mark '1.9' ; $SED -n -f script1 lines1
133 mark '1.10' ; $SED -n -f script1 <lines1
134 mark '1.11' ; $SED -n -e 's/^/e1_/p' lines1
135 mark '1.12'
136 $SED -n -e 's/^/e1_/p' <lines1
137 mark '1.13'
138 $SED -e 's/^/e1_/p' -e 's/^/e2_/p' lines1
139 mark '1.14'
140 $SED -f script1 -f script2 lines1
141 mark '1.15'
142 $SED -e 's/^/e1_/p' -f script1 lines1
143 mark '1.16'
144 $SED -e 's/^/e1_/p' lines1 lines1
145 # POSIX D11.2:11251
146 mark '1.17' ; $SED p <lines1 lines1
147cat >script1 <<EOF
148#n
149# A comment
150
151p
152EOF
153 mark '1.18' ; $SED -f script1 <lines1 lines1
154}
155
156test_addr()
157{
158 COMMENT='Address ranges'
159 mark '2.1' ; $SED -n -e '4p' lines1
160 mark '2.2' ; $SED -n -e '20p' lines1 lines2
161 mark '2.3' ; $SED -n -e '$p' lines1
162 mark '2.4' ; $SED -n -e '$p' lines1 lines2
163 mark '2.5' ; $SED -n -e '$a\
164hello' /dev/null
165 mark '2.6' ; $SED -n -e '$p' lines1 /dev/null lines2
166 # Should not print anything
167 mark '2.7' ; $SED -n -e '20p' lines1
168 mark '2.8' ; $SED -n -e '/NOTFOUND/p' lines1
169 mark '2.9' ; $SED -n '/l1_7/p' lines1
170 mark '2.10' ; $SED -n ' /l1_7/ p' lines1
171 mark '2.11' ; $SED -n '\_l1\_7_p' lines1
172 mark '2.12' ; $SED -n '1,4p' lines1
173 mark '2.13' ; $SED -n '1,$p' lines1 lines2
174 mark '2.14' ; $SED -n '1,/l2_9/p' lines1 lines2
175 mark '2.15' ; $SED -n '/4/,$p' lines1 lines2
176 mark '2.16' ; $SED -n '/4/,20p' lines1 lines2
177 mark '2.17' ; $SED -n '/4/,/10/p' lines1 lines2
178 mark '2.18' ; $SED -n '/l2_3/,/l1_8/p' lines1 lines2
179 mark '2.19' ; $SED -n '12,3p' lines1 lines2
180 mark '2.20' ; $SED -n '/l1_7/,3p' lines1 lines2
181 mark '2.21' ; $SED -n '13,+4p' lines1 lines2
182 mark '2.22' ; $SED -n '/l1_6/,+2p' lines1 lines2
183}
184
185test_group()
186{
187 COMMENT='Brace and other grouping'
188 mark '3.1' ; $SED -e '
1894,12 {
190 s/^/^/
191 s/$/$/
192 s/_/T/
193}' lines1
194 mark '3.2' ; $SED -e '
1954,12 {
196 s/^/^/
197 /6/,/10/ {
198 s/$/$/
199 /8/ s/_/T/
200 }
201}' lines1
202 mark '3.3' ; $SED -e '
2034,12 !{
204 s/^/^/
205 /6/,/10/ !{
206 s/$/$/
207 /8/ !s/_/T/
208 }
209}' lines1
210 mark '3.4' ; $SED -e '4,12!s/^/^/' lines1
211}
212
213test_acid()
214{
215 COMMENT='Commands a c d and i'
216 mark '4.1' ; $SED -n -e '
217s/^/before_i/p
21820i\
219inserted
220s/^/after_i/p
221' lines1 lines2
222 mark '4.2' ; $SED -n -e '
2235,12s/^/5-12/
224s/^/before_a/p
225/5-12/a\
226appended
227s/^/after_a/p
228' lines1 lines2
229 mark '4.3'
230 $SED -n -e '
231s/^/^/p
232/l1_/a\
233appended
2348,10N
235s/$/$/p
236' lines1 lines2
237 mark '4.4' ; $SED -n -e '
238c\
239hello
240' lines1
241 mark '4.5' ; $SED -n -e '
2428c\
243hello
244' lines1
245 mark '4.6' ; $SED -n -e '
2463,14c\
247hello
248' lines1
249# SunOS and GNU sed behave differently. We follow POSIX
250 mark '4.7' ; $SED -n -e '
2518,3c\
252hello
253' lines1
254 mark '4.8' ; $SED d <lines1
255}
256
257test_branch()
258{
259 COMMENT='Labels and branching'
260 mark '5.1' ; $SED -n -e '
261b label4
262:label3
263s/^/label3_/p
264b end
265:label4
2662,12b label1
267b label2
268:label1
269s/^/label1_/p
270b
271:label2
272s/^/label2_/p
273b label3
274:end
275' lines1
276 mark '5.2'
277 $SED -n -e '
278s/l1_/l2_/
279t ok
280b
281:ok
282s/^/tested /p
283' lines1 lines2
284# SunOS and GNU sed behave as follows: lines 9-$ aren't printed at all
285 mark '5.3' ; $SED -n -e '
2865,8b inside
2871,5 {
288 s/^/^/p
289 :inside
290 s/$/$/p
291}
292' lines1
293# Check that t clears the substitution done flag
294 mark '5.4' ; $SED -n -e '
2951,8s/^/^/
296t l1
297:l1
298t l2
299s/$/$/p
300b
301:l2
302s/^/ERROR/
303' lines1
304# Check that reading a line clears the substitution done flag
305 mark '5.5'
306 $SED -n -e '
307t l2
3081,8s/^/^/p
3092,7N
310b
311:l2
312s/^/ERROR/p
313' lines1
314 mark '5.6' ; $SED 5q lines1
315 mark '5.7' ; $SED -e '
3165i\
317hello
3185q' lines1
319# Branch across block boundary
320 mark '5.8' ; $SED -e '
321{
322:b
323}
324s/l/m/
325tb' lines1
326}
327
328test_pattern()
329{
330COMMENT='Pattern space commands'
331# Check that the pattern space is deleted
332 mark '6.1' ; $SED -n -e '
333c\
334changed
335p
336' lines1
337 mark '6.2' ; $SED -n -e '
3384d
339p
340' lines1
341 mark '6.3'
342 $SED -e 'N;N;N;D' lines1
343 mark '6.4' ; $SED -e '
3442h
3453H
3464g
3475G
3486x
3496p
3506x
3516p
352' lines1
353 mark '6.5' ; $SED -e '4n' lines1
354 mark '6.6' ; $SED -n -e '4n' lines1
355}
356
357test_print()
358{
359 COMMENT='Print and file routines'
360 awk 'END {for (i = 1; i < 256; i++) printf("%c", i);print "\n"}' \
361 </dev/null >lines3
362 # GNU and SunOS sed behave differently here
363 mark '7.1'
364 $SED -n l lines3
365 mark '7.2' ; $SED -e '/l2_/=' lines1 lines2
366 rm -f lines4
367 mark '7.3' ; $SED -e '3,12w lines4' lines1
368 COMMENT='w results'
369 cat lines4
370 mark '7.4' ; $SED -e '4r lines2' lines1
371 mark '7.5' ; $SED -e '5r /dev/dds' lines1
372 mark '7.6' ; $SED -e '6r /dev/null' lines1
373 mark '7.7'
374 sed '200q' $DICT | sed 's$.*$s/^/&/w tmpdir/&$' >script1
375 rm -rf tmpdir
376 mkdir tmpdir
377 $SED -f script1 lines1
378 cat tmpdir/*
379 rm -rf tmpdir
380 mark '7.8'
381 echo line1 > lines3
382 echo "" >> lines3
383 TODO=1
384 $SED -n -e '$p' lines3 /dev/null
385
386}
387
388test_subst()
389{
390 COMMENT='Substitution commands'
391 mark '8.1' ; $SED -e 's/./X/g' lines1
392 mark '8.2' ; $SED -e 's,.,X,g' lines1
393# SunOS sed thinks we are escaping . as wildcard, not as separator
394 mark '8.3'
395 $SED -e 's.\..X.g' lines1
396 mark '8.4' ; $SED -e 's/[\/]/Q/' lines1
397 mark '8.5' ; $SED -e 's_\__X_' lines1
398 mark '8.6' ; $SED -e 's/./(&)/g' lines1
399 mark '8.7' ; $SED -e 's/./(\&)/g' lines1
400 mark '8.8' ; $SED -e 's/\(.\)\(.\)\(.\)/x\3x\2x\1/g' lines1
401 mark '8.9' ; $SED -e 's/_/u0\
402u1\
403u2/g' lines1
404 mark '8.10'
405 $SED -e 's/./X/4' lines1
406 rm -f lines4
407 mark '8.11' ; $SED -e 's/1/X/w lines4' lines1
408 COMMENT='s wfile results'
409 cat lines4
410 mark '8.12' ; $SED -e 's/[123]/X/g' lines1
411 mark '8.13' ; $SED -e 'y/0123456789/9876543210/' lines1
412 mark '8.14' ;
413 $SED -e 'y10\123456789198765432\101' lines1
414 mark '8.15' ; $SED -e '1N;2y/\n/X/' lines1
415 mark '8.16'
416 echo 'eeefff' | $SED -e '
417 p
418 s/e/X/p
419 :x
420 s//Y/p
421 # Establish limit counter in the hold space
422 # GNU sed version 3.02 enters into an infinite loop here
423 x
424 /.\{10\}/ {
425 s/.*/ERROR/
426 b
427 }
428 s/.*/&./
429 x
430 /f/bx
431 '
432 # POSIX does not say that this should work,
433 # but it does for GNU, BSD, and SunOS
434 mark '8.17' ; $SED -e 's/[/]/Q/' lines1
435
436 COMMENT='[ as an s delimiter and its escapes'
437 mark '8.18' ; $SED -e 's[_[X[' lines1
438 # This is a matter of interpretation
439 # POSIX 1003.1, 2004 says "Within the BRE and the replacement,
440 # the BRE delimiter itself can be used as a *literal* character
441 # if it is preceded by a backslash"
442 # SunOS 5.1 /usr/bin/sed and Mac OS X follow the literal POSIX
443 # interpretation.
444 # GNU sed version 4.1.5 treats \[ as the beginning of a character
445 # set specification (both with --posix and without).
446 mark '8.19' ; sed 's/l/[/' lines1 | $SED -e 's[\[.[X['
447 mark '8.20' ; sed 's/l/[/' lines1 | $SED -e 's[\[.[X\[['
448 COMMENT='\ in y command'
449 mark '8.21'
450 echo 'a\b(c' |
451 $SED 'y%ABCDEFGHIJKLMNOPQRSTUVWXYZ, /\\()"%abcdefghijklmnopqrstuvwxyz,------%'
448}
449
450test_error()
451{
452 COMMENT='Error cases'
453 mark '9.1' ; $SED -x 2>/dev/null ; echo $?
454 mark '9.2' ; $SED -f 2>/dev/null ; echo $?
455 mark '9.3' ; $SED -e 2>/dev/null ; echo $?
456 mark '9.4' ; $SED -f /dev/xyzzyxyzy 2>/dev/null ; echo $?
457 mark '9.5' ; $SED p /dev/xyzzyxyzy 2>/dev/null ; echo $?
458 mark '9.6' ; $SED -f /bin/sh 2>/dev/null ; echo $?
459 mark '9.7' ; $SED '{' 2>/dev/null ; echo $?
460 mark '9.8' ; $SED '{' 2>/dev/null ; echo $?
461 mark '9.9' ; $SED '/hello/' 2>/dev/null ; echo $?
462 mark '9.10' ; $SED '1,/hello/' 2>/dev/null ; echo $?
463 mark '9.11' ; $SED -e '-5p' 2>/dev/null ; echo $?
464 mark '9.12' ; $SED '/jj' 2>/dev/null ; echo $?
465 mark '9.13' ; $SED 'a hello' 2>/dev/null ; echo $?
466 mark '9.14' ; $SED 'a \ hello' 2>/dev/null ; echo $?
467 mark '9.15' ; $SED 'b foo' 2>/dev/null ; echo $?
468 mark '9.16' ; $SED 'd hello' 2>/dev/null ; echo $?
469 mark '9.17' ; $SED 's/aa' 2>/dev/null ; echo $?
470 mark '9.18' ; $SED 's/aa/' 2>/dev/null ; echo $?
471 mark '9.19' ; $SED 's/a/b' 2>/dev/null ; echo $?
472 mark '9.20' ; $SED 's/a/b/c/d' 2>/dev/null ; echo $?
473 mark '9.21' ; $SED 's/a/b/ 1 2' 2>/dev/null ; echo $?
474 mark '9.22' ; $SED 's/a/b/ 1 g' 2>/dev/null ; echo $?
475 mark '9.23' ; $SED 's/a/b/w' 2>/dev/null ; echo $?
476 mark '9.24' ; $SED 'y/aa' 2>/dev/null ; echo $?
477 mark '9.25' ; $SED 'y/aa/b/' 2>/dev/null ; echo $?
478 mark '9.26' ; $SED 'y/aa/' 2>/dev/null ; echo $?
479 mark '9.27' ; $SED 'y/a/b' 2>/dev/null ; echo $?
480 mark '9.28' ; $SED 'y/a/b/c/d' 2>/dev/null ; echo $?
481 mark '9.29' ; $SED '!' 2>/dev/null ; echo $?
482 mark '9.30' ; $SED supercalifrangolisticexprialidociussupercalifrangolisticexcius 2>/dev/null ; echo $?
483 mark '9.31' ; $SED '' /dev/null 2>/dev/null ; echo $?
484}
485
486main
452}
453
454test_error()
455{
456 COMMENT='Error cases'
457 mark '9.1' ; $SED -x 2>/dev/null ; echo $?
458 mark '9.2' ; $SED -f 2>/dev/null ; echo $?
459 mark '9.3' ; $SED -e 2>/dev/null ; echo $?
460 mark '9.4' ; $SED -f /dev/xyzzyxyzy 2>/dev/null ; echo $?
461 mark '9.5' ; $SED p /dev/xyzzyxyzy 2>/dev/null ; echo $?
462 mark '9.6' ; $SED -f /bin/sh 2>/dev/null ; echo $?
463 mark '9.7' ; $SED '{' 2>/dev/null ; echo $?
464 mark '9.8' ; $SED '{' 2>/dev/null ; echo $?
465 mark '9.9' ; $SED '/hello/' 2>/dev/null ; echo $?
466 mark '9.10' ; $SED '1,/hello/' 2>/dev/null ; echo $?
467 mark '9.11' ; $SED -e '-5p' 2>/dev/null ; echo $?
468 mark '9.12' ; $SED '/jj' 2>/dev/null ; echo $?
469 mark '9.13' ; $SED 'a hello' 2>/dev/null ; echo $?
470 mark '9.14' ; $SED 'a \ hello' 2>/dev/null ; echo $?
471 mark '9.15' ; $SED 'b foo' 2>/dev/null ; echo $?
472 mark '9.16' ; $SED 'd hello' 2>/dev/null ; echo $?
473 mark '9.17' ; $SED 's/aa' 2>/dev/null ; echo $?
474 mark '9.18' ; $SED 's/aa/' 2>/dev/null ; echo $?
475 mark '9.19' ; $SED 's/a/b' 2>/dev/null ; echo $?
476 mark '9.20' ; $SED 's/a/b/c/d' 2>/dev/null ; echo $?
477 mark '9.21' ; $SED 's/a/b/ 1 2' 2>/dev/null ; echo $?
478 mark '9.22' ; $SED 's/a/b/ 1 g' 2>/dev/null ; echo $?
479 mark '9.23' ; $SED 's/a/b/w' 2>/dev/null ; echo $?
480 mark '9.24' ; $SED 'y/aa' 2>/dev/null ; echo $?
481 mark '9.25' ; $SED 'y/aa/b/' 2>/dev/null ; echo $?
482 mark '9.26' ; $SED 'y/aa/' 2>/dev/null ; echo $?
483 mark '9.27' ; $SED 'y/a/b' 2>/dev/null ; echo $?
484 mark '9.28' ; $SED 'y/a/b/c/d' 2>/dev/null ; echo $?
485 mark '9.29' ; $SED '!' 2>/dev/null ; echo $?
486 mark '9.30' ; $SED supercalifrangolisticexprialidociussupercalifrangolisticexcius 2>/dev/null ; echo $?
487 mark '9.31' ; $SED '' /dev/null 2>/dev/null ; echo $?
488}
489
490main