changes
[urisagit/Perl-Docs.git] / t / common.pm
CommitLineData
8ed110f9 1# common.pm - common test driver code
2
3use Test::More ;
4
5sub tester {
6
7 my( $tests ) = @_ ;
8
9use Data::Dumper ;
10
11# plan for one expected ok() call per test
12
13 plan( tests => scalar @{$tests} ) ;
14
15# loop over all the tests
16
17 foreach my $test ( @{$tests} ) {
18
19#print Dumper $test ;
20
21
22 if ( $test->{skip} ) {
23 ok( 1, "SKIPPING $test->{name}" ) ;
24 next ;
25 }
26
27# run any setup sub before this test. this can is used to modify the
28# object for this test (e.g. delete templates from the cache).
29
30 if( my $pretest = $test->{pretest} ) {
31
32 $pretest->($test) ;
33 }
34
35 my $sub = $test->{sub} ;
36 my $args = $test->{args} ;
37
38 my $result = eval {
39 $sub->( @{$args} ) ;
40 } ;
41
42# if we had an error and expected it, we pass this test
43
44 if ( $@ ) {
45
46 if ( $test->{error} && $@ =~ /$test->{error}/ ) {
47
48 ok( 1, $test->{name} ) ;
49 }
50 else {
51
52 print "unexpected error: $@\n" ;
53 ok( 0, $test->{name} ) ;
54 }
55 }
56
57 if( my $posttest = $test->{posttest} ) {
58
59 $posttest->($test) ;
60 }
61 }
62}
63
641 ;