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