5 use File::Basename qw(dirname);
10 my @paths = File::Spec->path;
11 my @ext = $^O eq 'MSWin32' ? (split /\Q$Config{path_sep}/, $ENV{PATHEXT}) : ('');
14 for my $dir (@paths) {
15 my $file = File::Spec->catfile($dir||'.', $shell);
17 my $full = $file . $ext;
25 my $extra_lib = '-I"' . dirname(dirname($INC{'local/lib.pm'})) . '"';
44 opt => '-NoProfile -ExecutionPolicy Unrestricted',
49 my $name = $shell->{name};
50 $shell->{shell} = which($name);
51 $shell->{ext} ||= $name;
52 $shell->{perl} ||= qq{"$^X"};
55 if !grep {$_ eq $name} @ARGV;
56 if (!$shell->{shell}) {
57 warn "unable to find executable for $name";
61 elsif (!$shell->{shell}) {
68 plan skip_all => 'no supported shells found';
70 plan tests => 6*@shells;
72 my $sep = $Config{path_sep};
74 my $root = File::Spec->rootdir;
75 for my $shell (@shells) {
76 my $ll = File::Temp->newdir();
77 my $ll_dir = local::lib->normalize_path("$ll");
78 local $ENV{PERL_LOCAL_LIB_ROOT};
79 delete $ENV{PERL_LOCAL_LIB_ROOT};
80 local $ENV{PATH} = $root;
82 delete $ENV{PERL5LIB};
83 my $env = call_ll($shell, "$ll");
84 is $env->{PERL_LOCAL_LIB_ROOT}, $ll_dir,
85 "$shell->{name}: activate root";
86 is $env->{PATH}, local::lib->install_base_bin_path($ll_dir)."$sep$root",
87 "$shell->{name}: activate PATH";
88 is $env->{PERL5LIB}, local::lib->install_base_perl_path($ll_dir),
89 "$shell->{name}: activate PERL5LIB";
91 $ENV{$_} = $env->{$_} for qw(PATH PERL5LIB PERL_LOCAL_LIB_ROOT);
92 $env = call_ll($shell, '--deactivate', "$ll");
94 is $env->{PERL_LOCAL_LIB_ROOT}, undef,
95 "$shell->{name}: deactivate root";
96 is $env->{PATH}, $root,
97 "$shell->{name}: deactivate PATH";
98 is $env->{PERL5LIB}, undef,
99 "$shell->{name}: deactivate PERL5LIB";
103 my ($info, @options) = @_;
104 my $option = @options ? '='.join(',', @options) : '';
106 local $ENV{SHELL} = $info->{shell};
108 my $file = File::Temp->new(
109 TEMPLATE => 'll-test-script-XXXXX',
111 SUFFIX => '.'.$info->{ext},
114 $file->print(scalar `"$^X" $extra_lib -Mlocal::lib$option` . "\n");
115 $file->print(qq{$info->{perl} -Mt::lib::ENVDumper -e1\n});
118 my $opt = $info->{opt} ? "$info->{opt} " : '';
119 my $out = `"$info->{shell}" $opt"$file"`;
121 die "failed with code: $?";
124 eval $out or die "bad output: $@";