| 1 |
use Test2::V0; |
| 2 |
|
| 3 |
use File::Temp qw/tempdir/; |
| 4 |
use File::Spec; |
| 5 |
|
| 6 |
use App::Yath::Tester qw/yath/; |
| 7 |
use Test2::Harness::Util::File::JSONL; |
| 8 |
|
| 9 |
use Test2::Harness::Util::JSON qw/decode_json/; |
| 10 |
|
| 11 |
use Test2::Util qw/CAN_REALLY_FORK/; |
| 12 |
|
| 13 |
skip_all "Cannot fork, skipping preload test" |
| 14 |
unless CAN_REALLY_FORK; |
| 15 |
|
| 16 |
skip_all "This test requires forking" if $ENV{T2_NO_FORK}; |
| 17 |
|
| 18 |
my $dir = __FILE__; |
| 19 |
$dir =~ s{\.t$}{}g; |
| 20 |
$dir =~ s{^\./}{}; |
| 21 |
|
| 22 |
yath( |
| 23 |
command => 'test', |
| 24 |
args => [$dir, '--ext=tx', '-A', '-PTestSimplePreload', '-PTestPreload'], |
| 25 |
exit => 0, |
| 26 |
test => sub { |
| 27 |
my $out = shift; |
| 28 |
|
| 29 |
like($out->{output}, qr{PASSED.*no_preload\.tx}, 'Ran file "no_preload.tx"'); |
| 30 |
like($out->{output}, qr{PASSED.*aaa\.tx}, 'Ran file "aaa.tx"'); |
| 31 |
like($out->{output}, qr{PASSED.*bbb\.tx}, 'Ran file "bbb.tx"'); |
| 32 |
like($out->{output}, qr{PASSED.*ccc\.tx}, 'Ran file "ccc.tx"'); |
| 33 |
like($out->{output}, qr{PASSED.*simple_test\.tx}, 'Ran file "simple_test.tx"'); |
| 34 |
like($out->{output}, qr{PASSED.*preload_test\.tx}, 'Ran file "preload_test.tx"'); |
| 35 |
like($out->{output}, qr{PASSED.*fast\.tx}, 'Ran file "fast.tx"'); |
| 36 |
like($out->{output}, qr{PASSED.*slow\.tx}, 'Ran file "slow.tx"'); |
| 37 |
like($out->{output}, qr{TO RETRY.*retry\.tx}, 'Ran file "retry.tx" with a failure'); |
| 38 |
like($out->{output}, qr{PASSED.*retry\.tx}, 'Ran file "retry.tx" again with a pass'); |
| 39 |
}, |
| 40 |
); |
| 41 |
|
| 42 |
yath( |
| 43 |
command => 'test', |
| 44 |
args => [$dir, '--ext=tx', '-A', '-PTestSimplePreload', '-PTestPreload', '-PBroken'], |
| 45 |
exit => T(), |
| 46 |
test => sub { |
| 47 |
my $out = shift; |
| 48 |
|
| 49 |
like($out->{output}, qr{This is broken}, "Reported the error"); |
| 50 |
like($out->{output}, qr{No tests were seen!}, "No tests were run"); |
| 51 |
}, |
| 52 |
); |
| 53 |
|
| 54 |
yath( |
| 55 |
command => 'test', |
| 56 |
args => [$dir, '--ext=tx', '-A', '-PTestBadPreload' ], |
| 57 |
exit => T(), |
| 58 |
test => sub { |
| 59 |
my $out = shift; |
| 60 |
|
| 61 |
like($out->{output}, qr{Child stage 'BAD' did not exit cleanly}, "Reported the error"); |
| 62 |
}, |
| 63 |
); |
| 64 |
|
| 65 |
unless ($ENV{AUTOMATED_TESTING}) { |
| 66 |
yath( |
| 67 |
command => 'start', |
| 68 |
args => ['-PTestSimplePreload', '-PTestPreload'], |
| 69 |
exit => 0, |
| 70 |
test => sub { |
| 71 |
yath( |
| 72 |
command => 'run', |
| 73 |
args => [$dir, '--ext=tx', '-A'], |
| 74 |
exit => 0, |
| 75 |
test => sub { |
| 76 |
my $out = shift; |
| 77 |
|
| 78 |
like($out->{output}, qr{PASSED.*no_preload\.tx}, 'Ran file "no_preload.tx"'); |
| 79 |
like($out->{output}, qr{PASSED.*aaa\.tx}, 'Ran file "aaa.tx"'); |
| 80 |
like($out->{output}, qr{PASSED.*bbb\.tx}, 'Ran file "bbb.tx"'); |
| 81 |
like($out->{output}, qr{PASSED.*ccc\.tx}, 'Ran file "ccc.tx"'); |
| 82 |
like($out->{output}, qr{PASSED.*simple_test\.tx}, 'Ran file "simple_test.tx"'); |
| 83 |
like($out->{output}, qr{PASSED.*preload_test\.tx}, 'Ran file "preload_test.tx"'); |
| 84 |
like($out->{output}, qr{PASSED.*fast\.tx}, 'Ran file "fast.tx"'); |
| 85 |
like($out->{output}, qr{PASSED.*slow\.tx}, 'Ran file "slow.tx"'); |
| 86 |
like($out->{output}, qr{TO RETRY.*retry\.tx}, 'Ran file "retry.tx" with a failure'); |
| 87 |
like($out->{output}, qr{PASSED.*retry\.tx}, 'Ran file "retry.tx" again with a pass'); |
| 88 |
}, |
| 89 |
); |
| 90 |
|
| 91 |
yath(command => 'stop', exit => 0); |
| 92 |
}, |
| 93 |
); |
| 94 |
|
| 95 |
# Persistent mode ignored broken preloads as they may be under active development |
| 96 |
yath( |
| 97 |
command => 'start', |
| 98 |
args => ['-PTestSimplePreload', '-PTestPreload', '-PBroken'], |
| 99 |
exit => 0, |
| 100 |
test => sub { |
| 101 |
yath( |
| 102 |
command => 'run', |
| 103 |
args => [$dir, '--ext=tx', '-A'], |
| 104 |
exit => 0, |
| 105 |
test => sub { |
| 106 |
my $out = shift; |
| 107 |
|
| 108 |
like($out->{output}, qr{This is broken}, "Reported the error"); |
| 109 |
like($out->{output}, qr{PASSED.*no_preload\.tx}, 'Ran file "no_preload.tx"'); |
| 110 |
like($out->{output}, qr{PASSED.*aaa\.tx}, 'Ran file "aaa.tx"'); |
| 111 |
like($out->{output}, qr{PASSED.*bbb\.tx}, 'Ran file "bbb.tx"'); |
| 112 |
like($out->{output}, qr{PASSED.*ccc\.tx}, 'Ran file "ccc.tx"'); |
| 113 |
like($out->{output}, qr{PASSED.*simple_test\.tx}, 'Ran file "simple_test.tx"'); |
| 114 |
like($out->{output}, qr{PASSED.*preload_test\.tx}, 'Ran file "preload_test.tx"'); |
| 115 |
like($out->{output}, qr{PASSED.*fast\.tx}, 'Ran file "fast.tx"'); |
| 116 |
like($out->{output}, qr{PASSED.*slow\.tx}, 'Ran file "slow.tx"'); |
| 117 |
like($out->{output}, qr{TO RETRY.*retry\.tx}, 'Ran file "retry.tx" with a failure'); |
| 118 |
like($out->{output}, qr{PASSED.*retry\.tx}, 'Ran file "retry.tx" again with a pass'); |
| 119 |
}, |
| 120 |
); |
| 121 |
|
| 122 |
yath(command => 'stop', exit => 0); |
| 123 |
}, |
| 124 |
); |
| 125 |
} |
| 126 |
|
| 127 |
done_testing; |