Deleted Added
full compact
multi_test.sh (167549) multi_test.sh (167552)
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 167549 2007-03-14 11:03:00Z dds $
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#
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
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.
41
42main()
43{
45
46main()
47{
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
48 REGRESS=regress.multitest.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
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
57 exec 4>&1 5>&2
56 echo "1..90"
58
57
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
58 exec 4>&1 5>&2
59 tests
69 exec 1>&4 2>&5
60 exec 1>&4 2>&5
70 diff -c $BASELOG $TESTLOG | more
61
62 # Remove temporary files
63 rm -f current.out lines[1-4] script[1-2]
71}
72
73tests()
74{
64}
65
66tests()
67{
75 SED=$1
76 DIR=$2
77 rm -rf $DIR
78 mkdir $DIR
79 MARK=100
68 SED=sed
69 MARK=0
80
81 test_args
82 test_addr
70
71 test_args
72 test_addr
83 echo Testing commands
84 test_group
85 test_acid
86 test_branch
87 test_pattern
88 test_print
89 test_subst
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
90}
91
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
92mark()
93{
99mark()
100{
101 [ $MARK -gt 0 ] && result
94 MARK=`expr $MARK + 1`
102 MARK=`expr $MARK + 1`
103 TESTNAME=$1
95 exec 1>&4 2>&5
104 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
105 exec >"current.out"
100}
101
102test_args()
103{
106}
107
108test_args()
109{
110 COMMENT='Argument parsing - first type'
104 mark '1.1'
111 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 $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
112 echo Second type
117 COMMENT='Argument parsing - 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
121 mark '1.7'
122 $SED -e 's/^/e1_/p' lines1
123 mark '1.8'
124 $SED -e 's/^/e1_/p' <lines1
125 mark '1.9' ; $SED -n -f script1 lines1
126 mark '1.10' ; $SED -n -f script1 <lines1
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'
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
126 mark '1.7'
127 $SED -e 's/^/e1_/p' lines1
128 mark '1.8'
129 $SED -e 's/^/e1_/p' <lines1
130 mark '1.9' ; $SED -n -f script1 lines1
131 mark '1.10' ; $SED -n -f script1 <lines1
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'
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 $SED -e 's/^/e1_/p' -f script1 lines1
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{
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{
155 echo Testing address ranges
156 COMMENT='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
164 mark '2.7' ; $SED -n -e '20p' lines1
165 mark '2.8' ; $SED -n -e '/NOTFOUND/p' lines1
166 mark '2.9' ; $SED -n '/l1_7/p' lines1
167 mark '2.10' ; $SED -n ' /l1_7/ p' lines1
168 mark '2.11' ; $SED -n '\_l1\_7_p' lines1
169 mark '2.12' ; $SED -n '1,4p' lines1
170 mark '2.13' ; $SED -n '1,$p' lines1 lines2
171 mark '2.14' ; $SED -n '1,/l2_9/p' lines1 lines2
172 mark '2.15' ; $SED -n '/4/,$p' lines1 lines2
173 mark '2.16' ; $SED -n '/4/,20p' lines1 lines2
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{
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
165 mark '2.7' ; $SED -n -e '20p' lines1
166 mark '2.8' ; $SED -n -e '/NOTFOUND/p' lines1
167 mark '2.9' ; $SED -n '/l1_7/p' lines1
168 mark '2.10' ; $SED -n ' /l1_7/ p' lines1
169 mark '2.11' ; $SED -n '\_l1\_7_p' lines1
170 mark '2.12' ; $SED -n '1,4p' lines1
171 mark '2.13' ; $SED -n '1,$p' lines1 lines2
172 mark '2.14' ; $SED -n '1,/l2_9/p' lines1 lines2
173 mark '2.15' ; $SED -n '/4/,$p' lines1 lines2
174 mark '2.16' ; $SED -n '/4/,20p' lines1 lines2
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{
182 echo Brace and other grouping
183 COMMENT='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 {
191 s/^/^/
192 /6/,/10/ {
193 s/$/$/
194 /8/ s/_/T/
195 }
196}' lines1
197 mark '3.3' ; $SED -e '
1984,12 !{
199 s/^/^/
200 /6/,/10/ !{
201 s/$/$/
202 /8/ !s/_/T/
203 }
204}' lines1
205 mark '3.4' ; $SED -e '4,12!s/^/^/' lines1
206}
207
208test_acid()
209{
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 {
192 s/^/^/
193 /6/,/10/ {
194 s/$/$/
195 /8/ s/_/T/
196 }
197}' lines1
198 mark '3.3' ; $SED -e '
1994,12 !{
200 s/^/^/
201 /6/,/10/ !{
202 s/$/$/
203 /8/ !s/_/T/
204 }
205}' lines1
206 mark '3.4' ; $SED -e '4,12!s/^/^/' lines1
207}
208
209test_acid()
210{
210 echo Testing a c d and i commands
211 COMMENT='Commands a c d and i'
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/
219s/^/before_a/p
220/5-12/a\
221appended
222s/^/after_a/p
223' lines1 lines2
224 mark '4.3'
225 $SED -n -e '
226s/^/^/p
227/l1_/a\
228appended
2298,10N
230s/$/$/p
231' lines1 lines2
232 mark '4.4' ; $SED -n -e '
233c\
234hello
235' lines1
236 mark '4.5' ; $SED -n -e '
2378c\
238hello
239' lines1
240 mark '4.6' ; $SED -n -e '
2413,14c\
242hello
243' lines1
244# SunOS and GNU sed behave differently. We follow POSIX
245 mark '4.7' ; $SED -n -e '
2468,3c\
247hello
248' lines1
249 mark '4.8' ; $SED d <lines1
250}
251
252test_branch()
253{
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/
220s/^/before_a/p
221/5-12/a\
222appended
223s/^/after_a/p
224' lines1 lines2
225 mark '4.3'
226 $SED -n -e '
227s/^/^/p
228/l1_/a\
229appended
2308,10N
231s/$/$/p
232' lines1 lines2
233 mark '4.4' ; $SED -n -e '
234c\
235hello
236' lines1
237 mark '4.5' ; $SED -n -e '
2388c\
239hello
240' lines1
241 mark '4.6' ; $SED -n -e '
2423,14c\
243hello
244' lines1
245# SunOS and GNU sed behave differently. We follow POSIX
246 mark '4.7' ; $SED -n -e '
2478,3c\
248hello
249' lines1
250 mark '4.8' ; $SED d <lines1
251}
252
253test_branch()
254{
254 echo Testing labels and branching
255 COMMENT='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
263:label1
264s/^/label1_/p
265b
266:label2
267s/^/label2_/p
268b label3
269:end
270' lines1
271 mark '5.2'
272 $SED -n -e '
273s/l1_/l2_/
274t ok
275b
276:ok
277s/^/tested /p
278' lines1 lines2
279# SunOS and GNU sed behave differently here. Clarification needed.
280 mark '5.3' ; $SED -n -e '
2815,8b inside
2821,5 {
283 s/^/^/p
284 :inside
285 s/$/$/p
286}
287' lines1
288# Check that t clears the substitution done flag
289 mark '5.4' ; $SED -n -e '
2901,8s/^/^/
291t l1
292:l1
293t l2
294s/$/$/p
295b
296:l2
297s/^/ERROR/
298' lines1
299# Check that reading a line clears the substitution done flag
300 mark '5.5'
301 $SED -n -e '
302t l2
3031,8s/^/^/p
3042,7N
305b
306:l2
307s/^/ERROR/p
308' lines1
309 mark '5.6' ; $SED 5q lines1
310 mark '5.7' ; $SED -e '
3115i\
312hello
3135q' lines1
314# Branch across block boundary
315 mark '5.8' ; $SED -e '
316{
317:b
318}
319s/l/m/
320tb' lines1
321}
322
323test_pattern()
324{
256 mark '5.1' ; $SED -n -e '
257b label4
258:label3
259s/^/label3_/p
260b end
261:label4
2622,12b label1
263b label2
264:label1
265s/^/label1_/p
266b
267:label2
268s/^/label2_/p
269b label3
270:end
271' lines1
272 mark '5.2'
273 $SED -n -e '
274s/l1_/l2_/
275t ok
276b
277:ok
278s/^/tested /p
279' lines1 lines2
280# SunOS and GNU sed behave differently here. Clarification needed.
281 mark '5.3' ; $SED -n -e '
2825,8b inside
2831,5 {
284 s/^/^/p
285 :inside
286 s/$/$/p
287}
288' lines1
289# Check that t clears the substitution done flag
290 mark '5.4' ; $SED -n -e '
2911,8s/^/^/
292t l1
293:l1
294t l2
295s/$/$/p
296b
297:l2
298s/^/ERROR/
299' lines1
300# Check that reading a line clears the substitution done flag
301 mark '5.5'
302 $SED -n -e '
303t l2
3041,8s/^/^/p
3052,7N
306b
307:l2
308s/^/ERROR/p
309' lines1
310 mark '5.6' ; $SED 5q lines1
311 mark '5.7' ; $SED -e '
3125i\
313hello
3145q' lines1
315# Branch across block boundary
316 mark '5.8' ; $SED -e '
317{
318:b
319}
320s/l/m/
321tb' lines1
322}
323
324test_pattern()
325{
325echo Pattern space commands
326COMMENT='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'
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'
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
338 $SED -e 'N;N;N;D' lines1
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{
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{
358 echo Testing print and file routines
355 COMMENT='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
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
367 echo w results
364 COMMENT='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'
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'
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
377 echo line1 > lines3
378 echo "" >> lines3
379 TODO=1
380 $SED -n -e '$p' lines3 /dev/null
387
388}
389
390test_subst()
391{
381
382}
383
384test_subst()
385{
392 echo Testing substitution commands
386 COMMENT='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'
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'
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
391 $SED -e 's.\..X.g' lines1
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
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
414 echo s wfile results
404 COMMENT='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 '
423 p
424 s/e/X/p
425 :x
426 s//Y/p
427 # Establish limit counter in the hold space
428 # GNU sed version 3.02 enters into an infinite loop here
429 x
430 /.\{10\}/ {
431 s/.*/ERROR/
432 b
433 }
434 s/.*/&./
435 x
436 /f/bx
437 '
438 # POSIX does not say that this should work,
439 # but it does for GNU, BSD, and SunOS
440 mark '8.17' ; $SED -e 's/[/]/Q/' lines1
441}
442
443test_error()
444{
445 exec 0>&3 4>&1 5>&2
446 exec 0</dev/null
447 exec 2>&1
448 set -x
449 $TEST -x && exit 1
450 $TEST -f && exit 1
451 $TEST -e && exit 1
452 $TEST -f /dev/dds && exit 1
453 $TEST p /dev/dds && exit 1
454 $TEST -f /bin/sh && exit 1
455 $TEST '{' && exit 1
456 $TEST '{' && exit 1
457 $TEST '/hello/' && exit 1
458 $TEST '1,/hello/' && exit 1
459 $TEST -e '-5p' && exit 1
460 $TEST '/jj' && exit 1
461 $TEST 'a hello' && exit 1
462 $TEST 'a \ hello' && exit 1
463 $TEST 'b foo' && exit 1
464 $TEST 'd hello' && exit 1
465 $TEST 's/aa' && exit 1
466 $TEST 's/aa/' && exit 1
467 $TEST 's/a/b' && exit 1
468 $TEST 's/a/b/c/d' && exit 1
469 $TEST 's/a/b/ 1 2' && exit 1
470 $TEST 's/a/b/ 1 g' && exit 1
471 $TEST 's/a/b/w' && exit 1
472 $TEST 'y/aa' && exit 1
473 $TEST 'y/aa/b/' && exit 1
474 $TEST 'y/aa/' && exit 1
475 $TEST 'y/a/b' && exit 1
476 $TEST 'y/a/b/c/d' && exit 1
477 $TEST '!' && exit 1
478 $TEST supercalifrangolisticexprialidociussupercalifrangolisticexcius
479 set +x
480 exec 0>&3 1>&4 2>&5
481}
482
483main
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 '
413 p
414 s/e/X/p
415 :x
416 s//Y/p
417 # Establish limit counter in the hold space
418 # GNU sed version 3.02 enters into an infinite loop here
419 x
420 /.\{10\}/ {
421 s/.*/ERROR/
422 b
423 }
424 s/.*/&./
425 x
426 /f/bx
427 '
428 # POSIX does not say that this should work,
429 # but it does for GNU, BSD, and SunOS
430 mark '8.17' ; $SED -e 's/[/]/Q/' lines1
431}
432
433test_error()
434{
435 exec 0>&3 4>&1 5>&2
436 exec 0</dev/null
437 exec 2>&1
438 set -x
439 $TEST -x && exit 1
440 $TEST -f && exit 1
441 $TEST -e && exit 1
442 $TEST -f /dev/dds && exit 1
443 $TEST p /dev/dds && exit 1
444 $TEST -f /bin/sh && exit 1
445 $TEST '{' && exit 1
446 $TEST '{' && exit 1
447 $TEST '/hello/' && exit 1
448 $TEST '1,/hello/' && exit 1
449 $TEST -e '-5p' && exit 1
450 $TEST '/jj' && exit 1
451 $TEST 'a hello' && exit 1
452 $TEST 'a \ hello' && exit 1
453 $TEST 'b foo' && exit 1
454 $TEST 'd hello' && exit 1
455 $TEST 's/aa' && exit 1
456 $TEST 's/aa/' && exit 1
457 $TEST 's/a/b' && exit 1
458 $TEST 's/a/b/c/d' && exit 1
459 $TEST 's/a/b/ 1 2' && exit 1
460 $TEST 's/a/b/ 1 g' && exit 1
461 $TEST 's/a/b/w' && exit 1
462 $TEST 'y/aa' && exit 1
463 $TEST 'y/aa/b/' && exit 1
464 $TEST 'y/aa/' && exit 1
465 $TEST 'y/a/b' && exit 1
466 $TEST 'y/a/b/c/d' && exit 1
467 $TEST '!' && exit 1
468 $TEST supercalifrangolisticexprialidociussupercalifrangolisticexcius
469 set +x
470 exec 0>&3 1>&4 2>&5
471}
472
473main