1 # driver.pm - common test driver code
6 *CORE::GLOBAL::syswrite =
7 sub(*\$$;$) { my( $h, $b, $s ) = @_; CORE::syswrite $h, $b, $s } ;
9 *CORE::GLOBAL::sysread =
10 sub(*\$$;$) { my( $h, $b, $s ) = @_; CORE::sysread $h, $b, $s } ;
12 *CORE::GLOBAL::rename =
13 sub($$) { my( $old, $new ) = @_; CORE::rename $old, $new } ;
15 *CORE::GLOBAL::sysopen =
16 sub(*$$;$) { my( $h, $n, $m, $p ) = @_; CORE::sysopen $h, $n, $m, $p } ;
25 # plan for one expected ok() call per test
27 plan( tests => scalar @{$tests} ) ;
29 # loop over all the tests
31 foreach my $test ( @{$tests} ) {
35 if ( $test->{skip} ) {
36 ok( 1, "SKIPPING $test->{name}" ) ;
40 my $override = $test->{override} ;
42 # run any setup sub before this test. this can is used to modify the
43 # object for this test or create test files and data.
45 if( my $pretest = $test->{pretest} ) {
50 if( my $sub = $test->{sub} ) {
52 my $args = $test->{args} ;
55 local *{"CORE::GLOBAL::$override"} = sub {}
58 $test->{result} = eval { $sub->( @{$args} ) } ;
62 # if we had an error and expected it, we pass this test
64 if ( $test->{error} &&
65 $@ =~ /$test->{error}/ ) {
70 print "unexpected error: $@\n" ;
76 if( my $posttest = $test->{posttest} ) {
81 ok( $test->{ok}, $test->{name} ) if exists $test->{ok} ;
82 is( $test->{result}, $test->{expected}, $test->{name} ) if
83 exists $test->{expected} ;