summaryrefslogtreecommitdiff
path: root/tests/tr/build-script.pl
blob: 8487cec46fb7e4983000263ff5a63a28f767fc67 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#! @PERL@ -w
require 5.002;
use strict;

my $xx = './tr';
$| = 1;

print <<EOF;
#! /bin/sh
# run-test generated automatically by build-script from test.data.pl
case \$# in
  0) xx='$xx';;
  *) xx="\$1";;
esac
echo=echo
\$echo testing with $xx=\$xx
errors=0
test "\$srcdir" || srcdir=.
test "\$verbose" && \$xx --version 2> /dev/null
EOF


my %seen;

while (<>)
  {
    next if (/^\s*#/);

    chop;
    my ($test_name, $input, $flags, $s1, $s2, $expected, $e_ret_code);
    my $prog =
       '($test_name, $input, $flags, $s1, $s2, $expected, $e_ret_code) = '
       . $_ . ';';
    eval $prog;
    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);
    open(EXP, ">$exp_name") || die "$0: $in: $!\n";
    print EXP $expected;
    close(EXP);
    my $arg2 = ($s2 ? " '$s2'" : '');
    my $err_output = "t$test_name.err";
    my $cmd = "\$xx $flags \'$s1\'$arg2 < \$srcdir/$in > $out 2> $err_output";
    $exp_name = "\$srcdir/$exp_name";
    print <<EOF ;
$cmd
code=\$?
if test \$code != $e_ret_code ; then
  \$echo Test $test_name failed: $xx return code \$code differs from expected value $e_ret_code 1>&2
  errors=`expr \$errors + 1`
else
  cmp $out \$srcdir/$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
test -s $err_output || rm -f $err_output
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