| 1 |
use Test2::V0; |
| 2 |
|
| 3 |
use File::Spec; |
| 4 |
use File::Temp qw/tempdir/; |
| 5 |
|
| 6 |
use App::Yath::Tester qw/yath/; |
| 7 |
|
| 8 |
use App::Yath::Util qw/find_yath/; |
| 9 |
find_yath(); # cache result before we chdir |
| 10 |
|
| 11 |
my $dir = __FILE__; |
| 12 |
$dir =~ s{\.t$}{}g; |
| 13 |
|
| 14 |
my $hook_dir = File::Spec->rel2abs($dir); |
| 15 |
my $target = File::Spec->catfile($hook_dir, 'simple.tx'); |
| 16 |
|
| 17 |
# Run where the rc search, which walks up from cwd, finds no .yath.rc, keeping |
| 18 |
# the project rc's -D and -I settings out of the @INC this file inspects. |
| 19 |
chdir(tempdir(CLEANUP => 1, TMPDIR => 1)) or die "Could not chdir to a temp dir: $!"; |
| 20 |
|
| 21 |
# One fixture per @INC hook form documented in perlvar "@INC". Unfiltered, the |
| 22 |
# blessed hook aborts the run when the settings are JSON encoded, and all three |
| 23 |
# reach child -I flags as nonexistent 'CODE(0x...)' style paths. |
| 24 |
my @cases = ( |
| 25 |
{name => 'blessed object hook', module => 'FakeHook', ref_re => qr{/FakeHook=HASH\(}}, |
| 26 |
{name => 'coderef hook', module => 'CoderefHook', ref_re => qr{/CODE\(0x}}, |
| 27 |
{name => 'arrayref hook', module => 'ArrayrefHook', ref_re => qr{/ARRAY\(0x}}, |
| 28 |
); |
| 29 |
|
| 30 |
for my $case (@cases) { |
| 31 |
yath( |
| 32 |
command => 'test', |
| 33 |
args => ['-v', $target], |
| 34 |
env => {PERL5OPT => "-I$hook_dir -M$case->{module}"}, |
| 35 |
exit => 0, |
| 36 |
test => sub { |
| 37 |
my $out = shift; |
| 38 |
|
| 39 |
unlike($out->{output}, qr/encountered object|JSON can only represent/, "$case->{name}: no JSON encode error"); |
| 40 |
|
| 41 |
unlike($out->{output}, $case->{ref_re}, "$case->{name}: no stringified hook in the reported \@INC"); |
| 42 |
}, |
| 43 |
); |
| 44 |
} |
| 45 |
|
| 46 |
done_testing; |