1 # common.pm - common test driver code
10 # plan for one expected ok() call per test
12 plan( tests => scalar @{$tests} ) ;
16 # loop over all the tests
18 foreach my $test ( @{$tests} ) {
20 if ( $test->{skip} ) {
21 ok( 1, "SKIPPING $test->{name}" ) ;
25 unless( $obj && $test->{keep_obj} ) {
27 # if there is no kept object, we will constuct one
30 Template::Simple->new(
31 %{ $test->{opts} || {} }
37 # check for expected errors
38 # no errors in new() to catch (yet)
44 # see if we use the test's template or keep the previous one
46 $tmpl = $test->{template} if defined $test->{template} ;
48 # run any setup sub before this test. this can is used to modify the
49 # object for this test (e.g. delete templates from the cache).
51 if( my $pretest = $test->{pretest} ) {
56 # get any existing template object
58 # render the template and catch any fatal errors
61 $obj->render( $tmpl, $test->{data} ) ;
64 #print "ERR $@\n" if $@;
66 # if we had an error and expected it, we pass this test
70 if ( $test->{error} && $@ =~ /$test->{error}/ ) {
72 ok( 1, $test->{name} ) ;
76 print "unexpected error: $@\n" ;
77 ok( 0, $test->{name} ) ;
82 # see if the expansion was what we expected
84 my $ok = ${$rendered} eq $test->{expected} ;
86 # dump any bad expansions
88 print <<ERR unless $ok ;
96 # report success/failure for this test
98 ok( $ok, $test->{name} ) ;