Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make the TestResult and TestSet able to determine if they're passing. Add a default version to the TestSet of 12.
- Loading branch information
Showing
6 changed files
with
165 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
#!/usr/bin/perl | ||
|
||
use strict; | ||
use warnings; | ||
|
||
use TAP::Spec::Parser; | ||
use YAML::Any qw(LoadFile); | ||
use Path::Class; | ||
use Carp; | ||
|
||
use Test::More; | ||
|
||
for my $file ( dir("t/spec-tests")->children ) { | ||
next unless $file =~ m{\.ya?ml}; | ||
|
||
my @yaml = LoadFile($file); | ||
|
||
for my $num (0..$#yaml) { | ||
my $test = $yaml[$num]; | ||
|
||
my $name = $test->{name} || sprintf "Test #%d from %s", $num, $file; | ||
note $name; | ||
|
||
my $tap = $test->{tap} || croak "Test has no tap"; | ||
my $want = $test->{want} || croak "Test has no want"; | ||
|
||
my $result = TAP::Spec::Parser->parse_from_string($tap); | ||
ok $result, "Got a result" or next; | ||
|
||
my $have = result2have($result); | ||
is_deeply $have, $want, $name or diag explain $have; | ||
} | ||
} | ||
|
||
done_testing; | ||
|
||
|
||
sub result2have { | ||
my $result = shift; | ||
my %have; | ||
|
||
$have{passed} = $result->passed; | ||
$have{version} = $result->version; | ||
|
||
if( my $plan = $result->plan ) { | ||
$have{has_plan} = 1; | ||
$have{planned_tests} = $plan->number_of_tests; | ||
} | ||
|
||
for my $line ( @{ $result->body->lines } ) { | ||
push @{$have{tests}}, line2have($line); | ||
} | ||
|
||
return \%have; | ||
} | ||
|
||
|
||
sub line2have { | ||
my $line = shift; | ||
my %have; | ||
|
||
my %fields = ( | ||
description => "description", | ||
number => "number", | ||
status => "status", | ||
passed => "passed", | ||
); | ||
|
||
for my $field (keys %fields) { | ||
my $value = eval { $line->$field() }; | ||
$have{$field} = $value if defined $value; | ||
} | ||
|
||
return \%have; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
--- | ||
name: Basic failing test | ||
tap: | | ||
1..1 | ||
not ok 1 | ||
want: | ||
passed: false | ||
has_plan: true | ||
planned_tests: 1 | ||
version: 12 | ||
tests: | ||
- number: 1 | ||
status: not ok | ||
passed: false | ||
... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
--- | ||
name: Basic passing test | ||
tap: | | ||
1..1 | ||
ok 1 | ||
want: | ||
passed: true | ||
has_plan: true | ||
planned_tests: 1 | ||
version: 12 | ||
tests: | ||
- number: 1 | ||
status: ok | ||
passed: true | ||
... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
--- | ||
name: TAP version | ||
tap: | | ||
TAP version 13 | ||
1..1 | ||
ok 1 | ||
want: | ||
passed: true | ||
has_plan: true | ||
planned_tests: 1 | ||
version: 13 | ||
tests: | ||
- number: 1 | ||
status: ok | ||
passed: true | ||
... | ||
|