2 # t/taint-mode.t: checks that local::lib sets up @INC correctly when
3 # included in a script that has taint mode on, and is executing in an
4 # environment in which local::lib has already been loaded.
9 use Test::More tests => 3;
10 use File::Temp 'tempfile';
15 use lib 't/lib'; use TempDir;
19 my $dir1 = mk_temp_dir('used_in_taint-XXXXX');
20 my $dir2 = mk_temp_dir('not_used_in_taint-XXXXX');
22 # Set up local::lib environment using our temp dir
24 local::lib->import($dir1);
25 local::lib->import($dir2);
27 # Create a script that has taint mode turned on, and tries to use a
28 # local lib to the same temp dir.
29 my ($fh, $filename) = tempfile('test_local_lib-XXXXX', DIR => Cwd::abs_path('t'), UNLINK => 1);
33 use strict; use warnings;
34 use local::lib "\Q$dir1\E";
35 print "\$_\\n" for \@INC;
39 open my $in, '<', File::Spec->devnull;
40 my $pid = open3($in, my $out, undef, $^X, map("-I$_", @INC_CLEAN), '-T', $filename);
42 s/[\r\n]*\z// for @libs;
45 is $?, 0, 'test script ran without error';
47 my $dir1_lib = local::lib->install_base_perl_path($dir1);
48 ok grep($_ eq $dir1_lib, @libs),
49 'local::lib used in taint script added to @INC'
50 or diag "searched for '$dir1_lib' in: ", explain \@libs;
52 my $dir2_lib = local::lib->install_base_perl_path($dir2);
53 ok !grep($_ eq $dir2_lib, @libs),
54 'local::lib not used used in taint script not added to @INC'
55 or diag "searched for '$dir2_lib' in: ", explain \@libs;