File: testman.pl

package info (click to toggle)
wise 2.4.1-28
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 39,348 kB
  • sloc: ansic: 276,376; makefile: 1,021; perl: 886; lex: 93; yacc: 81; sh: 25
file content (146 lines) | stat: -rwxr-xr-x 2,555 bytes parent folder | download | duplicates (2)
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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
#!/usr/bin/perl

if( $opt eq 'cf' ) {
    $conf = shift;
    $ENV{'WISECONFIGDIR'} = $conf;
}


#
# Reads in test files with test name, do and diff directives for each unit
#

@testarr = &read_all_testset(\*STDIN);
open(RES,">test.results");

$error = &do_all_testset(\@testarr,\*RES,\*STDERR);

if( $error == 1 ) {
    print STDERR "Tests failed\nPLEASE: email ewan birney (birney\@sanger.ac.uk) with the test.results file\n\n";
} else {
    print STDERR "Tests passed\n";
}




sub do_all_testset {
    my $testarr = shift;
    my $results_file = shift;
    my $talk_file = shift;
    my @array;
    my $error = 0;

    @array = @{$testarr};

    foreach $test (@array) {
	if( &do_testset($test,$results_file,$talk_file) == 1 ) {
	    $error = 1;
	}
    }

    return $error;
}

sub do_testset {
    my $test = shift;
    my $result_file = shift;
    my $talk_file = shift;
    my ($name,$do,$diff,$desc);
    my	$error =0;

    $name  = $test->{'name'};
    $do  = $test->{'do'};
    $do = "../bin/$do";
    $diff  = $test->{'diff'};
    $desc  = $test->{'desc'};

    if( $talk_file ) {
	print $talk_file ">>> Doing $name $desc\n>>> Calling [$do]\n";
    }

    if( ($exit = system($do)) != 0 ) {
	print $talk_file ">>> Bad exit status - $exit (system - $!)\n";
	$error =1;
    } else {

	open(DIFF,"diff $diff|");
	while(<DIFF>) {
	    chop;
	    if( /^[><].*wise.*\d/ ) {
		next;
	    }
	    if( /^[><].*\$[nN]ame\$/ ) {
		next;
	    }
	    if( /unreleased/ ) {
		next;
	    }

	    if( /^[<>]/ ) {
		print $result_file "Error in $name: $_\n";
		$error =1;
	    }
	}
    }
	
    if( $talk_file ) {
	if( $error ) {
	    print $talk_file ">>> $name ... Failed\n";
	} else {
	    print $talk_file ">>> $name ... Passed\n";
	}
    }

    return $error;
    
}
    
    

sub read_all_testset {
    my $file = shift;
    my @array;
    my $h;

    while( ($h = &read_testset($file)) ) {
	push(@array,$h);
    }

    return @array;
}

sub read_testset {
    my $file = shift;
    my $hash = {};
    my ($name,$do,$diff,$desc);

    
    while(<$file>) {
	chop;
	/^#/ && next;
	/^\/\// && last;
	/^name\s+(\S+)/ && do { $name = $1; next; };
	/^desc\s+(.*)$/ && do { $desc = $1; next; };
	/^do\s+(.*)$/ && do { $do = $1; next; };
	/^diff\s+(\S+\s+\S+)/ && do { $diff = $1; next; };
	/^\s+$/ && next;
	warn("Could not understand $_");
    }

    if( defined $name && defined $do && defined $diff) {
	$hash->{'name'} = $name;
	$hash->{'do'} = $do;
	$hash->{'diff'} = $diff;
	$hash->{'desc'} = $desc;

	return $hash;
    } else {
	return undef;
    }
}