Commit | Line | Data |
24351831 |
1 | # |
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. |
5 | # |
6 | |
7 | use strict; |
8 | use warnings; |
0c1be9f3 |
9 | use Test::More tests => 1; |
10 | use File::Temp 'tempfile'; |
24351831 |
11 | use Cwd; |
12 | |
0c1be9f3 |
13 | use lib 't/lib'; use TempDir; |
24351831 |
14 | |
0c1be9f3 |
15 | my $dir1 = mk_temp_dir('test_local_lib-XXXXX'); |
24351831 |
16 | |
17 | # Set up local::lib environment using our temp dir |
18 | require local::lib; |
19 | local::lib->import($dir1); |
20 | |
21 | # Create a script that has taint mode turned on, and tries to use a |
22 | # local lib to the same temp dir. |
23 | my ($fh, $filename) = tempfile('test_local_lib-XXXXX', DIR => Cwd::abs_path('t'), UNLINK => 1); |
24 | |
076f72d9 |
25 | # escape backlslashes for embedding into generated script |
26 | $dir1 =~ s/\\/\\\\/g; |
27 | |
24351831 |
28 | print $fh <<EOM; |
29 | #!/usr/bin/perl -T |
30 | use strict; use warnings; |
31 | use local::lib '$dir1'; |
076f72d9 |
32 | warn 'using lib dir $dir1', "\n"; |
33 | my \$dir = '$dir1'; |
34 | if (grep { m{^\\Q\$dir\\E/} } \@INC) { |
24351831 |
35 | exit 0; |
36 | } |
37 | exit 1 |
38 | EOM |
39 | close $fh; |
40 | |
41 | my $exit_val = system($^X, '-Ilib', '-T', $filename); |
42 | |
43 | is($exit_val >> 8, 0, 'test script exited with 0, local::lib dir found in @INC'); |