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# 3. All advertising materials mentioning features or use of this software 16# must display the following acknowledgement: 17# This product includes software developed by the University of 18# California, Berkeley and its contributors. 19# 4. Neither the name of the University nor the names of its contributors 20# may be used to endorse or promote products derived from this software 21# without specific prior written permission. 22# 23# THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 24# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 25# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 26# ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 27# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 28# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 29# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 30# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 31# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 32# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 33# SUCH DAMAGE. 34# 35# @(#)sed.test 8.1 (Berkeley) 6/6/93 36#
| 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# 3. All advertising materials mentioning features or use of this software 16# must display the following acknowledgement: 17# This product includes software developed by the University of 18# California, Berkeley and its contributors. 19# 4. Neither the name of the University nor the names of its contributors 20# may be used to endorse or promote products derived from this software 21# without specific prior written permission. 22# 23# THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 24# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 25# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 26# ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 27# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 28# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 29# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 30# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 31# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 32# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 33# SUCH DAMAGE. 34# 35# @(#)sed.test 8.1 (Berkeley) 6/6/93 36#
|
| 37# $FreeBSD: head/tools/regression/usr.bin/sed/multitest.t 117900 2003-07-22 19:22:08Z dds $ 38#
|
37 38# sed Regression Tests 39# 40# The following files are created: 41# lines[1-4], script1, script2 42# Two directories *.out contain the test results 43 44main() 45{ 46 BASE=/usr/bin/sed 47 BASELOG=sed.out 48 TEST=`cd ..; make whereobj`/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=1 61 GNU=0 62 SUN=0 63 tests $BASE $BASELOG 64 65 BSD=0 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 if [ $SUN -eq 1 ] ; then 108 echo SunOS sed prints only with -n 109 else 110 $SED 's/^/e1_/p' lines1 111 fi 112 mark '1.2' ; $SED -n 's/^/e1_/p' lines1 113 mark '1.3' 114 if [ $SUN -eq 1 ] ; then 115 echo SunOS sed prints only with -n 116 else 117 $SED 's/^/e1_/p' <lines1 118 fi 119 mark '1.4' ; $SED -n 's/^/e1_/p' <lines1 120 echo Second type 121 mark '1.4.1' 122 if [ $SUN -eq 1 ] ; then 123 echo SunOS sed fails this 124 fi 125 $SED -e '' <lines1 126 echo 's/^/s1_/p' >script1 127 echo 's/^/s2_/p' >script2 128 mark '1.5' 129 if [ $SUN -eq 1 ] ; then 130 echo SunOS sed prints only with -n 131 else 132 $SED -f script1 lines1 133 fi 134 mark '1.6' 135 if [ $SUN -eq 1 ] ; then 136 echo SunOS sed prints only with -n 137 else 138 $SED -f script1 <lines1 139 fi 140 mark '1.7' 141 if [ $SUN -eq 1 ] ; then 142 echo SunOS sed prints only with -n 143 else 144 $SED -e 's/^/e1_/p' lines1 145 fi 146 mark '1.8' 147 if [ $SUN -eq 1 ] ; then 148 echo SunOS sed prints only with -n 149 else 150 $SED -e 's/^/e1_/p' <lines1 151 fi 152 mark '1.9' ; $SED -n -f script1 lines1 153 mark '1.10' ; $SED -n -f script1 <lines1 154 mark '1.11' ; $SED -n -e 's/^/e1_/p' lines1 155 mark '1.12' 156 if [ $SUN -eq 1 ] ; then 157 echo SunOS sed prints only with -n 158 else 159 $SED -n -e 's/^/e1_/p' <lines1 160 fi 161 mark '1.13' 162 if [ $SUN -eq 1 ] ; then 163 echo SunOS sed prints only with -n 164 else 165 $SED -e 's/^/e1_/p' -e 's/^/e2_/p' lines1 166 fi 167 mark '1.14' 168 if [ $SUN -eq 1 ] ; then 169 echo SunOS sed prints only with -n 170 else 171 $SED -f script1 -f script2 lines1 172 fi 173 mark '1.15' 174 if [ $GNU -eq 1 -o $SUN -eq 1 ] ; then 175 echo GNU and SunOS sed fail this following older POSIX draft 176 else 177 $SED -e 's/^/e1_/p' -f script1 lines1 178 fi 179 mark '1.16' 180 if [ $SUN -eq 1 ] ; then 181 echo SunOS sed prints only with -n 182 else 183 $SED -e 's/^/e1_/p' lines1 lines1 184 fi 185 # POSIX D11.2:11251 186 mark '1.17' ; $SED p <lines1 lines1 187cat >script1 <<EOF 188#n 189# A comment 190 191p 192EOF 193 mark '1.18' ; $SED -f script1 <lines1 lines1 194} 195 196test_addr() 197{ 198 echo Testing address ranges 199 mark '2.1' ; $SED -n -e '4p' lines1 200 mark '2.2' ; $SED -n -e '20p' lines1 lines2 201 mark '2.3' ; $SED -n -e '$p' lines1 202 mark '2.4' ; $SED -n -e '$p' lines1 lines2 203 mark '2.5' ; $SED -n -e '$a\ 204hello' /dev/null 205 mark '2.6' ; $SED -n -e '$p' lines1 /dev/null lines2 206 # Should not print anything 207 mark '2.7' ; $SED -n -e '20p' lines1 208 mark '2.8' ; $SED -n -e '0p' lines1 209 mark '2.9' ; $SED -n '/l1_7/p' lines1 210 mark '2.10' ; $SED -n ' /l1_7/ p' lines1 211 mark '2.11' 212 if [ $BSD -eq 1 ] ; then 213 echo BSD sed fails this test 214 fi 215 if [ $GNU -eq 1 ] ; then 216 echo GNU sed fails this 217 fi 218 $SED -n '\_l1\_7_p' lines1 219 mark '2.12' ; $SED -n '1,4p' lines1 220 mark '2.13' ; $SED -n '1,$p' lines1 lines2 221 mark '2.14' ; $SED -n '1,/l2_9/p' lines1 lines2 222 mark '2.15' ; $SED -n '/4/,$p' lines1 lines2 223 mark '2.16' ; $SED -n '/4/,20p' lines1 lines2 224 mark '2.17' ; $SED -n '/4/,/10/p' lines1 lines2 225 mark '2.18' ; $SED -n '/l2_3/,/l1_8/p' lines1 lines2 226 mark '2.19' 227 if [ $GNU -eq 1 ] ; then 228 echo GNU sed fails this 229 fi 230 $SED -n '12,3p' lines1 lines2 231 mark '2.20' 232 if [ $GNU -eq 1 ] ; then 233 echo GNU sed fails this 234 fi 235 $SED -n '/l1_7/,3p' lines1 lines2 236} 237 238test_group() 239{ 240 echo Brace and other grouping 241 mark '3.1' ; $SED -e ' 2424,12 { 243 s/^/^/ 244 s/$/$/ 245 s/_/T/ 246}' lines1 247 mark '3.2' ; $SED -e ' 2484,12 { 249 s/^/^/ 250 /6/,/10/ { 251 s/$/$/ 252 /8/ s/_/T/ 253 } 254}' lines1 255 mark '3.3' ; $SED -e ' 2564,12 !{ 257 s/^/^/ 258 /6/,/10/ !{ 259 s/$/$/ 260 /8/ !s/_/T/ 261 } 262}' lines1 263 mark '3.4' ; $SED -e '4,12!s/^/^/' lines1 264} 265 266test_acid() 267{ 268 echo Testing a c d and i commands 269 mark '4.1' ; $SED -n -e ' 270s/^/before_i/p 27120i\ 272inserted 273s/^/after_i/p 274' lines1 lines2 275 mark '4.2' ; $SED -n -e ' 2765,12s/^/5-12/ 277s/^/before_a/p 278/5-12/a\ 279appended 280s/^/after_a/p 281' lines1 lines2 282 mark '4.3' 283 if [ $GNU -eq 1 ] ; then 284 echo GNU sed fails this 285 fi 286 $SED -n -e ' 287s/^/^/p 288/l1_/a\ 289appended 2908,10N 291s/$/$/p 292' lines1 lines2 293 mark '4.4' ; $SED -n -e ' 294c\ 295hello 296' lines1 297 mark '4.5' ; $SED -n -e ' 2988c\ 299hello 300' lines1 301 mark '4.6' ; $SED -n -e ' 3023,14c\ 303hello 304' lines1 305# SunOS and GNU sed behave differently. We follow POSIX 306# mark '4.7' ; $SED -n -e ' 307#8,3c\ 308#hello 309#' lines1 310 mark '4.8' ; $SED d <lines1 311} 312 313test_branch() 314{ 315 echo Testing labels and branching 316 mark '5.1' ; $SED -n -e ' 317b label4 318:label3 319s/^/label3_/p 320b end 321:label4 3222,12b label1 323b label2 324:label1 325s/^/label1_/p 326b 327:label2 328s/^/label2_/p 329b label3 330:end 331' lines1 332 mark '5.2' 333 if [ $BSD -eq 1 ] ; then 334 echo BSD sed fails this test 335 fi 336 $SED -n -e ' 337s/l1_/l2_/ 338t ok 339b 340:ok 341s/^/tested /p 342' lines1 lines2 343# SunOS sed behaves differently here. Clarification needed. 344# mark '5.3' ; $SED -n -e ' 345#5,8b inside 346#1,5 { 347# s/^/^/p 348# :inside 349# s/$/$/p 350#} 351#' lines1 352# Check that t clears the substitution done flag 353 mark '5.4' ; $SED -n -e ' 3541,8s/^/^/ 355t l1 356:l1 357t l2 358s/$/$/p 359b 360:l2 361s/^/ERROR/ 362' lines1 363# Check that reading a line clears the substitution done flag 364 mark '5.5' 365 if [ $BSD -eq 1 ] ; then 366 echo BSD sed fails this test 367 fi 368 $SED -n -e ' 369t l2 3701,8s/^/^/p 3712,7N 372b 373:l2 374s/^/ERROR/p 375' lines1 376 mark '5.6' ; $SED 5q lines1 377 mark '5.7' ; $SED -e ' 3785i\ 379hello 3805q' lines1 381# Branch across block boundary 382 mark '5.8' ; $SED -e ' 383{ 384:b 385} 386s/l/m/ 387tb' lines1 388} 389 390test_pattern() 391{ 392echo Pattern space commands 393# Check that the pattern space is deleted 394 mark '6.1' ; $SED -n -e ' 395c\ 396changed 397p 398' lines1 399 mark '6.2' ; $SED -n -e ' 4004d 401p 402' lines1 403# SunOS sed refused to print here 404# mark '6.3' ; $SED -e ' 405#N 406#N 407#N 408#D 409#P 410#4p 411#' lines1 412 mark '6.4' ; $SED -e ' 4132h 4143H 4154g 4165G 4176x 4186p 4196x 4206p 421' lines1 422 mark '6.5' ; $SED -e '4n' lines1 423 mark '6.6' ; $SED -n -e '4n' lines1 424} 425 426test_print() 427{ 428 echo Testing print and file routines 429 awk 'END {for (i = 1; i < 256; i++) printf("%c", i);print "\n"}' \ 430 </dev/null >lines3 431 # GNU and SunOS sed behave differently here 432 mark '7.1'
| 39 40# sed Regression Tests 41# 42# The following files are created: 43# lines[1-4], script1, script2 44# Two directories *.out contain the test results 45 46main() 47{ 48 BASE=/usr/bin/sed 49 BASELOG=sed.out 50 TEST=`cd ..; make whereobj`/sed 51 TESTLOG=nsed.out 52 DICT=/usr/share/dict/words 53 54 test_error | more 55 56 awk 'END { for (i = 1; i < 15; i++) print "l1_" i}' </dev/null >lines1 57 awk 'END { for (i = 1; i < 10; i++) print "l2_" i}' </dev/null >lines2 58 59 exec 4>&1 5>&2 60 61 # Set these flags to get messages about known problems 62 BSD=1 63 GNU=0 64 SUN=0 65 tests $BASE $BASELOG 66 67 BSD=0 68 GNU=0 69 SUN=0 70 tests $TEST $TESTLOG 71 exec 1>&4 2>&5 72 diff -c $BASELOG $TESTLOG | more 73} 74 75tests() 76{ 77 SED=$1 78 DIR=$2 79 rm -rf $DIR 80 mkdir $DIR 81 MARK=100 82 83 test_args 84 test_addr 85 echo Testing commands 86 test_group 87 test_acid 88 test_branch 89 test_pattern 90 test_print 91 test_subst 92} 93 94mark() 95{ 96 MARK=`expr $MARK + 1` 97 exec 1>&4 2>&5 98 exec >"$DIR/${MARK}_$1" 99 echo "Test $1:$MARK" 100 # Uncomment this line to match tests with sed error messages 101 echo "Test $1:$MARK" >&5 102} 103 104test_args() 105{ 106 mark '1.1' 107 echo Testing argument parsing 108 echo First type 109 if [ $SUN -eq 1 ] ; then 110 echo SunOS sed prints only with -n 111 else 112 $SED 's/^/e1_/p' lines1 113 fi 114 mark '1.2' ; $SED -n 's/^/e1_/p' lines1 115 mark '1.3' 116 if [ $SUN -eq 1 ] ; then 117 echo SunOS sed prints only with -n 118 else 119 $SED 's/^/e1_/p' <lines1 120 fi 121 mark '1.4' ; $SED -n 's/^/e1_/p' <lines1 122 echo Second type 123 mark '1.4.1' 124 if [ $SUN -eq 1 ] ; then 125 echo SunOS sed fails this 126 fi 127 $SED -e '' <lines1 128 echo 's/^/s1_/p' >script1 129 echo 's/^/s2_/p' >script2 130 mark '1.5' 131 if [ $SUN -eq 1 ] ; then 132 echo SunOS sed prints only with -n 133 else 134 $SED -f script1 lines1 135 fi 136 mark '1.6' 137 if [ $SUN -eq 1 ] ; then 138 echo SunOS sed prints only with -n 139 else 140 $SED -f script1 <lines1 141 fi 142 mark '1.7' 143 if [ $SUN -eq 1 ] ; then 144 echo SunOS sed prints only with -n 145 else 146 $SED -e 's/^/e1_/p' lines1 147 fi 148 mark '1.8' 149 if [ $SUN -eq 1 ] ; then 150 echo SunOS sed prints only with -n 151 else 152 $SED -e 's/^/e1_/p' <lines1 153 fi 154 mark '1.9' ; $SED -n -f script1 lines1 155 mark '1.10' ; $SED -n -f script1 <lines1 156 mark '1.11' ; $SED -n -e 's/^/e1_/p' lines1 157 mark '1.12' 158 if [ $SUN -eq 1 ] ; then 159 echo SunOS sed prints only with -n 160 else 161 $SED -n -e 's/^/e1_/p' <lines1 162 fi 163 mark '1.13' 164 if [ $SUN -eq 1 ] ; then 165 echo SunOS sed prints only with -n 166 else 167 $SED -e 's/^/e1_/p' -e 's/^/e2_/p' lines1 168 fi 169 mark '1.14' 170 if [ $SUN -eq 1 ] ; then 171 echo SunOS sed prints only with -n 172 else 173 $SED -f script1 -f script2 lines1 174 fi 175 mark '1.15' 176 if [ $GNU -eq 1 -o $SUN -eq 1 ] ; then 177 echo GNU and SunOS sed fail this following older POSIX draft 178 else 179 $SED -e 's/^/e1_/p' -f script1 lines1 180 fi 181 mark '1.16' 182 if [ $SUN -eq 1 ] ; then 183 echo SunOS sed prints only with -n 184 else 185 $SED -e 's/^/e1_/p' lines1 lines1 186 fi 187 # POSIX D11.2:11251 188 mark '1.17' ; $SED p <lines1 lines1 189cat >script1 <<EOF 190#n 191# A comment 192 193p 194EOF 195 mark '1.18' ; $SED -f script1 <lines1 lines1 196} 197 198test_addr() 199{ 200 echo Testing address ranges 201 mark '2.1' ; $SED -n -e '4p' lines1 202 mark '2.2' ; $SED -n -e '20p' lines1 lines2 203 mark '2.3' ; $SED -n -e '$p' lines1 204 mark '2.4' ; $SED -n -e '$p' lines1 lines2 205 mark '2.5' ; $SED -n -e '$a\ 206hello' /dev/null 207 mark '2.6' ; $SED -n -e '$p' lines1 /dev/null lines2 208 # Should not print anything 209 mark '2.7' ; $SED -n -e '20p' lines1 210 mark '2.8' ; $SED -n -e '0p' lines1 211 mark '2.9' ; $SED -n '/l1_7/p' lines1 212 mark '2.10' ; $SED -n ' /l1_7/ p' lines1 213 mark '2.11' 214 if [ $BSD -eq 1 ] ; then 215 echo BSD sed fails this test 216 fi 217 if [ $GNU -eq 1 ] ; then 218 echo GNU sed fails this 219 fi 220 $SED -n '\_l1\_7_p' lines1 221 mark '2.12' ; $SED -n '1,4p' lines1 222 mark '2.13' ; $SED -n '1,$p' lines1 lines2 223 mark '2.14' ; $SED -n '1,/l2_9/p' lines1 lines2 224 mark '2.15' ; $SED -n '/4/,$p' lines1 lines2 225 mark '2.16' ; $SED -n '/4/,20p' lines1 lines2 226 mark '2.17' ; $SED -n '/4/,/10/p' lines1 lines2 227 mark '2.18' ; $SED -n '/l2_3/,/l1_8/p' lines1 lines2 228 mark '2.19' 229 if [ $GNU -eq 1 ] ; then 230 echo GNU sed fails this 231 fi 232 $SED -n '12,3p' lines1 lines2 233 mark '2.20' 234 if [ $GNU -eq 1 ] ; then 235 echo GNU sed fails this 236 fi 237 $SED -n '/l1_7/,3p' lines1 lines2 238} 239 240test_group() 241{ 242 echo Brace and other grouping 243 mark '3.1' ; $SED -e ' 2444,12 { 245 s/^/^/ 246 s/$/$/ 247 s/_/T/ 248}' lines1 249 mark '3.2' ; $SED -e ' 2504,12 { 251 s/^/^/ 252 /6/,/10/ { 253 s/$/$/ 254 /8/ s/_/T/ 255 } 256}' lines1 257 mark '3.3' ; $SED -e ' 2584,12 !{ 259 s/^/^/ 260 /6/,/10/ !{ 261 s/$/$/ 262 /8/ !s/_/T/ 263 } 264}' lines1 265 mark '3.4' ; $SED -e '4,12!s/^/^/' lines1 266} 267 268test_acid() 269{ 270 echo Testing a c d and i commands 271 mark '4.1' ; $SED -n -e ' 272s/^/before_i/p 27320i\ 274inserted 275s/^/after_i/p 276' lines1 lines2 277 mark '4.2' ; $SED -n -e ' 2785,12s/^/5-12/ 279s/^/before_a/p 280/5-12/a\ 281appended 282s/^/after_a/p 283' lines1 lines2 284 mark '4.3' 285 if [ $GNU -eq 1 ] ; then 286 echo GNU sed fails this 287 fi 288 $SED -n -e ' 289s/^/^/p 290/l1_/a\ 291appended 2928,10N 293s/$/$/p 294' lines1 lines2 295 mark '4.4' ; $SED -n -e ' 296c\ 297hello 298' lines1 299 mark '4.5' ; $SED -n -e ' 3008c\ 301hello 302' lines1 303 mark '4.6' ; $SED -n -e ' 3043,14c\ 305hello 306' lines1 307# SunOS and GNU sed behave differently. We follow POSIX 308# mark '4.7' ; $SED -n -e ' 309#8,3c\ 310#hello 311#' lines1 312 mark '4.8' ; $SED d <lines1 313} 314 315test_branch() 316{ 317 echo Testing labels and branching 318 mark '5.1' ; $SED -n -e ' 319b label4 320:label3 321s/^/label3_/p 322b end 323:label4 3242,12b label1 325b label2 326:label1 327s/^/label1_/p 328b 329:label2 330s/^/label2_/p 331b label3 332:end 333' lines1 334 mark '5.2' 335 if [ $BSD -eq 1 ] ; then 336 echo BSD sed fails this test 337 fi 338 $SED -n -e ' 339s/l1_/l2_/ 340t ok 341b 342:ok 343s/^/tested /p 344' lines1 lines2 345# SunOS sed behaves differently here. Clarification needed. 346# mark '5.3' ; $SED -n -e ' 347#5,8b inside 348#1,5 { 349# s/^/^/p 350# :inside 351# s/$/$/p 352#} 353#' lines1 354# Check that t clears the substitution done flag 355 mark '5.4' ; $SED -n -e ' 3561,8s/^/^/ 357t l1 358:l1 359t l2 360s/$/$/p 361b 362:l2 363s/^/ERROR/ 364' lines1 365# Check that reading a line clears the substitution done flag 366 mark '5.5' 367 if [ $BSD -eq 1 ] ; then 368 echo BSD sed fails this test 369 fi 370 $SED -n -e ' 371t l2 3721,8s/^/^/p 3732,7N 374b 375:l2 376s/^/ERROR/p 377' lines1 378 mark '5.6' ; $SED 5q lines1 379 mark '5.7' ; $SED -e ' 3805i\ 381hello 3825q' lines1 383# Branch across block boundary 384 mark '5.8' ; $SED -e ' 385{ 386:b 387} 388s/l/m/ 389tb' lines1 390} 391 392test_pattern() 393{ 394echo Pattern space commands 395# Check that the pattern space is deleted 396 mark '6.1' ; $SED -n -e ' 397c\ 398changed 399p 400' lines1 401 mark '6.2' ; $SED -n -e ' 4024d 403p 404' lines1 405# SunOS sed refused to print here 406# mark '6.3' ; $SED -e ' 407#N 408#N 409#N 410#D 411#P 412#4p 413#' lines1 414 mark '6.4' ; $SED -e ' 4152h 4163H 4174g 4185G 4196x 4206p 4216x 4226p 423' lines1 424 mark '6.5' ; $SED -e '4n' lines1 425 mark '6.6' ; $SED -n -e '4n' lines1 426} 427 428test_print() 429{ 430 echo Testing print and file routines 431 awk 'END {for (i = 1; i < 256; i++) printf("%c", i);print "\n"}' \ 432 </dev/null >lines3 433 # GNU and SunOS sed behave differently here 434 mark '7.1'
|
433 if [ $BSD -eq 1 ] ; then 434 echo 'BSD sed drops core on this one; TEST SKIPPED' 435 else 436 $SED -n l lines3 437 fi
| 435 $SED -n l lines3
|
438 mark '7.2' ; $SED -e '/l2_/=' lines1 lines2 439 rm -f lines4 440 mark '7.3' ; $SED -e '3,12w lines4' lines1 441 echo w results 442 cat lines4 443 mark '7.4' ; $SED -e '4r lines2' lines1 444 mark '7.5' ; $SED -e '5r /dev/dds' lines1 445 mark '7.6' ; $SED -e '6r /dev/null' lines1 446 mark '7.7' 447 if [ $BSD -eq 1 -o $GNU -eq 1 -o $SUN -eq 1 ] ; then 448 echo BSD, GNU and SunOS cannot pass this one 449 else 450 sed '200q' $DICT | sed 's$.*$s/^/&/w tmpdir/&$' >script1 451 rm -rf tmpdir 452 mkdir tmpdir 453 $SED -f script1 lines1 454 cat tmpdir/* 455 rm -rf tmpdir 456 fi 457 mark '7.8' 458 if [ $BSD -eq 1 ] ; then 459 echo BSD sed cannot pass 7.7 460 else 461 echo line1 > lines3 462 echo "" >> lines3 463 $SED -n -e '$p' lines3 /dev/null 464 fi 465 466} 467 468test_subst() 469{ 470 echo Testing substitution commands 471 mark '8.1' ; $SED -e 's/./X/g' lines1 472 mark '8.2' ; $SED -e 's,.,X,g' lines1 473# GNU and SunOS sed thinks we are escaping . as wildcard, not as separator 474# mark '8.3' ; $SED -e 's.\..X.g' lines1 475# POSIX does not say that this should work 476# mark '8.4' ; $SED -e 's/[/]/Q/' lines1 477 mark '8.4' ; $SED -e 's/[\/]/Q/' lines1 478 mark '8.5' ; $SED -e 's_\__X_' lines1 479 mark '8.6' ; $SED -e 's/./(&)/g' lines1 480 mark '8.7' ; $SED -e 's/./(\&)/g' lines1 481 mark '8.8' ; $SED -e 's/\(.\)\(.\)\(.\)/x\3x\2x\1/g' lines1 482 mark '8.9' ; $SED -e 's/_/u0\ 483u1\ 484u2/g' lines1 485 mark '8.10' 486 if [ $BSD -eq 1 -o $GNU -eq 1 ] ; then 487 echo 'BSD/GNU sed do not understand digit flags on s commands' 488 fi 489 $SED -e 's/./X/4' lines1 490 rm -f lines4 491 mark '8.11' ; $SED -e 's/1/X/w lines4' lines1 492 echo s wfile results 493 cat lines4 494 mark '8.12' ; $SED -e 's/[123]/X/g' lines1 495 mark '8.13' ; $SED -e 'y/0123456789/9876543210/' lines1 496 mark '8.14' ; 497 if [ $BSD -eq 1 -o $GNU -eq 1 -o $SUN -eq 1 ] ; then 498 echo BSD/GNU/SUN sed fail this test 499 else 500 $SED -e 'y10\123456789198765432\101' lines1 501 fi 502 mark '8.15' ; $SED -e '1N;2y/\n/X/' lines1 503 mark '8.16'
| 436 mark '7.2' ; $SED -e '/l2_/=' lines1 lines2 437 rm -f lines4 438 mark '7.3' ; $SED -e '3,12w lines4' lines1 439 echo w results 440 cat lines4 441 mark '7.4' ; $SED -e '4r lines2' lines1 442 mark '7.5' ; $SED -e '5r /dev/dds' lines1 443 mark '7.6' ; $SED -e '6r /dev/null' lines1 444 mark '7.7' 445 if [ $BSD -eq 1 -o $GNU -eq 1 -o $SUN -eq 1 ] ; then 446 echo BSD, GNU and SunOS cannot pass this one 447 else 448 sed '200q' $DICT | sed 's$.*$s/^/&/w tmpdir/&$' >script1 449 rm -rf tmpdir 450 mkdir tmpdir 451 $SED -f script1 lines1 452 cat tmpdir/* 453 rm -rf tmpdir 454 fi 455 mark '7.8' 456 if [ $BSD -eq 1 ] ; then 457 echo BSD sed cannot pass 7.7 458 else 459 echo line1 > lines3 460 echo "" >> lines3 461 $SED -n -e '$p' lines3 /dev/null 462 fi 463 464} 465 466test_subst() 467{ 468 echo Testing substitution commands 469 mark '8.1' ; $SED -e 's/./X/g' lines1 470 mark '8.2' ; $SED -e 's,.,X,g' lines1 471# GNU and SunOS sed thinks we are escaping . as wildcard, not as separator 472# mark '8.3' ; $SED -e 's.\..X.g' lines1 473# POSIX does not say that this should work 474# mark '8.4' ; $SED -e 's/[/]/Q/' lines1 475 mark '8.4' ; $SED -e 's/[\/]/Q/' lines1 476 mark '8.5' ; $SED -e 's_\__X_' lines1 477 mark '8.6' ; $SED -e 's/./(&)/g' lines1 478 mark '8.7' ; $SED -e 's/./(\&)/g' lines1 479 mark '8.8' ; $SED -e 's/\(.\)\(.\)\(.\)/x\3x\2x\1/g' lines1 480 mark '8.9' ; $SED -e 's/_/u0\ 481u1\ 482u2/g' lines1 483 mark '8.10' 484 if [ $BSD -eq 1 -o $GNU -eq 1 ] ; then 485 echo 'BSD/GNU sed do not understand digit flags on s commands' 486 fi 487 $SED -e 's/./X/4' lines1 488 rm -f lines4 489 mark '8.11' ; $SED -e 's/1/X/w lines4' lines1 490 echo s wfile results 491 cat lines4 492 mark '8.12' ; $SED -e 's/[123]/X/g' lines1 493 mark '8.13' ; $SED -e 'y/0123456789/9876543210/' lines1 494 mark '8.14' ; 495 if [ $BSD -eq 1 -o $GNU -eq 1 -o $SUN -eq 1 ] ; then 496 echo BSD/GNU/SUN sed fail this test 497 else 498 $SED -e 'y10\123456789198765432\101' lines1 499 fi 500 mark '8.15' ; $SED -e '1N;2y/\n/X/' lines1 501 mark '8.16'
|
504 if [ $BSD -eq 1 ] ; then 505 echo 'BSD sed does not handle branch defined REs' 506 else 507 echo 'eeefff' | $SED -e 'p' -e 's/e/X/p' -e ':x' \ 508 -e 's//Y/p' -e '/f/bx' 509 fi
| 502 echo 'eeefff' | $SED -e ' 503 p 504 s/e/X/p 505 :x 506 s//Y/p 507 # Establish limit counter in the hold space 508 # GNU sed version 3.02 enters into an infinite loop here 509 x 510 /.\{10\}/ { 511 s/.*/ERROR/ 512 b 513 } 514 s/.*/&./ 515 x 516 /f/bx 517 '
|
510} 511 512test_error() 513{ 514 exec 0>&3 4>&1 5>&2 515 exec 0</dev/null 516 exec 2>&1 517 set -x 518 $TEST -x && exit 1 519 $TEST -f && exit 1 520 $TEST -e && exit 1 521 $TEST -f /dev/dds && exit 1 522 $TEST p /dev/dds && exit 1 523 $TEST -f /bin/sh && exit 1 524 $TEST '{' && exit 1 525 $TEST '{' && exit 1 526 $TEST '/hello/' && exit 1 527 $TEST '1,/hello/' && exit 1 528 $TEST -e '-5p' && exit 1 529 $TEST '/jj' && exit 1 530 $TEST 'a hello' && exit 1 531 $TEST 'a \ hello' && exit 1 532 $TEST 'b foo' && exit 1 533 $TEST 'd hello' && exit 1 534 $TEST 's/aa' && exit 1 535 $TEST 's/aa/' && exit 1 536 $TEST 's/a/b' && exit 1 537 $TEST 's/a/b/c/d' && exit 1 538 $TEST 's/a/b/ 1 2' && exit 1 539 $TEST 's/a/b/ 1 g' && exit 1 540 $TEST 's/a/b/w' && exit 1 541 $TEST 'y/aa' && exit 1 542 $TEST 'y/aa/b/' && exit 1 543 $TEST 'y/aa/' && exit 1 544 $TEST 'y/a/b' && exit 1 545 $TEST 'y/a/b/c/d' && exit 1 546 $TEST '!' && exit 1 547 $TEST supercalifrangolisticexprialidociussupercalifrangolisticexcius 548 set +x 549 exec 0>&3 1>&4 2>&5 550} 551 552main
| 518} 519 520test_error() 521{ 522 exec 0>&3 4>&1 5>&2 523 exec 0</dev/null 524 exec 2>&1 525 set -x 526 $TEST -x && exit 1 527 $TEST -f && exit 1 528 $TEST -e && exit 1 529 $TEST -f /dev/dds && exit 1 530 $TEST p /dev/dds && exit 1 531 $TEST -f /bin/sh && exit 1 532 $TEST '{' && exit 1 533 $TEST '{' && exit 1 534 $TEST '/hello/' && exit 1 535 $TEST '1,/hello/' && exit 1 536 $TEST -e '-5p' && exit 1 537 $TEST '/jj' && exit 1 538 $TEST 'a hello' && exit 1 539 $TEST 'a \ hello' && exit 1 540 $TEST 'b foo' && exit 1 541 $TEST 'd hello' && exit 1 542 $TEST 's/aa' && exit 1 543 $TEST 's/aa/' && exit 1 544 $TEST 's/a/b' && exit 1 545 $TEST 's/a/b/c/d' && exit 1 546 $TEST 's/a/b/ 1 2' && exit 1 547 $TEST 's/a/b/ 1 g' && exit 1 548 $TEST 's/a/b/w' && exit 1 549 $TEST 'y/aa' && exit 1 550 $TEST 'y/aa/b/' && exit 1 551 $TEST 'y/aa/' && exit 1 552 $TEST 'y/a/b' && exit 1 553 $TEST 'y/a/b/c/d' && exit 1 554 $TEST '!' && exit 1 555 $TEST supercalifrangolisticexprialidociussupercalifrangolisticexcius 556 set +x 557 exec 0>&3 1>&4 2>&5 558} 559 560main
|