X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=p5sagit%2Flocal-lib.git;a=blobdiff_plain;f=t%2Fshell.t;h=7ab7ef29b71ec9de1d3874cbf2dc214fa5e420eb;hp=047d49c57cd7c69d9d65e50cd8cc51e406794e0e;hb=1730f48f02f596ea214aab12466dd6471a2990d7;hpb=1d89f85b87644d20299afa0574a9b4d780f333ee diff --git a/t/shell.t b/t/shell.t index 047d49c..7ab7ef2 100644 --- a/t/shell.t +++ b/t/shell.t @@ -8,18 +8,13 @@ use Config; use local::lib (); my @paths = File::Spec->path; -my @ext = $^O eq 'MSWin32' ? (split /\Q$Config{path_sep}/, $ENV{PATHEXT}) : (''); sub which { my $shell = shift; - for my $dir (@paths) { - my $file = File::Spec->catfile($dir||'.', $shell); - for my $ext (@ext) { - my $full = $file . $ext; - return $full - if -x $full; - } - } - return; + my ($full) = + grep { -x } + map { File::Spec->catfile( $_, $shell) } + File::Spec->path; + return $full; } my $extra_lib = '-I"' . dirname(dirname($INC{'local/lib.pm'})) . '"'; @@ -34,14 +29,17 @@ for my $shell ( opt => '-f', }, { - name => 'cmd', + name => 'fish', + }, + { + name => 'cmd.exe', opt => '/Q /D /C', ext => 'bat', perl => qq{@"$^X"}, skip => $^O eq 'cygwin', }, { - name => 'powershell', + name => 'powershell.exe', opt => '-NoProfile -ExecutionPolicy Unrestricted -File', ext => 'ps1', perl => qq{& '$^X'}, @@ -82,10 +80,12 @@ for my $shell (@shells) { local $ENV{PATH} = $root; local $ENV{PERL5LIB}; delete $ENV{PERL5LIB}; + my $bin_path = local::lib->install_base_bin_path($ll_dir); + mkdir $bin_path; my $env = call_ll($shell, "$ll"); is $env->{PERL_LOCAL_LIB_ROOT}, $ll_dir, "$shell->{name}: activate root"; - is $env->{PATH}, local::lib->install_base_bin_path($ll_dir)."$sep$root", + like $env->{PATH}, qr/^\Q$bin_path$sep$root\E(?:$|\Q$sep\E)/, "$shell->{name}: activate PATH"; is $env->{PERL5LIB}, local::lib->install_base_perl_path($ll_dir), "$shell->{name}: activate PERL5LIB"; @@ -95,7 +95,7 @@ for my $shell (@shells) { is $env->{PERL_LOCAL_LIB_ROOT}, undef, "$shell->{name}: deactivate root"; - is $env->{PATH}, $root, + like $env->{PATH}, qr/^\Q$root\E(?:$|\Q$sep\E)/, "$shell->{name}: deactivate PATH"; is $env->{PERL5LIB}, undef, "$shell->{name}: deactivate PERL5LIB"; @@ -107,19 +107,24 @@ sub call_ll { local $ENV{SHELL} = $info->{shell}; + my $script + = `"$^X" $extra_lib -Mlocal::lib$option` . "\n" + . qq{$info->{perl} -Mt::lib::ENVDumper -e1\n}; + my $file = File::Temp->new( TEMPLATE => 'll-test-script-XXXXX', TMPDIR => 1, SUFFIX => '.'.$info->{ext}, ); - - $file->print(scalar `"$^X" $extra_lib -Mlocal::lib$option` . "\n"); - $file->print(qq{$info->{perl} -Mt::lib::ENVDumper -e1\n}); - $file->close; + print { $file } $script; + close $file; my $opt = $info->{opt} ? "$info->{opt} " : ''; - my $out = `"$info->{shell}" $opt"$file"`; + my $cmd = qq{"$info->{shell}" $opt"$file"}; + my $out = `$cmd`; if ($?) { + diag "script:\n$script"; + diag "running:\n$cmd"; die "failed with code: $?"; } my $VAR1;