# Tests for cut command; invoked by command file "fulltests"
#   Written by Dave Tribby (August 1997)
#   $Id: dotests,v 1.2 1997/10/03 04:06:34 gdr Exp $

# You can generate a set of test files with the following:
#     ll /bin > cut.f1.columns
#     tr ' ' '\t' < cut.f1.columns | tr -s '\t' > cut.f1.tab
#     tr '\t' ';' < cut.f1.tab > cut.f1.semi

# Location of the cut command to be tested
set testcmd="../cut"

# Record starting time
echo -n "Testing command $testcmd beginning at"
date

set src="cut.f1.column"
set cmp="cut.f1.colcmp"
set dest="/tmp/$cmp"
echo "Cutting columns from $src"
$testcmd -c 14-17,41- $src > $dest
echo "  Completion status = $status"
echo "Checking results against control file $cmp (no differences expected)"
cmp $cmp $dest
echo "  Completion status = $status"
echo ""

set cmp="${cmp}A"
set dest="/tmp/$cmp"
echo "Cutting columns from $src using stdin"
$testcmd -c 14-17,41- < $src > $dest
echo "  Completion status = $status"
echo "Checking results against control file $cmp (no differences expected)"
cmp $cmp $dest
echo "  Completion status = $status"
echo ""

set src="cut.f1.tab"
set cmp="cut.f1.tabcmp"
set dest="/tmp/$cmp"
echo "Cutting tab-delimited fields from $src"
$testcmd -f 3,8 $src > $dest
echo "  Completion status = $status"
echo "Checking results against control file $cmp (no differences expected)"
cmp $cmp $dest
echo "  Completion status = $status"
echo ""

set src="cut.f1.semi"
set cmp="cut.f1.semcmp"
set dest="/tmp/$cmp"
echo "Cutting semicolon-delimited fields from $src"
$testcmd -d ';' -f 3,8 $src > $dest
echo "  Completion status = $status"
echo "Checking results against control file $cmp (no differences expected)"
cmp $cmp $dest
echo "  Completion status = $status"
echo ""

set cmp="${cmp}A"
set dest="/tmp/$cmp"
echo "Cutting semicolon-delimited fields from $src, supressing extra lines"
$testcmd -d ';' -f 3,8 -s $src > $dest
echo "  Completion status = $status"
echo "Checking results against control file $cmp (no differences expected)"
cmp $cmp $dest
echo "  Completion status = $status"
echo ""


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

set dest="/tmp/err.cond"

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

echo ""
echo "Expected error: values may not include zero:"
$testcmd -f 0,1,2 $src > $dest
echo "  Error completion status = $status (expected: 1)"

echo ""
echo "Expected error: values may not include zero:"
$testcmd -c 0-5 $src > $dest
echo "  Error completion status = $status (expected: 1)"

echo ""
echo "Expected error: <number> too large (max <max_value>)"
$testcmd -c 2000-32767 $src > $dest
echo "  Error completion status = $status (expected: 1)"

echo ""
echo "Expected error: <number> too large (max <max_value>)"
$testcmd -f 300000 $src > $dest
echo "  Error completion status = $status (expected: 1)"

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