Skip to content

Commit

Permalink
Fix TAP::Harness choking on single backslashes in descriptions
Browse files Browse the repository at this point in the history
Currently, TAP::Harness assumes backslashes in test descriptions will always be
either doubled, or followed by '#'. Since backslashing every slash produces
altered descriptions, we made Test.pm6 only backslash '#' in descriptions[^1],
but that broke the harness's expectations.

Fix by changing the grammar for description token to accept single slashes too.

Neither v12[^2], v13[^3], or v14 draft [^4] versions of TAP spec say
anything about backslashes or whether they can escape '#' in test
descriptions to prevent it from specifying a TAP directive. So the
correctitude of this commit's behaviour is based on what Perl 5's is doing.

P.S.: I couldn't figure out how to make TAP::Harness keep quiet and not produce
any output, hence such a weird test included in this work.

[1] b183cab
[2] https://testanything.org/tap-specification.html
[3] https://testanything.org/tap-version-13-specification.html
[4] TestAnything/testanything.github.io#36
  • Loading branch information
zoffixznet committed Jan 6, 2017
1 parent 4038c6c commit b120ac4
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/TAP.pm6
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ grammar Grammar {
'1..' <count=.num> <.sp>* [ '#' <.sp>* $<directive>=[:i 'SKIP'] <.alnum>* [ <.sp>+ $<explanation>=[\N*] ]? ]?
}
regex description {
[ <-[\n\#\\]> | \\<[\\#]> ]+ <!after <sp>+>
[ '\\\\' || '\#' || <-[\n#]> ]+ <!after <sp>+>
}
token test {
$<nok>=['not '?] 'ok' [ <.sp> <num> ]? ' -'?
Expand Down
45 changes: 45 additions & 0 deletions t/06-tap-harness/01-desc-backslashes.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
use v6;
use lib <lib>;
use Test;
use TAP:auth<perl>;

plan 8;

constant $TEST_FILE
= 't/06-tap-harness/test-files/01-desc-backslashes--1.TAP-TEST';

# stupid hack to avoid TAP::Harness's output from interfering with our tests
# I can't find docs for it to know how to do this properly; so run it as
# as a separate script, make it do tests, then test that output with like()
given run :out, :err, $*EXECUTABLE, '-e',
use lib <lib>;
use Test;
use TAP:auth<perl>;
plan 8;
my $h = TAP::Harness.new;
my $w = $h.run(' ~ $TEST_FILE ~ ').waiter;
await $w;
given $w.result {
is .tests-planned, 12, 'HTEST1 planned';
is .passed, 12, 'HTEST2 passed';
is .failed, 0, 'HTEST3 failed';
is .errors, 0, 'HTEST4 errors';
is .skipped, 1, 'HTEST5 skipped';
is .todo, 0, 'HTEST6 todo';
is .todo-passed, 0, 'HTEST7 todo passed';
is .exit-failed, False, 'HTEST8 exit failed';
}
{
given .err.slurp-rest { when :so { diag "STDERR output was ```$_```" } }

like $output, /^^ 'ok' \N+ 'HTEST1'/, 'planned';
like $output, /^^ 'ok' \N+ 'HTEST2'/, 'passed';
like $output, /^^ 'ok' \N+ 'HTEST3'/, 'failed';
like $output, /^^ 'ok' \N+ 'HTEST4'/, 'errors';
like $output, /^^ 'ok' \N+ 'HTEST5'/, 'skipped';
like $output, /^^ 'ok' \N+ 'HTEST6'/, 'todo';
like $output, /^^ 'ok' \N+ 'HTEST7'/, 'todo passed';
like $output, /^^ 'ok' \N+ 'HTEST8'/, '.exit-failed';
}
17 changes: 17 additions & 0 deletions t/06-tap-harness/test-files/01-desc-backslashes--1.TAP-TEST
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/usr/bin/env perl6
use v6;
use Test;
plan 12;

ok 1, 'fake todo # TODO it is fake 1';
ok 1, 'fake todo \# TODO it is fake 2';
ok 1, 'fake todo \\# TODO it is fake 3';
ok 1, 'fake todo \\# TODO it is fake 4';
ok 1, 'fake todo \\\# TODO it is fake 5';
ok 1, 'fake todo \\\\# TODO it is fake 6';
ok 1, 'fake todo \\\\\# TODO it is fake 7';
ok 1, '\\';
ok 1, '\\\\';
ok 1, '\\\\\\';
ok 1, '\\\\\\\\';
ok 1, '\\\\\\\\\\';

0 comments on commit b120ac4

Please sign in to comment.