Skip to content

Commit

Permalink
First pass at the TB1 TAP formatter.
Browse files Browse the repository at this point in the history
* Make the ending commentary dynamic in TAP::Base.
* Make the directive label dynamic.

The exit code commentary is still in Test::Builder, not in the formatter.  I don't think
that's critical, I doubt most tests were relying on that.

For #215
  • Loading branch information
schwern committed Nov 30, 2011
1 parent 81a9fed commit c911851
Show file tree
Hide file tree
Showing 2 changed files with 86 additions and 7 deletions.
52 changes: 45 additions & 7 deletions lib/TB2/Formatter/TAP/Base.pm
Expand Up @@ -290,6 +290,32 @@ sub _output_plan {
}


has 'diag_tests_but_no_plan' =>
is => 'ro',
isa => 'Str',
default => "%d %s ran, but no plan was declared.";

has 'diag_skipped_with_tests' =>
is => 'ro',
isa => 'Str',
default => "The test was skipped, but %d %s ran.";

has 'diag_wrong_number_of_tests' =>
is => 'ro',
isa => 'Str',
default => "%d %s planned, but %d ran.";

has 'diag_tests_failed' =>
is => 'ro',
isa => 'Str',
default => "%d %s of %d failed.";

has 'diag_no_tests' =>
is => 'ro',
isa => 'Str',
default => "No tests run!";


my %inflections = (
test => "tests",
was => "were"
Expand Down Expand Up @@ -326,7 +352,7 @@ sub output_ending_commentary {
if( !$plan ) {
# Ran tests but never declared a plan
if( $tests_run ) {
$self->diag("$tests_run $w_test ran, but no plan was declared.");
$self->diag( sprintf $self->diag_tests_but_no_plan, $tests_run, $w_test );
}
# No plan is ok if nothing happened
else {
Expand All @@ -339,7 +365,7 @@ sub output_ending_commentary {
if( $plan && $plan->skip ) {
# It was supposed to be a skip, but tests were run
if( $tests_run ) {
$self->diag("The test was skipped, but $tests_run $w_test ran.");
$self->diag( sprintf $self->diag_skipped_with_tests, $tests_run, $w_test );
}
# A proper skip
else {
Expand All @@ -349,22 +375,24 @@ sub output_ending_commentary {

# Saw a plan, but no tests.
if( !$tests_run ) {
$self->diag("No tests run!");
$self->diag( $self->diag_no_tests );
return;
}


# Saw a plan, and tests, but not the right amount.
if( $plan && $tests_planned && $tests_extra ) {
my $w_tests_p = _inflect("test", $tests_planned);
$self->diag("$tests_planned $w_tests_p planned, but $tests_run ran.");
$self->diag(
sprintf $self->diag_wrong_number_of_tests, $tests_planned, $w_tests_p, $tests_run
);
}


# Right amount, but some failed.
if( $tests_failed ) {
my $w_tests_f = _inflect("test", $tests_failed);
$self->diag("$tests_failed $w_tests_f of $tests_run failed.");
$self->diag( sprintf $self->diag_tests_failed, $tests_failed, $w_tests_f, $tests_run );
}

return;
Expand All @@ -384,6 +412,16 @@ has seen_results =>
default => 0
;

has 'directive_display' =>
is => 'ro',
isa => 'HashRef',
default => sub {
return {
skip => 'SKIP',
todo => 'TODO'
}
};

sub handle_result {
my $self = shift;
my $result = shift;
Expand All @@ -408,8 +446,8 @@ sub handle_result {
$self->_escape(\$reason);

my @directives;
push @directives, "TODO" if $result->is_todo;
push @directives, "SKIP" if $result->is_skip;
push @directives, $self->directive_display->{todo} if $result->is_todo;
push @directives, $self->directive_display->{skip} if $result->is_skip;

$out .= " # @{[ join ' ', @directives ]} $reason" if @directives;
$out .= "\n";
Expand Down
41 changes: 41 additions & 0 deletions lib/TB2/Formatter/TAP/TB1.pm
@@ -0,0 +1,41 @@
package TB2::Formatter::TAP::TB1;

use TB2::Mouse;
extends 'TB2::Formatter::TAP::v12';

=head1 NAME
TB2::Formatter::TAP::TB1 - TAP formatter for compatibily with 0.98
=head1 DESCRIPTION
This is a TAP formatter specifically designed to emulate the quirks of
Test::Builder 0.98, the last stable release of Test::Builder before
the TB2 architecture. This is intended to provide Test module authors
with a smooth transition between 0.98 and 1.5.
=cut

# It was "# skip" but "# TODO"
has '+directive_display' =>
default => sub {
return {
skip => 'skip',
todo => 'TODO'
}
};

# Messages output as part of the ending commentary
has '+diag_tests_but_no_plan' =>
default => "Tests were run but no plan was declared and done_testing() was not seen.";

has '+diag_wrong_number_of_tests' =>
default => "Looks like you planned %d %s but ran %d.";

has '+diag_tests_failed' =>
default => "Looks like you failed %d %s of %d run.";

has '+diag_no_tests' =>
default => "No tests run!";

1;

0 comments on commit c911851

Please sign in to comment.