1
0
mirror of git://git.sv.gnu.org/coreutils.git synced 2026-07-26 02:30:35 +02:00
This commit is contained in:
Jim Meyering
1996-09-30 00:24:30 +00:00
parent e666e3459e
commit 78315499ba
3 changed files with 176 additions and 0 deletions
+34
View File
@@ -0,0 +1,34 @@
## Process this file with automake to produce Makefile.in.
AUTOMAKE_OPTIONS = 1.1c
x = cut
t = t1 t2 t3 t4 t5 t6 t7 t8 t9 tA tB tC tD ta tb tc td te tf tg th \
ti tj tk tl tm tn to tp tq tr ts tt tu tv tw tx ty tz
in = $(t:=.in)
exp = $(t:=.exp)
out = $(t:=.out)
err = $(t:=.err)
EXTRA_DIST = build-script.pl Test.pm $x-tests $(in) $(exp)
noinst_SCRIPTS = $x-tests build-script
PERL = @PERL@
editpl = sed -e 's,@''PERL''@,$(PERL),g' -e 's,@''srcdir''@,@srcdir@,g'
TESTS = $x-tests
$x-tests: @MAINT@build-script Test.pm
./build-script ../../src/$x > $@.n
mv $@.n $@
chmod 755 $@
SUFFIXES = .pl
.pl:
rm -f $@ $@.tmp
$(editpl) $< > $@.tmp && chmod +x $@.tmp && mv $@.tmp $@
MAINTAINERCLEANFILES = $x-tests $(in) $(exp)
CLEANFILES = $(out) $(err)
+62
View File
@@ -0,0 +1,62 @@
package Test;
require 5.002;
use strict;
my $nl = "\n";
@Test::t = (
# test input flags expected output expected return code
#
['1', "a:b:c$nl", '-d: -f1,3-', "a:c\n", 0],
['2', "a:b:c\n", '-d: -f1,3-', "a:c\n", 0],
['3', "a:b:c$nl", '-d: -f2-', "b:c\n", 0],
['4', "a:b:c$nl", '-d: -f4', "\n", 0],
['5', "", '-d: -f4', "", 0],
['6', "123$nl", '-c4', "\n", 0],
['7', "123", '-c4', "\n", 0],
['8', "123\n1", '-c4', "\n\n", 0],
['9', "", '-c4', "", 0],
['a', "a:b:c$nl", '-s -d: -f3-', "c\n", 0],
['b', "a:b:c$nl", '-s -d: -f2,3', "b:c\n", 0],
['c', "a:b:c$nl", '-s -d: -f1,3', "a:c\n", 0],
# Trailing colon should not be output
['d', "a:b:c:$nl", '-s -d: -f1,3', "a:c\n", 0],
['e', "a:b:c:$nl", '-s -d: -f3-', "c:\n", 0],
['f', "a:b:c:$nl", '-s -d: -f3-4', "c:\n", 0],
['g', "a:b:c:$nl", '-s -d: -f3,4', "c:\n", 0],
# Make sure -s suppresses non-delimited lines
['h', "abc\n", '-s -d: -f2,3', "", 0],
#
['i', ":::\n", '-d: -f1-3', "::\n", 0],
['j', ":::\n", '-d: -f1-4', ":::\n", 0],
['k', ":::\n", '-d: -f2-3', ":\n", 0],
['l', ":::\n", '-d: -f2-4', "::\n", 0],
['m', ":::\n", '-s -d: -f1-3', "::\n", 0],
['n', ":::\n", '-s -d: -f1-4', ":::\n", 0],
['o', ":::\n", '-s -d: -f2-3', ":\n", 0],
['p', ":::\n", '-s -d: -f2-4', "::\n", 0],
['q', ":::\n:\n", '-s -d: -f2-4', "::\n\n", 0],
['r', ":::\n:1\n", '-s -d: -f2-4', "::\n1\n", 0],
['s', ":::\n:a\n", '-s -d: -f1-4', ":::\n:a\n", 0],
['t', ":::\n:1\n", '-s -d: -f3-', ":\n\n", 0],
# Make sure it handles empty input properly, with and without -s.
['u', "", '-s -f3-', "", 0],
['v', "", '-f3-', "", 0],
# Make sure it handles empty input properly.
['w', "", '-b 1', "", 0],
['x', ":\n", '-s -d: -f2-4', "\n", 0],
# Errors
# -s may be used only with -f
['y', ":\n", '-s -b4', "", 1],
# You must specify bytes or fields (or chars)
['z', ":\n", '', "", 1],
# Empty field list
['A', ":\n", '-f \'\'', "", 1],
# Missing field list
['B', ":\n", '-f', "", 1],
# Empty byte list
['C', ":\n", '-b \'\'', "", 1],
# Missing byte list
['D', ":\n", '-b', "", 1],
);
1;
+80
View File
@@ -0,0 +1,80 @@
#! @PERL@ -w
# -*- perl -*-
# @configure_input@
require 5.002;
BEGIN { push @INC, '@srcdir@' if '@srcdir@' ne '.'; }
use strict;
use Test;
$| = 1;
my $xx = $ARGV[0];
print <<EOF;
#! /bin/sh
# This script was generated automatically by build-script.
case \$# in
0) xx='$xx';;
*) xx="\$1";;
esac
test "\$VERBOSE" && echo=echo || echo=:
\$echo testing program: \$xx
errors=0
test "\$srcdir" || srcdir=.
test "\$VERBOSE" && \$xx --version 2> /dev/null
EOF
my %seen;
my $test_vector;
foreach $test_vector (@Test::t)
{
my ($test_name, $input, $flags, $expected, $e_ret_code)
= @{$test_vector};
die "$0: $.: duplicate test name \`$test_name'\n"
if (defined ($seen{$test_name}));
$seen{$test_name} = 1;
my $in = "t$test_name.in";
my $exp_name = "t$test_name.exp";
my $out = "t$test_name.out";
open (IN, ">$in") || die "$0: $in: $!\n";
print IN $input;
close (IN) || die "$0: $in: $!\n";
open (EXP, ">$exp_name") || die "$0: $exp_name: $!\n";
print EXP $expected;
close (EXP) || die "$0: $exp_name: $!\n";
my $err_output = "t$test_name.err";
my $cmd = "\$xx $flags \$srcdir/$in > $out 2> $err_output";
$exp_name = "\$srcdir/$exp_name";
print <<EOF ;
$cmd 2> /dev/null
code=\$?
if test \$code != $e_ret_code ; then
echo Test $test_name failed: cut return code \$code differs from expected value $e_ret_code 1>&2
errors=`expr \$errors + 1`
else
cmp $out $exp_name
case \$? in
0) if test "\$VERBOSE" ; then echo passed $test_name; fi ;; # equal files
1) echo Test $test_name failed: files $out and $exp_name differ 1>&2;
errors=`expr \$errors + 1` ;;
2) echo Test $test_name may have failed. 1>&2;
echo The command \"cmp $out $exp_name\" failed. 1>&2 ;
errors=`expr \$errors + 1` ;;
esac
fi
EOF
}
print <<EOF2 ;
if test \$errors = 0 ; then
\$echo Passed all tests. 1>&2
else
\$echo Failed \$errors tests. 1>&2
fi
test \$errors = 0 || errors=1
exit \$errors
EOF2