Skip to content

Commit e70642a

Browse files
schwernLeont
authored andcommitted
Don't allow SourceHandler ties. Harness behavior must be deterministic.
test.tap scores as 0.9 both as a TAP file and as a Perl executable. Currently one will be randomly chosen adding a heisenbug to the test suite. This patch makes confidence ties an error. See http://stackoverflow.com/questions/44101948/prove-returns-inconsistent-test-results-with-testmore-and-tap-extension/44102160 for an example in the wild.
1 parent 0230738 commit e70642a

File tree

4 files changed

+33
-4
lines changed

4 files changed

+33
-4
lines changed

MANIFEST

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,7 @@ t/source_tests/source.sh
209209
t/source_tests/source.t
210210
t/source_tests/source.tap
211211
t/source_tests/source_args.sh
212+
t/source_tests/test.tap
212213
t/spool.t
213214
t/state.t
214215
t/state_results.t

lib/TAP/Parser/IteratorFactory.pm

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,15 @@ sub detect_source {
269269
keys %handlers
270270
);
271271

272+
# Check for a tie.
273+
if( @handlers > 1 &&
274+
$handlers{$handlers[0]} == $handlers{$handlers[1]}
275+
) {
276+
my $filename = $source->meta->{file}{basename};
277+
die("There is a tie between $handlers[0] and $handlers[1].\n".
278+
"Both voted $handlers{$handlers[0]} on $filename.\n");
279+
}
280+
272281
# this is really useful for debugging handlers:
273282
if ( $ENV{TAP_HARNESS_SOURCE_FACTORY_VOTES} ) {
274283
warn(

t/iterator_factory.t

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ BEGIN {
1010
use strict;
1111
use warnings;
1212

13-
use Test::More tests => 42;
13+
use Test::More tests => 44;
1414

1515
use IO::File;
1616
use File::Spec;
@@ -124,6 +124,9 @@ my @sources = (
124124
handler => 'TAP::Parser::SourceHandler::Handle',
125125
iterator => 'TAP::Parser::Iterator::Stream',
126126
},
127+
{ file => 'test.tap',
128+
tie => 1,
129+
},
127130
);
128131
129132
for my $test (@sources) {
@@ -141,10 +144,18 @@ for my $test (@sources) {
141144
my $source = TAP::Parser::Source->new->raw( ref($raw) ? $raw : \$raw );
142145
my $iterator = eval { $sf->make_iterator($source) };
143146
my $error = $@;
144-
ok( !$error, "$name: no error on make_iterator" );
145-
diag($error) if $error;
146147
147-
# isa_ok( $iterator, $test->{iterator}, $name );
148+
if( $test->{tie} ) {
149+
like(
150+
$error, qr{^There is a tie.*Both voted .* on $test->{file}}ms,
151+
"$name: votes tied"
152+
)
153+
}
154+
else {
155+
ok( !$error, "$name: no error on make_iterator" );
156+
diag($error) if $error;
157+
}
158+
148159
is( $sf->_last_handler, $test->{handler}, $name );
149160
}
150161

t/source_tests/test.tap

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#!/usr/bin/perl
2+
3+
# This looks equally like a TAP file and a Perl executable.
4+
5+
print <<'END_TESTS';
6+
1..1
7+
ok 1 - source.pl
8+
END_TESTS

0 commit comments

Comments
 (0)