]> mj.ucw.cz Git - libucw.git/blob - build/tester
Fixed a typo preventing compilation in non-threaded mode.
[libucw.git] / build / tester
1 #!/usr/bin/perl
2 # A simple unit testing script
3 # (c) 2004 Martin Mares <mj@ucw.cz>
4
5 my @tests = ();
6 my $tt;
7 my $append_to;
8
9 while (<>) {
10         /^#/ && next;
11         if (/^\s*$/) {
12                 $tt = undef;
13                 $append_to = undef;
14         } elsif (defined($append_to) && /^\s+(.*)$/) {
15                 $$append_to .= "\n$1";
16         } elsif (my ($n,$v) = /^(\w+):\s+(.*)$/) {
17                 if (!$tt) {
18                         $tt = {};
19                         push @tests, $tt;
20                 }
21                 ($tt->{$n}) && die "$n already defined";
22                 $tt->{$n} = $v;
23                 $append_to = \($tt->{$n});
24         } else {
25                 die "Test script syntax error";
26         }
27 }
28
29 my $i = 0;
30 my $errors = 0;
31 my $prev_run = undef;
32 foreach $tt (@tests) {
33         $i++;
34         print "Test $i: ";
35         $run = ($tt->{'Run'} || $prev_run) or die "Don't know what to run";
36         $prev_run = $run;
37         my ($ifi, $ofi);
38         if (defined $tt->{'In'}) {
39                 $ifi = "run/tmp/test$i.in";
40                 open X, ">$ifi" or die "Unable to create $ifi";
41                 print X $tt->{'In'}, "\n";
42                 close X;
43                 $run .= " <$ifi";
44         } else {
45                 $run .= " </dev/null";
46         }
47         if (defined $tt->{'Out'}) {
48                 $ofi = "run/tmp/test$i.out";
49                 unlink $ofi;
50                 $run .= " >$ofi";
51         } else {
52                 $run .= " >/dev/null";
53         }
54         `$run`;
55         if ($?) {
56                 print "FAILED with exit code $?\n";
57                 $errors++;
58                 next;
59         }
60         if (defined $tt->{'Out'}) {
61                 open X, "<$ofi" or die "Unable to read $ofi";
62                 my $out;
63                 {
64                         local $/ = undef;
65                         $out = <X>;
66                 }
67                 close X;
68                 if ($out ne $tt->{'Out'} . "\n") {
69                         print "FAILED (see $ofi)\n";
70                         $errors++;
71                         next;
72                 }
73         }
74         unlink $ifi if $ifi;
75         unlink $ofi if $ofi;
76         print "OK\n";
77 }
78
79 exit !!$errors;