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

Process raw TAP output from STDIN #83

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions bin/prove
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,16 @@ file, you can add them to your tests by using a '-':

See the C<README> in the C<examples> directory of this distribution.

If you have raw TAP output (matching C<qr/\d\.\.\d/>) in a file, you
can likewise add them to your tests by using a '-':

prove - < my_raw_tap_output.txt

Or from a command:

ruby test.rb | prove -


=head2 Default Test Directory

If no files or directories are supplied, C<prove> looks for all files
Expand Down
28 changes: 26 additions & 2 deletions lib/App/Prove/State.pm
Original file line number Diff line number Diff line change
Expand Up @@ -388,8 +388,32 @@ sub _get_raw_tests {

for my $arg (@argv) {
if ( '-' eq $arg ) {
push @argv => <STDIN>;
chomp(@argv);
local $/;
my $in = <STDIN>;
if ($in =~ /
\A # Beginning of first line
TAP\s+version\s+\d+ # TAP version line
|
^ # Beginning of any line
\s* # Indented subtests
(?:
[#] # A comment
|
(?:
1\.\.\d | # A plan line
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that should be \d+, otherwise it would fail to match 1..10

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code is only as good as tests. Good catch.

ok | # A test line - pass
not\s+ok # A test line - fail
)
\b # End of word or number
(?!\S) # Space if anything else on line
)
/xm) {
# Raw TAP output.
push @tests => [$in, '*STDIN'];
} else {
# List of tests.
push @argv => split /\n/, $in;
}
next;
}

Expand Down
95 changes: 95 additions & 0 deletions t/prove.t
Original file line number Diff line number Diff line change
Expand Up @@ -1458,6 +1458,98 @@ BEGIN { # START PLAN
# ],
# },


# STDIN
{ name => 'STDIN (file names)',
stdin => "uno\ndos\ntres\n",
args => {
argv => ['-'],
},
expect => {
argv => ['-'],
},
runlog => [
[ '_runtests',
{ verbosity => 0, show_count => 1 },
'uno', 'dos', 'tres'
]
],
},
(map +{
name => "STDIN (file - $_)",
stdin => "$_\ndos\ntres\n",
args => {
argv => ['-'],
},
expect => {
argv => ['-'],
},
runlog => [
[ '_runtests',
{ verbosity => 0, show_count => 1 },
$_, 'dos', 'tres',
]
],
} => split /\n/, <<'FILES'
1..2.t
1..2a
ok.t
okay
OK
not ok.t
not oklahoma
NOT OK
FILES
),
(map +{
name => "STDIN (TAP - $_)",
stdin => "\n$_\n",
args => {
argv => ['-'],
},
expect => {
argv => ['-'],
},
runlog => [
[ '_runtests',
{ verbosity => 0, show_count => 1 },
["\n$_\n", '*STDIN'],
]
],
} => split /\n/, <<'TAP'
1..4
1..4 # Skipped: Win32 not supported
ok
ok 2
not ok
not ok 3
# comment
1..4
1..4 # Skipped: Win32 not supported
ok
ok 2
not ok
not ok 3
# comment
TAP
),
{
name => "STDIN (TAP - TAP version 13)",
stdin => "TAP version 13\n",
args => {
argv => ['-'],
},
expect => {
argv => ['-'],
},
runlog => [
[ '_runtests',
{ verbosity => 0, show_count => 1 },
["TAP version 13\n", '*STDIN'],
]
],
},

);

# END SCHEDULE
Expand Down Expand Up @@ -1536,6 +1628,9 @@ for my $test (@SCHEDULE) {
}

if ( my $runlog = $test->{runlog} ) {
local *STDIN;
open STDIN, '<', \$test->{stdin} or die "No open STDIN: $!"
if $test->{stdin};
eval { $app->run };
if ( my $err_pattern = $test->{run_error} ) {
like $@, $err_pattern, "$name: expected error OK";
Expand Down