Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Test::Class for Test::Builder 1.5 #2

Merged
merged 3 commits into from Apr 12, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
21 changes: 15 additions & 6 deletions lib/Test/Class.pm
Expand Up @@ -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 {
Expand Down Expand Up @@ -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 );
};

Expand Down
6 changes: 3 additions & 3 deletions t/skip1.t
Expand Up @@ -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";
};
68 changes: 36 additions & 32 deletions t/skip2.t
Expand Up @@ -3,47 +3,51 @@
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;
$self->builder->ok(1==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=<DATA>; 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;
}
2 changes: 2 additions & 0 deletions t/skip_class_reason.t
Expand Up @@ -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=<DATA>; chomp($expected);
ok($actual, $expected);
};
Expand Down