| 1 |
use Test2::V0; |
| 2 |
use Test2::Require::AuthorTesting; |
| 3 |
|
| 4 |
use File::Temp qw/tempdir/; |
| 5 |
use File::Spec; |
| 6 |
|
| 7 |
use App::Yath::Tester qw/yath/; |
| 8 |
use Test2::Harness::Util::File::JSONL; |
| 9 |
use Test2::Harness::Util qw/clean_path/; |
| 10 |
|
| 11 |
use Test2::Harness::Util::JSON qw/decode_json/; |
| 12 |
|
| 13 |
use Test2::Util qw/CAN_REALLY_FORK/; |
| 14 |
skip_all "Cannot fork, skipping preload test" |
| 15 |
if $ENV{T2_NO_FORK} || !CAN_REALLY_FORK; |
| 16 |
|
| 17 |
my $tx = __FILE__ . 'x'; |
| 18 |
|
| 19 |
my $tmpdir = tempdir(CLEANUP => 1); |
| 20 |
mkdir("$tmpdir/Preload") or die "($tmpdir/Preload) $!"; |
| 21 |
|
| 22 |
{ |
| 23 |
open(my $fh, '>', "$tmpdir/Preload.pm") or die "Could not create preload: $!"; |
| 24 |
print $fh <<' EOT'; |
| 25 |
package Preload; |
| 26 |
use strict; |
| 27 |
use warnings; |
| 28 |
|
| 29 |
use Test2::Harness::Runner::Preload; |
| 30 |
|
| 31 |
stage A => sub { |
| 32 |
default(); |
| 33 |
|
| 34 |
# Do like this to avoid blacklisting |
| 35 |
preload sub { require Preload::Flux }; |
| 36 |
}; |
| 37 |
|
| 38 |
1; |
| 39 |
EOT |
| 40 |
} |
| 41 |
|
| 42 |
sub touch { |
| 43 |
my ($inject) = @_; |
| 44 |
my $path = "$tmpdir/Preload/Flux.pm"; |
| 45 |
note "Touching $path..."; |
| 46 |
sleep 1; |
| 47 |
|
| 48 |
open(my $fh, '>', $path) or die $!; |
| 49 |
|
| 50 |
print $fh <<" EOT"; |
| 51 |
package Preload::Flux; |
| 52 |
use strict; |
| 53 |
use warnings; |
| 54 |
|
| 55 |
sub foo { 'foo' } |
| 56 |
|
| 57 |
$inject |
| 58 |
|
| 59 |
1; |
| 60 |
EOT |
| 61 |
|
| 62 |
close($fh); |
| 63 |
|
| 64 |
sleep 2; |
| 65 |
} |
| 66 |
|
| 67 |
touch('$Preload::Flux::VAR = "initial";'); |
| 68 |
|
| 69 |
yath( |
| 70 |
command => 'start', |
| 71 |
pre => ["-D$tmpdir"], |
| 72 |
args => ["-I$tmpdir", '-PPreload'], |
| 73 |
debug => 2, |
| 74 |
exit => 0, |
| 75 |
); |
| 76 |
|
| 77 |
yath( |
| 78 |
command => 'run', |
| 79 |
args => [$tx, '::', 'initial'], |
| 80 |
exit => 0, |
| 81 |
); |
| 82 |
|
| 83 |
touch('$Preload::Flux::VAR = "Syntax Error $bob";'); |
| 84 |
|
| 85 |
yath( |
| 86 |
command => 'run', |
| 87 |
args => [$tx], # no arg, so undef |
| 88 |
exit => 0, |
| 89 |
); |
| 90 |
|
| 91 |
touch('$Preload::Flux::VAR = "fixed";'); |
| 92 |
|
| 93 |
yath( |
| 94 |
command => 'run', |
| 95 |
args => [$tx, '::', 'fixed'], |
| 96 |
exit => 0, |
| 97 |
); |
| 98 |
|
| 99 |
|
| 100 |
yath(command => 'stop', exit => 0); |
| 101 |
|
| 102 |
done_testing; |