1 # common.pm - common test driver code
12 # plan for one expected ok() call per test
14 plan( tests => scalar @{$tests} * 2 ) ;
18 # loop over all the tests
20 foreach my $compiled ( 0, 1 ) {
22 foreach my $test ( @{$tests} ) {
24 $test->{name} .= ' - compiled' if $compiled ;
26 if ( $test->{skip} ) {
27 ok( 1, "SKIPPING $test->{name}" ) ;
31 if ( $test->{compile_skip} && $compiled ) {
32 ok( 1, "SKIPPING $test->{name}" ) ;
36 unless( $obj && $test->{keep_obj} ) {
38 # if there is no kept object, we will constuct one
41 Template::Simple->new(
42 %{ $test->{opts} || {} }
48 # check for expected errors
49 # no errors in new() to catch (yet)
55 # see if we use the test's template or keep the previous one
57 $tmpl = $test->{template} if defined $test->{template} ;
59 #print "TMPL [$tmpl]\n" ;
60 # run any setup sub before this test. this can is used to modify the
61 # object for this test (e.g. delete templates from the cache).
63 if( my $pretest = $test->{pretest} ) {
67 #print Dumper $obj if $test->{dump} ;
71 my $tmpl_name = 'test' ;
72 $obj->add_templates( {$tmpl_name => $tmpl} ) ;
73 eval { $obj->compile( $tmpl_name ) } ;
76 next if check_error( $test ) ;
79 # get any existing template object
80 # render the template and catch any fatal errors
83 $obj->render( $tmpl, $test->{data} ) ;
86 # if we had an error and expected it, we pass this test
88 next if check_error( $test ) ;
90 if( my $posttest = $test->{posttest} ) {
95 # see if the expansion was what we expected
97 my $ok = ${$rendered} eq $test->{expected} ;
99 # dump any bad renderings
101 print <<ERR unless $ok ;
109 # report success/failure for this test
111 ok( $ok, $test->{name} ) ;
122 if ( $test->{error} && $@ =~ /$test->{error}/ ) {
124 ok( 1, $test->{name} ) ;
128 print "unexpected error: $@\n" ;
129 ok( 0, $test->{name} ) ;