| 1 |
use Test2::V0 -target => 'Test2::Harness::Auditor::Watcher'; |
| 2 |
|
| 3 |
use Test2::Harness::Collector::TapParser qw/parse_stdout_tap/; |
| 4 |
use Test2::Harness::Event; |
| 5 |
|
| 6 |
my $EVENT_ID = 1; |
| 7 |
|
| 8 |
sub harness_event { |
| 9 |
my ($facet_data) = @_; |
| 10 |
|
| 11 |
return Test2::Harness::Event->new( |
| 12 |
run_id => 'run', |
| 13 |
job_id => 'job', |
| 14 |
job_try => 0, |
| 15 |
event_id => 'event-' . $EVENT_ID++, |
| 16 |
facet_data => $facet_data, |
| 17 |
); |
| 18 |
} |
| 19 |
|
| 20 |
sub harness_output_event { |
| 21 |
my ($line, $tag) = @_; |
| 22 |
|
| 23 |
return harness_event({info => [{details => $line, tag => $tag, debug => $tag eq 'STDERR' ? 1 : 0}]}); |
| 24 |
} |
| 25 |
|
| 26 |
# A pair of nested streamed subtests, as a test that does not use the event |
| 27 |
# stream writes them. |
| 28 |
my @TAP = ( |
| 29 |
'# Subtest: foo', |
| 30 |
' # Subtest: bar', |
| 31 |
' ok 1 - baz', |
| 32 |
' 1..1', |
| 33 |
' ok 1 - bar', |
| 34 |
' 1..1', |
| 35 |
'ok 1 - foo', |
| 36 |
'1..1', |
| 37 |
); |
| 38 |
|
| 39 |
sub watch { |
| 40 |
my (%params) = @_; |
| 41 |
|
| 42 |
my $watcher = $CLASS->new(job => {job_id => 'job'}, try => 0); |
| 43 |
|
| 44 |
for my $idx (0 .. $#TAP) { |
| 45 |
$watcher->process(harness_output_event($params{noise}, $params{tag} || 'STDERR')) |
| 46 |
if defined($params{noise_at}) && $params{noise_at} == $idx; |
| 47 |
|
| 48 |
$watcher->process(harness_event(parse_stdout_tap($TAP[$idx]))); |
| 49 |
} |
| 50 |
|
| 51 |
return $watcher; |
| 52 |
} |
| 53 |
|
| 54 |
subtest clean_run => sub { |
| 55 |
my $watcher = watch(); |
| 56 |
|
| 57 |
ok($watcher->pass, "Nested subtests passed"); |
| 58 |
is($watcher->assertion_count, 1, "Counted the top level assertion"); |
| 59 |
}; |
| 60 |
|
| 61 |
subtest output_does_not_close_subtests => sub { |
| 62 |
# A module warning (Test2::Util::UUID does this when it falls back to |
| 63 |
# UUID::Tiny) lands in the middle of the subtest TAP. It is not indented, |
| 64 |
# but it is not TAP either, so it must not end the subtest. |
| 65 |
for my $idx (0 .. $#TAP) { |
| 66 |
for my $tag (qw/STDERR STDOUT/) { |
| 67 |
my $watcher = watch(noise_at => $idx, noise => 'noise from a module', tag => $tag); |
| 68 |
|
| 69 |
ok($watcher->pass, "$tag before TAP line $idx did not fail the job") |
| 70 |
or diag(join "\n" => map { $_->{details} } $watcher->fail_error_facet_list); |
| 71 |
|
| 72 |
is($watcher->assertion_count, 1, "$tag before TAP line $idx left the assertion count alone"); |
| 73 |
} |
| 74 |
} |
| 75 |
}; |
| 76 |
|
| 77 |
subtest tap_still_closes_subtests => sub { |
| 78 |
my $watcher = $CLASS->new(job => {job_id => 'job'}, try => 0); |
| 79 |
|
| 80 |
# The inner subtest never gets its plan or its result line, the outer one |
| 81 |
# closes it. |
| 82 |
$watcher->process(harness_event(parse_stdout_tap($_))) for ( |
| 83 |
'# Subtest: foo', |
| 84 |
' # Subtest: bar', |
| 85 |
' ok 1 - baz', |
| 86 |
' 1..2', |
| 87 |
'ok 1 - foo', |
| 88 |
'1..1', |
| 89 |
); |
| 90 |
|
| 91 |
ok($watcher->fail, "Incomplete subtest was caught"); |
| 92 |
}; |
| 93 |
|
| 94 |
done_testing; |