
# -------------------------------------------------------------------
# sed Regression Tests
#  Converted to GNO's gsh format from FreeBSD's sed.test (sh format)
#
# The following files are created in /tmp/:
# lines[1-4], script1, script2
# -------------------------------------------------------------------

# Location of sed command to be tested
set SED=/obj/gno/usr.bin/sed/sed

# GNO's rm command is implemented under the cp command
set RM="cp -p rm"

# Use either cmp or diff for comparing files
set compare="cmp"

# Create directory under /tmp to hold results
$RM -rf /tmp/out >& /tmp/err.list
mkdir /tmp/out

echo "l1_1" > /tmp/lines1.0
echo "l1_2" >> /tmp/lines1.0
echo "l1_3" >> /tmp/lines1.0
echo "l1_4" >> /tmp/lines1.0
echo "l1_5" >> /tmp/lines1.0
echo "l1_6" >> /tmp/lines1.0
echo "l1_7" >> /tmp/lines1.0
echo "l1_8" >> /tmp/lines1.0
echo "l1_9" >> /tmp/lines1.0
echo "l1_10" >> /tmp/lines1.0
echo "l1_11" >> /tmp/lines1.0
echo "l1_12" >> /tmp/lines1.0
echo "l1_13" >> /tmp/lines1.0
echo "l1_14" >> /tmp/lines1.0
#  NOTE: gsh's echo appends an extra blank at end-of-line.
#  Use sed to remove it.
$SED -e 's/ $//' /tmp/lines1.0 > /tmp/lines1
$RM -f /tmp/lines1.0

echo "l2_1" > /tmp/lines2.0
echo "l2_2" >> /tmp/lines2.0
echo "l2_3" >> /tmp/lines2.0
echo "l2_4" >> /tmp/lines2.0
echo "l2_5" >> /tmp/lines2.0
echo "l2_6" >> /tmp/lines2.0
echo "l2_7" >> /tmp/lines2.0
echo "l2_8" >> /tmp/lines2.0
echo "l2_9" >> /tmp/lines2.0
$SED -e 's/ $//' /tmp/lines2.0 > /tmp/lines2
$RM -f /tmp/lines2.0

# Create an empty /tmp/null to simulate /dev/null
echo "" | $SED -n > /tmp/null

# #### test_args
set tnum='1.1'
echo "sed test $tnum"
echo "Testing argument parsing"
echo "First type"
$SED 's/^/e1_/p' /tmp/lines1 > /tmp/out/out.$tnum
echo "  Completion status = $status"
echo "Checking results against control file (no differences expected)"
$compare out/out.$tnum /tmp/out/out.$tnum
echo "  $tnum comparison status = $status"
echo ""

set tnum='1.2'
echo "sed test $tnum"
$SED -n 's/^/e1_/p' /tmp/lines1 > /tmp/out/out.$tnum
echo "  Completion status = $status"
echo "Checking results against control file (no differences expected)"
$compare out/out.$tnum /tmp/out/out.$tnum
echo "  $tnum comparison status = $status"
echo ""

set tnum='1.3'
echo "sed test $tnum"
$SED 's/^/e1_/p' </tmp/lines1 > /tmp/out/out.$tnum
echo "  Completion status = $status"
echo "Checking results against control file (no differences expected)"
$compare out/out.$tnum /tmp/out/out.$tnum
echo "  $tnum comparison status = $status"
echo ""

set tnum='1.4'
echo "sed test $tnum"
$SED -n 's/^/e1_/p' </tmp/lines1 > /tmp/out/out.$tnum
echo "  Completion status = $status"
echo "Checking results against control file (no differences expected)"
$compare out/out.$tnum /tmp/out/out.$tnum
echo "  $tnum comparison status = $status"
echo ""

#  echo Second type
#  set tnum='1.4.1'
#  $SED -e '' </tmp/lines1
echo 's/^/s1_/p' >/tmp/script1
echo 's/^/s2_/p' >/tmp/script2
set tnum='1.5'
echo "sed test $tnum"
$SED -f /tmp/script1 /tmp/lines1 > /tmp/out/out.$tnum
echo "  Completion status = $status"
echo "Checking results against control file (no differences expected)"
$compare out/out.$tnum /tmp/out/out.$tnum
echo "  $tnum comparison status = $status"
echo ""

set tnum='1.6'
echo "sed test $tnum"
$SED -f /tmp/script1 </tmp/lines1 > /tmp/out/out.$tnum
echo "  Completion status = $status"
echo "Checking results against control file (no differences expected)"
$compare out/out.$tnum /tmp/out/out.$tnum
echo "  $tnum comparison status = $status"
echo ""

set tnum='1.7'
echo "sed test $tnum"
$SED -e 's/^/e1_/p' /tmp/lines1 > /tmp/out/out.$tnum
echo "  Completion status = $status"
echo "Checking results against control file (no differences expected)"
$compare out/out.$tnum /tmp/out/out.$tnum
echo "  $tnum comparison status = $status"
echo ""

set tnum='1.8'
echo "sed test $tnum"
$SED -e 's/^/e1_/p' </tmp/lines1 > /tmp/out/out.$tnum
echo "  Completion status = $status"
echo "Checking results against control file (no differences expected)"
$compare out/out.$tnum /tmp/out/out.$tnum
echo "  $tnum comparison status = $status"
echo ""

set tnum='1.9'
echo "sed test $tnum"
$SED -n -f /tmp/script1 /tmp/lines1 > /tmp/out/out.$tnum
echo "  Completion status = $status"
echo "Checking results against control file (no differences expected)"
$compare out/out.$tnum /tmp/out/out.$tnum
echo "  $tnum comparison status = $status"
echo ""

set tnum='1.10'
echo "sed test $tnum"
$SED -n -f /tmp/script1 </tmp/lines1 > /tmp/out/out.$tnum
echo "  Completion status = $status"
echo "Checking results against control file (no differences expected)"
$compare out/out.$tnum /tmp/out/out.$tnum
echo "  $tnum comparison status = $status"
echo ""

set tnum='1.11'
echo "sed test $tnum"
$SED -n -e 's/^/e1_/p' /tmp/lines1 > /tmp/out/out.$tnum
echo "  Completion status = $status"
echo "Checking results against control file (no differences expected)"
$compare out/out.$tnum /tmp/out/out.$tnum
echo "  $tnum comparison status = $status"
echo ""

set tnum='1.12'
echo "sed test $tnum"
$SED -n -e 's/^/e1_/p' </tmp/lines1 > /tmp/out/out.$tnum
echo "  Completion status = $status"
echo "Checking results against control file (no differences expected)"
$compare out/out.$tnum /tmp/out/out.$tnum
echo "  $tnum comparison status = $status"
echo ""

set tnum='1.13'
echo "sed test $tnum"
$SED -e 's/^/e1_/p' -e 's/^/e2_/p' /tmp/lines1 > /tmp/out/out.$tnum
echo "  Completion status = $status"
echo "Checking results against control file (no differences expected)"
$compare out/out.$tnum /tmp/out/out.$tnum
echo "  $tnum comparison status = $status"
echo ""

set tnum='1.14'
echo "sed test $tnum"
$SED -f /tmp/script1 -f /tmp/script2 /tmp/lines1 > /tmp/out/out.$tnum
echo "  Completion status = $status"
echo "Checking results against control file (no differences expected)"
$compare out/out.$tnum /tmp/out/out.$tnum
echo "  $tnum comparison status = $status"
echo ""

set tnum='1.15'
echo "sed test $tnum"
$SED -e 's/^/e1_/p' -f /tmp/script1 /tmp/lines1 > /tmp/out/out.$tnum
echo "  Completion status = $status"
echo "Checking results against control file (no differences expected)"
$compare out/out.$tnum /tmp/out/out.$tnum
echo "  $tnum comparison status = $status"
echo ""

set tnum='1.16'
echo "sed test $tnum"
$SED -e 's/^/e1_/p' /tmp/lines1 /tmp/lines1 > /tmp/out/out.$tnum
echo "  Completion status = $status"
echo "Checking results against control file (no differences expected)"
$compare out/out.$tnum /tmp/out/out.$tnum
echo "  $tnum comparison status = $status"
echo ""

# POSIX D11.2:11251
set tnum='1.17'
echo "sed test $tnum"
$SED p </tmp/lines1 /tmp/lines1 > /tmp/out/out.$tnum
echo "  Completion status = $status"
echo "Checking results against control file (no differences expected)"
$compare out/out.$tnum /tmp/out/out.$tnum
echo "  $tnum comparison status = $status"
echo ""

echo '#n'          > /tmp/sed.cmd
echo '# A comment' >> /tmp/sed.cmd
echo ''            >> /tmp/sed.cmd
echo 'p'           >> /tmp/sed.cmd
$SED -e 's/ $//' /tmp/sed.cmd > /tmp/sed.cmd1
set tnum='1.18'
echo "sed test $tnum"
$SED -f /tmp/sed.cmd1 </tmp/lines1 /tmp/lines1 > /tmp/out/out.$tnum
echo "  Completion status = $status"
echo "Checking results against control file (no differences expected)"
$compare out/out.$tnum /tmp/out/out.$tnum
echo "  $tnum comparison status = $status"
echo ""


# #### test_addr
echo "Testing address ranges"
set tnum='2.1'
echo "sed test $tnum"
$SED -n -e '4p' /tmp/lines1 > /tmp/out/out.$tnum
echo "  Completion status = $status"
echo "Checking results against control file (no differences expected)"
$compare out/out.$tnum /tmp/out/out.$tnum
echo "  $tnum comparison status = $status"
echo ""

set tnum='2.2'
echo "sed test $tnum"
$SED -n -e '20p' /tmp/lines1 /tmp/lines2 > /tmp/out/out.$tnum
echo "  Completion status = $status"
echo "Checking results against control file (no differences expected)"
$compare out/out.$tnum /tmp/out/out.$tnum
echo "  $tnum comparison status = $status"
echo ""

set tnum='2.3'
echo "sed test $tnum"
$SED -n -e '$p' /tmp/lines1 > /tmp/out/out.$tnum
echo "  Completion status = $status"
echo "Checking results against control file (no differences expected)"
$compare out/out.$tnum /tmp/out/out.$tnum
echo "  $tnum comparison status = $status"
echo ""

set tnum='2.4'
echo "sed test $tnum"
$SED -n -e '$p' /tmp/lines1 /tmp/lines2 > /tmp/out/out.$tnum
echo "  Completion status = $status"
echo "Checking results against control file (no differences expected)"
$compare out/out.$tnum /tmp/out/out.$tnum
echo "  $tnum comparison status = $status"
echo ""

set tnum='2.5'
echo "sed test $tnum"
echo '$a\\'  > /tmp/sed.cmd
echo 'hello' >> /tmp/sed.cmd
$SED -e 's/ $//' /tmp/sed.cmd > /tmp/sed.cmd1
$SED -n -f /tmp/sed.cmd1 /tmp/null > /tmp/out/out.$tnum
echo "  Completion status = $status"
echo "Checking results against control file (no differences expected)"
$compare /tmp/out/out.$tnum /tmp/null
echo "  $tnum comparison status = $status"
echo ""

set tnum='2.6'
echo "sed test $tnum"
$SED -n -e '$p' /tmp/lines1 /tmp/null /tmp/lines2 > /tmp/out/out.$tnum
echo "  Completion status = $status"
echo "Checking results against control file (no differences expected)"
$compare out/out.$tnum /tmp/out/out.$tnum
echo "  $tnum comparison status = $status"
echo ""

# Should not print anything
set tnum='2.7'
echo "sed test $tnum"
$SED -n -e '20p' /tmp/lines1 > /tmp/out/out.$tnum
echo "  Completion status = $status"
echo "Checking results against control file (no differences expected)"
$compare /tmp/out/out.$tnum /tmp/null
echo "  $tnum comparison status = $status"
echo ""

set tnum='2.8'
echo "sed test $tnum"
$SED -n -e '0p' /tmp/lines1 > /tmp/out/out.$tnum
echo "  Completion status = $status"
echo "Checking results against control file (no differences expected)"
$compare /tmp/out/out.$tnum /tmp/null
echo "  $tnum comparison status = $status"
echo ""

set tnum='2.9'
echo "sed test $tnum"
$SED -n '/l1_7/p' /tmp/lines1 > /tmp/out/out.$tnum
echo "  Completion status = $status"
echo "Checking results against control file (no differences expected)"
$compare out/out.$tnum /tmp/out/out.$tnum
echo "  $tnum comparison status = $status"
echo ""

set tnum='2.10'
echo "sed test $tnum"
$SED -n ' /l1_7/ p' /tmp/lines1 > /tmp/out/out.$tnum
echo "  Completion status = $status"
echo "Checking results against control file (no differences expected)"
$compare out/out.$tnum /tmp/out/out.$tnum
echo "  $tnum comparison status = $status"
echo ""

# NOTE test 2.11 removed. BSD sed fails this test

set tnum='2.12'
echo "sed test $tnum"
$SED -n '1,4p' /tmp/lines1 > /tmp/out/out.$tnum
echo "  Completion status = $status"
echo "Checking results against control file (no differences expected)"
$compare out/out.$tnum /tmp/out/out.$tnum
echo "  $tnum comparison status = $status"
echo ""

set tnum='2.13'
echo "sed test $tnum"
$SED -n '1,$p' /tmp/lines1 /tmp/lines2 > /tmp/out/out.$tnum
echo "  Completion status = $status"
echo "Checking results against control file (no differences expected)"
$compare out/out.$tnum /tmp/out/out.$tnum
echo "  $tnum comparison status = $status"
echo ""

set tnum='2.14'
echo "sed test $tnum"
$SED -n '1,/l2_9/p' /tmp/lines1 /tmp/lines2 > /tmp/out/out.$tnum
echo "  Completion status = $status"
echo "Checking results against control file (no differences expected)"
$compare out/out.$tnum /tmp/out/out.$tnum
echo "  $tnum comparison status = $status"
echo ""

set tnum='2.15'
echo "sed test $tnum"
$SED -n '/4/,$p' /tmp/lines1 /tmp/lines2 > /tmp/out/out.$tnum
echo "  Completion status = $status"
echo "Checking results against control file (no differences expected)"
$compare out/out.$tnum /tmp/out/out.$tnum
echo "  $tnum comparison status = $status"
echo ""

set tnum='2.16'
echo "sed test $tnum"
$SED -n '/4/,20p' /tmp/lines1 /tmp/lines2 > /tmp/out/out.$tnum
echo "  Completion status = $status"
echo "Checking results against control file (no differences expected)"
$compare out/out.$tnum /tmp/out/out.$tnum
echo "  $tnum comparison status = $status"
echo ""

set tnum='2.17'
echo "sed test $tnum"
$SED -n '/4/,/10/p' /tmp/lines1 /tmp/lines2 > /tmp/out/out.$tnum
echo "  Completion status = $status"
echo "Checking results against control file (no differences expected)"
$compare out/out.$tnum /tmp/out/out.$tnum
echo "  $tnum comparison status = $status"
echo ""

set tnum='2.18'
echo "sed test $tnum"
$SED -n '/l2_3/,/l1_8/p' /tmp/lines1 /tmp/lines2 > /tmp/out/out.$tnum
echo "  Completion status = $status"
echo "Checking results against control file (no differences expected)"
$compare out/out.$tnum /tmp/out/out.$tnum
echo "  $tnum comparison status = $status"
echo ""

set tnum='2.19'
echo "sed test $tnum"
$SED -n '12,3p' /tmp/lines1 /tmp/lines2 > /tmp/out/out.$tnum
echo "  Completion status = $status"
echo "Checking results against control file (no differences expected)"
$compare out/out.$tnum /tmp/out/out.$tnum
echo "  $tnum comparison status = $status"
echo ""

set tnum='2.20'
echo "sed test $tnum"
$SED -n '/l1_7/,3p' /tmp/lines1 /tmp/lines2 > /tmp/out/out.$tnum
echo "  Completion status = $status"
echo "Checking results against control file (no differences expected)"
$compare out/out.$tnum /tmp/out/out.$tnum
echo "  $tnum comparison status = $status"
echo ""


echo "Testing commands"

# #### test_group
echo "Brace and other grouping"
set tnum='3.1'
echo "sed test $tnum"
echo '4,12 {'   > /tmp/sed.cmd
echo '	s/^/^/' >> /tmp/sed.cmd
echo '	s/$/$/' >> /tmp/sed.cmd
echo '	s/_/T/' >> /tmp/sed.cmd
echo '}'        >> /tmp/sed.cmd
$SED -e 's/ $//' /tmp/sed.cmd > /tmp/sed.cmd1
$SED -f /tmp/sed.cmd1 /tmp/lines1 > /tmp/out/out.$tnum
echo "  Completion status = $status"
echo "Checking results against control file (no differences expected)"
$compare out/out.$tnum /tmp/out/out.$tnum
echo "  $tnum comparison status = $status"
echo ""

set tnum='3.2'
echo "sed test $tnum"
echo '4,12 {'         > /tmp/sed.cmd
echo '	s/^/^/'       >> /tmp/sed.cmd
echo '	/6/,/10/ {'   >> /tmp/sed.cmd
echo '		s/$/$/'     >> /tmp/sed.cmd
echo '		/8/ s/_/T/' >> /tmp/sed.cmd
echo '	}'            >> /tmp/sed.cmd
echo '}'              >> /tmp/sed.cmd
$SED -e 's/ $//' /tmp/sed.cmd > /tmp/sed.cmd1
$SED -f /tmp/sed.cmd1 /tmp/lines1 > /tmp/out/out.$tnum
echo "  Completion status = $status"
echo "Checking results against control file (no differences expected)"
$compare out/out.$tnum /tmp/out/out.$tnum
echo "  $tnum comparison status = $status"
echo ""

set tnum='3.3'
echo "sed test $tnum"
echo '4,12 !{'         > /tmp/sed.cmd
echo '	s/^/^/'        >> /tmp/sed.cmd
echo '	/6/,/10/ !{'   >> /tmp/sed.cmd
echo '		s/$/$/'      >> /tmp/sed.cmd
echo '		/8/ !s/_/T/' >> /tmp/sed.cmd
echo '	}'             >> /tmp/sed.cmd
echo '}'               >> /tmp/sed.cmd
$SED -e 's/ $//' /tmp/sed.cmd > /tmp/sed.cmd1
$SED -f /tmp/sed.cmd1 /tmp/lines1 > /tmp/out/out.$tnum
echo "  Completion status = $status"
echo "Checking results against control file (no differences expected)"
$compare out/out.$tnum /tmp/out/out.$tnum
echo "  $tnum comparison status = $status"
echo ""

set tnum='3.4'
echo "sed test $tnum"
$SED -e '4,12!s/^/^/' /tmp/lines1 > /tmp/out/out.$tnum
echo "  Completion status = $status"
echo "Checking results against control file (no differences expected)"
$compare out/out.$tnum /tmp/out/out.$tnum
echo "  $tnum comparison status = $status"
echo ""


# #### test_acid
echo "Testing a c d and i commands"
set tnum='4.1'
echo "sed test $tnum"
echo 's/^/before_i/p' > /tmp/sed.cmd
echo '20i\\'          >> /tmp/sed.cmd
echo 'inserted'       >> /tmp/sed.cmd
echo 's/^/after_i/p'  >> /tmp/sed.cmd
echo ''               >> /tmp/sed.cmd
$SED -e 's/ $//' /tmp/sed.cmd > /tmp/sed.cmd1
$SED -n -f /tmp/sed.cmd1 /tmp/lines1 /tmp/lines2 > /tmp/out/out.$tnum
echo "  Completion status = $status"
echo "Checking results against control file (no differences expected)"
$compare out/out.$tnum /tmp/out/out.$tnum
echo "  $tnum comparison status = $status"
echo ""

set tnum='4.2'
echo "sed test $tnum"
echo '5,12s/^/5-12/'  > /tmp/sed.cmd
echo 's/^/before_a/p' >> /tmp/sed.cmd
echo '/5-12/a\\'      >> /tmp/sed.cmd
echo 'appended'       >> /tmp/sed.cmd
echo 's/^/after_a/p'  >> /tmp/sed.cmd
echo ''               >> /tmp/sed.cmd
$SED -e 's/ $//' /tmp/sed.cmd > /tmp/sed.cmd1
$SED -n -f /tmp/sed.cmd1 /tmp/lines1 /tmp/lines2 > /tmp/out/out.$tnum
echo "  Completion status = $status"
echo "Checking results against control file (no differences expected)"
$compare out/out.$tnum /tmp/out/out.$tnum
echo "  $tnum comparison status = $status"
echo ""

set tnum='4.3'
echo "sed test $tnum"
echo 's/^/^/p'  > /tmp/sed.cmd
echo '/l1_/a\\' >> /tmp/sed.cmd
echo 'appended' >> /tmp/sed.cmd
echo '8,10N'    >> /tmp/sed.cmd
echo 's/$/$/p'  >> /tmp/sed.cmd
echo ''         >> /tmp/sed.cmd
$SED -e 's/ $//' /tmp/sed.cmd > /tmp/sed.cmd1
$SED -n -f /tmp/sed.cmd1 /tmp/lines1 /tmp/lines2 > /tmp/out/out.$tnum
echo "  Completion status = $status"
echo "Checking results against control file (no differences expected)"
$compare out/out.$tnum /tmp/out/out.$tnum
echo "  $tnum comparison status = $status"
echo ""

set tnum='4.4'
echo "sed test $tnum"
echo 'c\\'   > /tmp/sed.cmd
echo 'hello' >> /tmp/sed.cmd
echo ''      >> /tmp/sed.cmd
$SED -e 's/ $//' /tmp/sed.cmd > /tmp/sed.cmd1
$SED -n -f /tmp/sed.cmd1 /tmp/lines1 > /tmp/out/out.$tnum
echo "  Completion status = $status"
echo "Checking results against control file (no differences expected)"
$compare out/out.$tnum /tmp/out/out.$tnum
echo "  $tnum comparison status = $status"
echo ""

set tnum='4.5'
echo "sed test $tnum"
echo '8c\\'  > /tmp/sed.cmd
echo 'hello' >> /tmp/sed.cmd
echo ''      >> /tmp/sed.cmd
$SED -e 's/ $//' /tmp/sed.cmd > /tmp/sed.cmd1
$SED -n -f /tmp/sed.cmd1 /tmp/lines1 > /tmp/out/out.$tnum
echo "  Completion status = $status"
echo "Checking results against control file (no differences expected)"
$compare out/out.$tnum /tmp/out/out.$tnum
echo "  $tnum comparison status = $status"
echo ""

set tnum='4.6'
echo "sed test $tnum"
echo '3,14c\\' > /tmp/sed.cmd
echo 'hello'   >> /tmp/sed.cmd
echo ''        >> /tmp/sed.cmd
$SED -e 's/ $//' /tmp/sed.cmd > /tmp/sed.cmd1
$SED -n -f /tmp/sed.cmd1 /tmp/lines1 > /tmp/out/out.$tnum
echo "  Completion status = $status"
echo "Checking results against control file (no differences expected)"
$compare out/out.$tnum /tmp/out/out.$tnum
echo "  $tnum comparison status = $status"
echo ""

set tnum='4.8'
echo "sed test $tnum"
$SED d </tmp/lines1 > /tmp/out/out.$tnum
echo "  Completion status = $status"
echo "Checking results against control file (no differences expected)"
$compare /tmp/out/out.$tnum /tmp/null
echo "  $tnum comparison status = $status"
echo ""


# #### test_branch
echo "Testing labels and branching"
set tnum='5.1'
echo "sed test $tnum"
echo 'b label4'      > /tmp/sed.cmd
echo ':label3'       >> /tmp/sed.cmd
echo 's/^/label3_/p' >> /tmp/sed.cmd
echo 'b end'         >> /tmp/sed.cmd
echo ':label4'       >> /tmp/sed.cmd
echo '2,12b label1'  >> /tmp/sed.cmd
echo 'b label2'      >> /tmp/sed.cmd
echo ':label1'       >> /tmp/sed.cmd
echo 's/^/label1_/p' >> /tmp/sed.cmd
echo 'b'             >> /tmp/sed.cmd
echo ':label2'       >> /tmp/sed.cmd
echo 's/^/label2_/p' >> /tmp/sed.cmd
echo 'b label3'      >> /tmp/sed.cmd
echo ':end'          >> /tmp/sed.cmd
echo ''              >> /tmp/sed.cmd
$SED -e 's/ $//' /tmp/sed.cmd > /tmp/sed.cmd1
$SED -n -f /tmp/sed.cmd1 /tmp/lines1 > /tmp/out/out.$tnum
echo "  Completion status = $status"
echo "Checking results against control file (no differences expected)"
$compare out/out.$tnum /tmp/out/out.$tnum
echo "  $tnum comparison status = $status"
echo ""

# Note: test 5.2 removed. BSD sed fails this test
# Note: test 5.3 removed. SunOS sed behaves differently here.  Clarification needed.
# Check that t clears the substitution done flag
set tnum='5.4'
echo "sed test $tnum"
echo '1,8s/^/^/'  > /tmp/sed.cmd
echo 't l1'       >> /tmp/sed.cmd
echo ':l1'        >> /tmp/sed.cmd
echo 't l2'       >> /tmp/sed.cmd
echo 's/$/$/p'    >> /tmp/sed.cmd
echo 'b'          >> /tmp/sed.cmd
echo ':l2'        >> /tmp/sed.cmd
echo 's/^/ERROR/' >> /tmp/sed.cmd
echo ''           >> /tmp/sed.cmd
$SED -e 's/ $//' /tmp/sed.cmd > /tmp/sed.cmd1
$SED -n -f /tmp/sed.cmd1 /tmp/lines1 > /tmp/out/out.$tnum
echo "  Completion status = $status"
echo "Checking results against control file (no differences expected)"
$compare out/out.$tnum /tmp/out/out.$tnum
echo "  $tnum comparison status = $status"
echo ""

# Check that reading a line clears the substitution done flag
# Note: test 5.5 removed: BSD sed fails this test

set tnum='5.6'
echo "sed test $tnum"
$SED 5q /tmp/lines1 > /tmp/out/out.$tnum
echo "  Completion status = $status"
echo "Checking results against control file (no differences expected)"
$compare out/out.$tnum /tmp/out/out.$tnum
echo "  $tnum comparison status = $status"
echo ""

set tnum='5.7'
echo "sed test $tnum"
echo '5i\\'  > /tmp/sed.cmd
echo 'hello' >> /tmp/sed.cmd
echo '5q'    >> /tmp/sed.cmd
$SED -e 's/ $//' /tmp/sed.cmd > /tmp/sed.cmd1
$SED -n -f /tmp/sed.cmd1 /tmp/lines1 > /tmp/out/out.$tnum
# Branch across block boundary
set tnum='5.8'
echo "sed test $tnum"
echo '{'      > /tmp/sed.cmd
echo ':b'     >> /tmp/sed.cmd
echo '}'      >> /tmp/sed.cmd
echo 's/l/m/' >> /tmp/sed.cmd
echo 'tb'     >> /tmp/sed.cmd
$SED -e 's/ $//' /tmp/sed.cmd > /tmp/sed.cmd1
$SED -n -f /tmp/sed.cmd1 /tmp/lines1 > /tmp/out/out.$tnum
echo "  Completion status = $status"
echo "Checking results against control file (no differences expected)"
$compare /tmp/out/out.$tnum /tmp/null
echo "  $tnum comparison status = $status"
echo ""


# #### test_pattern
echo "Pattern space commands"
# Check that the pattern space is deleted
set tnum='6.1'
echo "sed test $tnum"
echo 'c\\'     > /tmp/sed.cmd
echo 'changed' >> /tmp/sed.cmd
echo 'p'       >> /tmp/sed.cmd
echo ''        >> /tmp/sed.cmd
$SED -e 's/ $//' /tmp/sed.cmd > /tmp/sed.cmd1
$SED -n -f /tmp/sed.cmd1 /tmp/lines1 > /tmp/out/out.$tnum
echo "  Completion status = $status"
echo "Checking results against control file (no differences expected)"
$compare out/out.$tnum /tmp/out/out.$tnum
echo "  $tnum comparison status = $status"
echo ""

set tnum='6.2'
echo "sed test $tnum"
echo '4d' > /tmp/sed.cmd
echo 'p'  >> /tmp/sed.cmd
echo ''   >> /tmp/sed.cmd
$SED -e 's/ $//' /tmp/sed.cmd > /tmp/sed.cmd1
$SED -n -f /tmp/sed.cmd1 /tmp/lines1 > /tmp/out/out.$tnum
echo "  Completion status = $status"
echo "Checking results against control file (no differences expected)"
$compare out/out.$tnum /tmp/out/out.$tnum
echo "  $tnum comparison status = $status"
echo ""

# Note: test 6.3 removed: SunOS sed refused to print here

set tnum='6.4'
echo "sed test $tnum"
echo '2h' > /tmp/sed.cmd
echo '3H' >> /tmp/sed.cmd
echo '4g' >> /tmp/sed.cmd
echo '5G' >> /tmp/sed.cmd
echo '6x' >> /tmp/sed.cmd
echo '6p' >> /tmp/sed.cmd
echo '6x' >> /tmp/sed.cmd
echo '6p' >> /tmp/sed.cmd
echo ''   >> /tmp/sed.cmd
$SED -e 's/ $//' /tmp/sed.cmd > /tmp/sed.cmd1
$SED -n -f /tmp/sed.cmd1 /tmp/lines1 > /tmp/out/out.$tnum
echo "  Completion status = $status"
echo "Checking results against control file (no differences expected)"
$compare out/out.$tnum /tmp/out/out.$tnum
echo "  $tnum comparison status = $status"
echo ""

set tnum='6.5'
echo "sed test $tnum"
$SED -e '4n' /tmp/lines1 > /tmp/out/out.$tnum
echo "  Completion status = $status"
echo "Checking results against control file (no differences expected)"
$compare out/out.$tnum /tmp/out/out.$tnum
echo "  $tnum comparison status = $status"
echo ""

set tnum='6.6'
echo "sed test $tnum"
$SED -n -e '4n' /tmp/lines1 > /tmp/out/out.$tnum
echo "  Completion status = $status"
echo "Checking results against control file (no differences expected)"
$compare /tmp/out/out.$tnum /tmp/null
echo "  $tnum comparison status = $status"
echo ""


# #### test_print
echo "Testing print and file routines"
# GNU and SunOS sed behave differently here
# Note: test 7.1 removed: BSD sed drops core on this one
set tnum='7.2'
echo "sed test $tnum"
$SED -e '/l2_/=' /tmp/lines1 /tmp/lines2 > /tmp/out/out.$tnum
echo "  Completion status = $status"
echo "Checking results against control file (no differences expected)"
$compare out/out.$tnum /tmp/out/out.$tnum
echo "  $tnum comparison status = $status"
echo ""

$RM -f /tmp/lines4 >& /tmp/err.list
set tnum='7.3'
echo "sed test $tnum"
$SED -e '3,12w /tmp/lines4' /tmp/lines1 > /tmp/out/out.$tnum
echo "  Completion status = $status"
cat /tmp/lines4 > /tmp/out/out.$tnum
echo "Checking results against control file (no differences expected)"
$compare out/out.$tnum /tmp/out/out.$tnum
echo "  $tnum comparison status = $status"
echo ""

set tnum='7.4'
echo "sed test $tnum"
$SED -e '4r /tmp/lines2' /tmp/lines1 > /tmp/out/out.$tnum
echo "  Completion status = $status"
echo "Checking results against control file (no differences expected)"
$compare out/out.$tnum /tmp/out/out.$tnum
echo "  $tnum comparison status = $status"
echo ""

# ??? set tnum='7.5'
# ??? $SED -e '5r /dev/dds' /tmp/lines1

set tnum='7.6'
echo "sed test $tnum"
$SED -e '6r /tmp/null' /tmp/lines1 > /tmp/out/out.$tnum
echo "  Completion status = $status"
echo "Checking results against control file (no differences expected)"
$compare out/out.$tnum /tmp/out/out.$tnum
echo "  $tnum comparison status = $status"
echo ""

# Note: sed test 7.7 and 7.8 removed due to non-BSD compatibility

# #### test_subst
echo "Testing substitution commands"
set tnum='8.1'
echo "sed test $tnum"
$SED -e 's/./X/g' /tmp/lines1 > /tmp/out/out.$tnum
echo "  Completion status = $status"
echo "Checking results against control file (no differences expected)"
$compare out/out.$tnum /tmp/out/out.$tnum
echo "  $tnum comparison status = $status"
echo ""

set tnum='8.2'
echo "sed test $tnum"
$SED -e 's,.,X,g' /tmp/lines1 > /tmp/out/out.$tnum
echo "  Completion status = $status"
echo "Checking results against control file (no differences expected)"
$compare out/out.$tnum /tmp/out/out.$tnum
echo "  $tnum comparison status = $status"
echo ""

# Note: test 8.3 removed: GNU and SunOS sed thinks we are escaping . as wildcard, not as separator
# Note: test 8.4: POSIX does not say that this should work
set tnum='8.4'
echo "sed test $tnum"
$SED -e 's/[\/]/Q/' /tmp/lines1 > /tmp/out/out.$tnum
echo "  Completion status = $status"
echo "Checking results against control file (no differences expected)"
$compare out/out.$tnum /tmp/out/out.$tnum
echo "  $tnum comparison status = $status"
echo ""

set tnum='8.5'
echo "sed test $tnum"
$SED -e 's_\__X_' /tmp/lines1 > /tmp/out/out.$tnum
echo "  Completion status = $status"
echo "Checking results against control file (no differences expected)"
$compare out/out.$tnum /tmp/out/out.$tnum
echo "  $tnum comparison status = $status"
echo ""

set tnum='8.6'
echo "sed test $tnum"
$SED -e 's/./(&)/g' /tmp/lines1 > /tmp/out/out.$tnum
echo "  Completion status = $status"
echo "Checking results against control file (no differences expected)"
$compare out/out.$tnum /tmp/out/out.$tnum
echo "  $tnum comparison status = $status"
echo ""

set tnum='8.7'
echo "sed test $tnum"
$SED -e 's/./(\&)/g' /tmp/lines1 > /tmp/out/out.$tnum
echo "  Completion status = $status"
echo "Checking results against control file (no differences expected)"
$compare out/out.$tnum /tmp/out/out.$tnum
echo "  $tnum comparison status = $status"
echo ""

set tnum='8.8'
echo "sed test $tnum"
$SED -e 's/\(.\)\(.\)\(.\)/x\3x\2x\1/g' /tmp/lines1 > /tmp/out/out.$tnum
echo "  Completion status = $status"
echo "Checking results against control file (no differences expected)"
$compare out/out.$tnum /tmp/out/out.$tnum
echo "  $tnum comparison status = $status"
echo ""

set tnum='8.9'
echo "sed test $tnum"
echo 's/_/u0\\' > /tmp/sed.cmd
echo 'u1\\'     >> /tmp/sed.cmd
echo 'u2/g'     >> /tmp/sed.cmd
$SED -e 's/ $//' /tmp/sed.cmd > /tmp/sed.cmd1
$SED -f /tmp/sed.cmd1 /tmp/lines1 > /tmp/out/out.$tnum
echo "  Completion status = $status"
echo "Checking results against control file (no differences expected)"
$compare out/out.$tnum /tmp/out/out.$tnum
echo "  $tnum comparison status = $status"
echo ""

# Note: test 8.10 removed: BSD/GNU sed do not understand digit flags on s commands

set tnum='8.11'
echo "sed test $tnum"
$SED -e 's/1/X/w /tmp/lines4' /tmp/lines1 > /tmp/out/out.$tnum
echo "  Completion status = $status"
cat /tmp/lines4 > /tmp/out/out.$tnum
echo "Checking results against control file (no differences expected)"
$compare out/out.$tnum /tmp/out/out.$tnum
echo "  $tnum comparison status = $status"
echo ""

set tnum='8.12'
echo "sed test $tnum"
$SED -e 's/[123]/X/g' /tmp/lines1 > /tmp/out/out.$tnum
echo "  Completion status = $status"
echo "Checking results against control file (no differences expected)"
$compare out/out.$tnum /tmp/out/out.$tnum
echo "  $tnum comparison status = $status"
echo ""

set tnum='8.13'
echo "sed test $tnum"
$SED -e 'y/0123456789/9876543210/' /tmp/lines1 > /tmp/out/out.$tnum
echo "  Completion status = $status"
echo "Checking results against control file (no differences expected)"
$compare out/out.$tnum /tmp/out/out.$tnum
echo "  $tnum comparison status = $status"
echo ""

# NOTE 8.14 removed: BSD/GNU/SUN sed fail this test

set tnum='8.15'
echo "sed test $tnum"
$SED -e '1N;2y/\n/X/' /tmp/lines1 > /tmp/out/out.$tnum
echo "  Completion status = $status"
echo "Checking results against control file (no differences expected)"
$compare out/out.$tnum /tmp/out/out.$tnum
echo "  $tnum comparison status = $status"
echo ""

# NOTE 8.16 removed: BSD sed does not handle branch defined REs

# -------------------------------------------------------------------

# Tests originally written for tr command; modified to test sed

set src="file1.mixed"
set cmp="file1.UPPER"
set dest="/tmp/$cmp"
echo "Upshifting all characters in $src"
$SED -e's/a/A/g' -e's/b/B/g' -e's/c/C/g' -e's/d/D/g' -e's/e/E/g' -e's/f/F/g' -e's/g/G/g' -e's/h/H/g' -e's/i/I/g' -e's/j/J/g' -e's/k/K/g' -e's/l/L/g' -e's/m/M/g' -e's/n/N/g' -e's/o/O/g' -e's/p/P/g' -e's/q/Q/g' -e's/r/R/g' -e's/s/S/g' -e's/t/T/g' -e's/u/U/g' -e's/v/V/g' -e's/w/W/g' -e's/x/X/g' -e's/y/Y/g' -e's/z/Z/g'  < $src > $dest
echo "  Completion status = $status"
echo "Checking results against control file $cmp (no differences expected)"
$compare $cmp $dest
echo "  comparison status = $status"
echo ""

set cmp="file1.novowel"
set dest="/tmp/$cmp"
echo "Removing lower-case vowels in $src"
$SED -e's/[aeiouy]//g' < $src > $dest
echo "  Completion status = $status"
echo "Checking results against control file $cmp (no differences expected)"
$compare $cmp $dest
echo "  comparison status = $status"
echo ""

set cmp="file1.nolower"
set dest="/tmp/$cmp"
echo "Removing lower-case letters and squeezing spaces in $src"
$SED -e's/[a-z]//g' -e's/  */ /g' < $src > $dest
echo "  Completion status = $status"
echo "Checking results against control file $cmp (no differences expected)"
$compare $cmp $dest
echo "  comparison status = $status"
echo ""


echo "***** Error Messages *****"

set dest="/tmp/err.cond"

echo ""
echo "Expected error: illegal option"
$SED -x $src > $dest
echo "  Error completion status = $status (expected: 1)"

echo ""
set src="badname"
echo "Expected error: $src: no such file or directory"
$SED -f $src > $dest
echo "  Error completion status = $status (expected: 1)"
