summaryrefslogtreecommitdiff
path: root/tests/tr/build-script
blob: a6df348e409a270cef589802def6de5c576718d7 (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
#!/p/bin/perl

$tr = '../tr +io 5';
$tr = 'tr';
$test = 0;
$failures = 0;
$| = 1;

print ":\nerrors=0\n";

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

    $test++;
    chop;
    $prog = '($input,$flags,$s1,$s2,$expected,$e_ret_code) = ' . $_ . ';';
    eval $prog;
    $in = "t$test.in"; 
    $exp_name = 't' . $test . '.expected'; 
    $out = "t$test.out"; 

    open(IN, ">$in") || die "Couldn't open $in for writing.\n";
    print IN $input;
    close(IN);
    open(EXP, ">$exp_name")
	|| die "Couldn't open $exp_name for writing.\n";
    print EXP $expected;
    close(EXP);
    $arg2 = ($s2 ? "'$s2'" : '');
    $cmd = "$tr $flags \'$s1\' $arg2 < $in > $out";
    print <<EOF ;
$cmd 2> /dev/null
code=\$?
if test \$code != $e_ret_code ; then
  echo Test $test failed: tr 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; fi ;; # equal files
    1) echo Test $test failed: files $out and $exp_name differ 1>&2;
       errors=`expr \$errors + 1` ;;
    2) echo Test $test 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 -gt 0 ; then
  echo Failed \$errors tests. 1>&2
fi
EOF2