xref: /freebsd/usr.bin/sed/tests/regress.sh (revision 6ba2210ee039f2f12878c217bcf058e9c8b26b29)
1# $FreeBSD$
2
3REGRESSION_START($1)
4
5echo '1..26'
6
7REGRESSION_TEST(`G', `sed G <${SRCDIR}/regress.in')
8REGRESSION_TEST(`P', `sed P <${SRCDIR}/regress.in')
9REGRESSION_TEST(`psl', `sed \$!g\;P\;D <${SRCDIR}/regress.in')
10REGRESSION_TEST(`bcb', `sed s/X/$(jot -n -bx -s "" 2043)\\\\zz/ <${SRCDIR}/regress.in')
11REGRESSION_TEST(`y', `echo -n foo | sed y/o/O/')
12REGRESSION_TEST(`sg', `echo foo | sed s/,*/,/g')
13REGRESSION_TEST(`s3', `echo foo | sed s/,*/,/3')
14REGRESSION_TEST(`s4', `echo foo | sed s/,*/,/4')
15REGRESSION_TEST(`s5', `echo foo | sed s/,*/,/5')
16REGRESSION_TEST(`c0', `sed ''`c\
17foo
18''`<${SRCDIR}/regress.in')
19REGRESSION_TEST(`c1', `sed ''`4,$c\
20foo
21''`<${SRCDIR}/regress.in')
22REGRESSION_TEST(`c2', `sed ''`3,9c\
23foo
24''`<${SRCDIR}/regress.in')
25REGRESSION_TEST(`c3', `sed ''`3,/no such string/c\
26foo
27''`<${SRCDIR}/regress.in')
28REGRESSION_TEST(`b2a', `sed ''`2,3b
291,2d''` <${SRCDIR}/regress.in')
30
31`
32inplace_test()
33{
34	expr="$1"
35	rc=0
36	ns=$(jot 5)
37	ins= outs= _ins=
38	for n in $ns; do
39		jot -w "l${n}_%d" 9 | tee lines.in.$n lines._in.$n | \
40		    sed "$expr" > lines.out.$n
41		ins="$ins lines.in.$n"
42		outs="$outs lines.out.$n"
43		_ins="$_ins lines._in.$n"
44	done
45	sed "$expr" $_ins > lines.out
46
47	sed -i "" "$expr" $ins
48	sed -I "" "$expr" $_ins
49
50	for n in $ns; do
51		diff -u lines.out.$n lines.in.$n || rc=1
52	done
53	cat $_ins | diff -u lines.out - || rc=1
54	rm -f $ins $outs $_ins lines.out
55
56	return $rc
57}
58'
59
60REGRESSION_TEST_FREEFORM(`inplace1', `inplace_test 3,6d')
61REGRESSION_TEST_FREEFORM(`inplace2', `inplace_test 8,30d')
62REGRESSION_TEST_FREEFORM(`inplace3', `inplace_test 20,99d')
63REGRESSION_TEST_FREEFORM(`inplace4', `inplace_test "{;{;8,30d;};}"')
64REGRESSION_TEST_FREEFORM(`inplace5', `inplace_test "3x;6G"')
65
66REGRESSION_TEST(`icase1', `sed /SED/Id <${SRCDIR}/regress.in')
67REGRESSION_TEST(`icase2', `sed s/SED/Foo/I <${SRCDIR}/regress.in')
68REGRESSION_TEST(`icase3', `sed s/SED/Foo/ <${SRCDIR}/regress.in')
69REGRESSION_TEST(`icase4', `sed s/SED/Foo/i <${SRCDIR}/regress.in')
70
71REGRESSION_TEST(`hanoi', `echo ":abcd: : :" | sed -f ${SRCDIR}/hanoi.sed')
72REGRESSION_TEST(`math', `echo "4+7*3+2^7/3" | sed -f ${SRCDIR}/math.sed')
73REGRESSION_TEST(`not', `echo foo | sed "1!!s/foo/bar/"')
74
75REGRESSION_END()
76