Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/Test2/Harness/Runner/Job.pm
Original file line number Diff line number Diff line change
Expand Up @@ -511,7 +511,7 @@ sub env_vars {
my $from_task = $self->{+TASK}->{env_vars};

my @p5l = ($from_task->{PERL5LIB}, $from_run->{PERL5LIB});
push @p5l => $self->includes if $self->{+TASK}->{binary} || $self->{+TASK}->{non_perl};
push @p5l => $self->includes;
push @p5l => $ENV{PERL5LIB} if $ENV{PERL5LIB};
my $p5l = join $Config{path_sep} => grep { defined $_ && $_ ne '.' } @p5l;

Expand Down
6 changes: 6 additions & 0 deletions t/integration/includes.t
Original file line number Diff line number Diff line change
Expand Up @@ -52,4 +52,10 @@ yath(
exit => 0,
) if can_run('bash');

yath(
command => 'test',
args => ['child-inherits-inc.tx'],
exit => 0,
);

done_testing;
27 changes: 27 additions & 0 deletions t/integration/includes/child-inherits-inc.tx
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
use Test2::V0;

use File::Spec;
use Config qw/%Config/;

# This test verifies that child processes spawned via system() inherit
# the include paths set by yath (fixes GitHub #296).
# When yath runs a test with --lib, the test process gets -I flags on
# the command line. But system($^X, ...) children don't inherit CLI flags;
# they need PERL5LIB to find project modules.

my @parts = File::Spec->splitpath(File::Spec->rel2abs(__FILE__));
pop @parts;
my $path = File::Spec->catpath(@parts);

my $lib_dir = File::Spec->catdir($path, 'lib');

# Spawn a child perl process and capture its @INC
my $child_inc = `$^X -e "print join qq{\\n}, \@INC"`;
my @child_inc = split /\n/, $child_inc;

ok(
(grep { $_ eq $lib_dir } @child_inc),
"Child process via backticks inherits project lib dir ($lib_dir) via PERL5LIB"
) or diag "Child \@INC was: @child_inc";

done_testing;
13 changes: 12 additions & 1 deletion t/integration/includes/default-i.tx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use Test2::V0;

use File::Spec;
use Config qw/%Config/;

my @parts = File::Spec->splitpath(File::Spec->rel2abs(__FILE__));
pop @parts;
Expand All @@ -20,6 +21,16 @@ like(
"Added lib, blib/lib, and blib/arch AFTER the -Ixyz"
);

is($ENV{PERL5LIB}, $ENV{OLD_PERL5LIB}, "PERL5LIB has not been modified");
like(
[split $Config{path_sep}, $ENV{PERL5LIB}],
[
App::Yath->app_path,
File::Spec->catdir($path, 'xyz'),
File::Spec->catdir($path, 'lib'),
File::Spec->catdir($path, 'blib', 'lib'),
File::Spec->catdir($path, 'blib', 'arch'),
],
"PERL5LIB includes all lib paths so child processes inherit them"
);

done_testing;
12 changes: 11 additions & 1 deletion t/integration/includes/default.tx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use Test2::V0;
require App::Yath;

use File::Spec;
use Config qw/%Config/;

my @parts = File::Spec->splitpath(File::Spec->rel2abs(__FILE__));
pop @parts;
Expand All @@ -19,6 +20,15 @@ like(
"Added lib, blib/lib, and blib/arch to the front of the line"
);

is($ENV{PERL5LIB}, $ENV{OLD_PERL5LIB}, "PERL5LIB has not been modified");
like(
[split $Config{path_sep}, $ENV{PERL5LIB}],
[
App::Yath->app_path,
File::Spec->catdir($path, 'lib'),
File::Spec->catdir($path, 'blib', 'lib'),
File::Spec->catdir($path, 'blib', 'arch'),
],
"PERL5LIB includes lib paths so child processes inherit them"
);

done_testing;
2 changes: 1 addition & 1 deletion t/integration/includes/dot-last.tx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,6 @@ like(

is($INC[-1], '.', "Dot added last");

is($ENV{PERL5LIB}, $ENV{OLD_PERL5LIB}, "PERL5LIB has not been modified");
isnt($ENV{PERL5LIB}, $ENV{OLD_PERL5LIB}, "PERL5LIB includes project lib paths for child process inheritance");

done_testing;
2 changes: 1 addition & 1 deletion t/integration/includes/order-ibili.tx
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,6 @@ like(
"Added all via cli, in order"
);

is($ENV{PERL5LIB}, $ENV{OLD_PERL5LIB}, "PERL5LIB has not been modified");
isnt($ENV{PERL5LIB}, $ENV{OLD_PERL5LIB}, "PERL5LIB includes project lib paths for child process inheritance");

done_testing;
2 changes: 1 addition & 1 deletion t/integration/includes/order-ilibi.tx
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,6 @@ like(
"Added all via cli, in order"
);

is($ENV{PERL5LIB}, $ENV{OLD_PERL5LIB}, "PERL5LIB has not been modified");
isnt($ENV{PERL5LIB}, $ENV{OLD_PERL5LIB}, "PERL5LIB includes project lib paths for child process inheritance");

done_testing;
Loading