| 1 |
use Test2::V0; |
| 2 |
|
| 3 |
use App::Yath::Tester qw/yath/; |
| 4 |
use File::Temp qw/tempdir/; |
| 5 |
use Test2::Harness::Util::File::JSONL; |
| 6 |
|
| 7 |
use Test2::Harness::Util::JSON qw/decode_json/; |
| 8 |
|
| 9 |
my $dir = __FILE__; |
| 10 |
$dir =~ s{\.t$}{}g; |
| 11 |
$dir =~ s{^\./}{}; |
| 12 |
|
| 13 |
sub verify { |
| 14 |
my (@outputs) = @_; |
| 15 |
|
| 16 |
my $text = ''; |
| 17 |
for my $out (@outputs) { |
| 18 |
$text .= $out->{output}; |
| 19 |
} |
| 20 |
|
| 21 |
like($text, qr/TEST PLUGIN: Loaded Plugin/, "Yath loaded the plugin"); |
| 22 |
like($text, qr/TEST PLUGIN: duration_data/, "duration_data() was called"); |
| 23 |
|
| 24 |
like($text, qr/TEST PLUGIN: changed_files\(Test2::Harness::Settings\)/, "changed_files() was called"); |
| 25 |
like($text, qr/TEST PLUGIN: get_coverage_tests\(Test2::Harness::Settings, HASH\(5\)\)/, "get_coverage_tests() was called"); |
| 26 |
|
| 27 |
like($text, qr/TEST PLUGIN: munge_files/, "munge_files() was called"); |
| 28 |
like($text, qr/TEST PLUGIN: munge_search/, "munge_search() was called"); |
| 29 |
like($text, qr/TEST PLUGIN: inject_run_data/, "inject_run_data() was called"); |
| 30 |
like($text, qr/TEST PLUGIN: handle_event/, "handle_event() was called"); |
| 31 |
|
| 32 |
like($text, qr/TEST PLUGIN: claim_file .*test\.tx$/m, "claim_file(test.tx) was called"); |
| 33 |
like($text, qr/TEST PLUGIN: claim_file .*TestPlugin\.pm$/m, "claim_file(TestPlugin.pm) was called"); |
| 34 |
like($text, qr/TEST PLUGIN: setup Test2::Harness::Settings/, "setup() was called with settings"); |
| 35 |
like($text, qr/TEST PLUGIN: teardown Test2::Harness::Settings/, "teardown() was called with settings"); |
| 36 |
|
| 37 |
like($text, qr/\(TESTPLUG\)\s+STDERR WRITE$/m, "Got the STDERR write from the shellcall"); |
| 38 |
like($text, qr/\(TESTPLUG\)\s+STDOUT WRITE$/m, "Got the STDOUT write from the shellcall"); |
| 39 |
|
| 40 |
like( |
| 41 |
$text, |
| 42 |
qr/TEST PLUGIN: finish asserts_seen => 10, final_data => HASH, pass => 1, settings => Test2::Harness::Settings, tests_seen => 5/, |
| 43 |
"finish() was called with necessary args" |
| 44 |
); |
| 45 |
|
| 46 |
is(@{[$text =~ m/TEST PLUGIN: setup/g]}, 1, "Only ran setup once"); |
| 47 |
is(@{[$text =~ m/TEST PLUGIN: teardown/g]}, 1, "Only ran teardown once"); |
| 48 |
is(@{[$text =~ m/TEST PLUGIN: finish/g]}, 1, "Only ran finish once"); |
| 49 |
|
| 50 |
if (ok($text =~ m/^FIELDS:(.*)$/m, "Found fields")) { |
| 51 |
my $data = decode_json($1); |
| 52 |
is( |
| 53 |
$data, |
| 54 |
[{ |
| 55 |
name => 'test_plugin', details => 'foo', raw => 'bar', data => 'baz', |
| 56 |
}], |
| 57 |
"Injected the run data" |
| 58 |
); |
| 59 |
} |
| 60 |
|
| 61 |
my %rank = ( |
| 62 |
test => 1, |
| 63 |
c => 2, |
| 64 |
b => 3, |
| 65 |
a => 4, |
| 66 |
d => 5, |
| 67 |
); |
| 68 |
|
| 69 |
my %jobs = reverse($text =~ m{job\s+(\d+)\s+.*\W(\w+)\.tx}g); |
| 70 |
is(\%jobs, \%rank, "Ran jobs in specified order"); |
| 71 |
} |
| 72 |
|
| 73 |
yath( |
| 74 |
command => 'test', |
| 75 |
args => [$dir, '--ext=tx', '-A', '--durations-threshold' => 1, '--no-plugins', '-pTestPlugin', '--changes-plugin', 'TestPlugin'], |
| 76 |
exit => 0, |
| 77 |
test => \&verify, |
| 78 |
); |
| 79 |
|
| 80 |
unless ($ENV{AUTOMATED_TESTING} || $ENV{AUTHOR_TESTING}) { |
| 81 |
subtest persist => sub { |
| 82 |
verify( |
| 83 |
yath(command => 'start', args => ['--no-plugins', '-pTestPlugin'], exit => 0), |
| 84 |
yath(command => 'run', args => ['--no-plugins', '-pTestPlugin', '--changes-plugin', 'TestPlugin', exit => 0, $dir, '--ext=tx', '-A']), |
| 85 |
yath(command => 'stop', args => ['--no-plugins', '-pTestPlugin'], exit => 0), |
| 86 |
); |
| 87 |
}; |
| 88 |
} |
| 89 |
|
| 90 |
done_testing; |