diff --git a/lib/Test/Class.pm b/lib/Test/Class.pm index 40bc80a..a5a7e19 100644 --- a/lib/Test/Class.pm +++ b/lib/Test/Class.pm @@ -230,11 +230,19 @@ sub _has_no_tests { sub _all_ok_from { my ($self, $start_test) = @_; - my $current_test = $Builder->current_test; - return(1) if $start_test == $current_test; - my @results = ($Builder->summary)[$start_test .. $current_test-1]; - foreach my $result (@results) { return(0) unless $result }; - return(1); + + # The Test::Builder 1.5 way to do it + if( $Builder->can("history") ) { + return $Builder->history->can_succeed; + } + # The Test::Builder 0.x way to do it + else { + my $current_test = $Builder->current_test; + return(1) if $start_test == $current_test; + my @results = ($Builder->summary)[$start_test .. $current_test-1]; + foreach my $result (@results) { return(0) unless $result }; + return(1); + } }; sub _exception_failure { @@ -440,7 +448,8 @@ sub FAIL_ALL { my $last_test = _last_test_if_exiting_immediately(); $Builder->expected_tests( $last_test ) unless $Builder->has_plan; $Builder->ok(0, $reason) until $Builder->current_test >= $last_test; - my $num_failed = grep( !$_, $Builder->summary ); + my $num_failed = $Builder->can("history") + ? $Builder->history->fail_count : grep( !$_, $Builder->summary ); exit( $num_failed < 254 ? $num_failed : 254 ); }; diff --git a/t/skip1.t b/t/skip1.t index bab407a..1e43af6 100644 --- a/t/skip1.t +++ b/t/skip1.t @@ -18,9 +18,9 @@ Test::Class->SKIP_ALL("skipping"); END { seek $io, SEEK_SET, 0; print "1..1\n"; - my $output = <$io>; - chomp($output); - my $ok = $output =~ /^1..0 # Skip skipping$/i; + my @output = <$io>; + shift @output if $output[0] =~ /^TAP version \d+/; + my $ok = $output[0] =~ /^1..0 # Skip skipping$/i; print "not " unless $ok; print "ok 1 - SKIP_ALL called skip_all\n"; }; diff --git a/t/skip2.t b/t/skip2.t index 91d5304..704a421 100644 --- a/t/skip2.t +++ b/t/skip2.t @@ -3,15 +3,19 @@ use strict; use warnings; +# Override exit before Test::Class is loaded so the real override +# will be seen later. +BEGIN { + *CORE::GLOBAL::exit = sub (;$) { + return @_ ? CORE::exit($_[0]) : CORE::exit(); + }; +} + package Local::Test; use base qw(Test::Class); -use Test; -use Test::Builder; -use Fcntl; -use IO::File; - -plan tests => 6; +use Test::Builder::Tester tests => 4; +use Test::More; sub _only : Test(setup => 1) { my $self = shift; @@ -19,31 +23,31 @@ sub _only : Test(setup => 1) { $self->SKIP_ALL("skippy"); }; -sub test : Test(3) { die "this should never run!" }; - -my $io = IO::File->new_tmpfile or die "couldn't create tmp file ($!)\n"; -my $Test = Test::Builder->new; -$Test->output($io); -$Test->failure_output($io); - -$ENV{TEST_VERBOSE}=0; -Local::Test->runtests; - -END { - seek $io, SEEK_SET, 0; - while (my $actual = <$io>) { - chomp($actual); - my $expected=; chomp($expected); - ok($actual, $expected); - }; - - ok($?, 0, "exit value okay"); - $?=0; +sub test : Test(3) { + die "this should never run!"; }; -__DATA__ -1..4 -ok 1 - test -ok 2 # skip skippy -ok 3 # skip skippy -ok 4 # skip skippy +test_out("ok 1 - test"); +test_out("ok 2 # skip skippy"); +test_out("ok 3 # skip skippy"); +test_out("ok 4 # skip skippy"); + +{ + # Capture the exit from SKIP_ALL, do the tests on the TAP output, + # and then exit for real to stop Test::Class from continuing. + no warnings 'redefine'; + local *CORE::GLOBAL::exit = sub { + test_test("SKIP_ALL"); + my $exit_status = @_ ? shift : 0; + is $exit_status, 0, "exit ok"; + + # Due to a quirk in Test::Builder::Tester, we're stuck with the + # plan generated by Test::Class (4 tests) + pass("make the plan happy"); + pass("make the plan happy"); + + CORE::exit($exit_status); + }; + + Local::Test->runtests; +} diff --git a/t/skip_class_reason.t b/t/skip_class_reason.t index c576c9e..57c6bd4 100755 --- a/t/skip_class_reason.t +++ b/t/skip_class_reason.t @@ -41,6 +41,8 @@ END { seek $io, SEEK_SET, 0; while (my $actual = <$io>) { chomp($actual); + next if $actual =~ /^TAP version \d+/; + $actual =~ s{# skip\b}{# skip}i; # normalize directives my $expected=; chomp($expected); ok($actual, $expected); };