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; |
9 | use Test::More; |
10 | use File::Temp qw(tempdir tempfile); |
11 | use Cwd; |
12 | |
13 | plan tests => 1; |
14 | |
15 | # Setup temp dir to serve as local lib |
16 | my $dir1 = tempdir('test_local_lib-XXXXX', DIR => Cwd::abs_path('t'), CLEANUP => 1); |
17 | |
18 | # Set up local::lib environment using our temp dir |
19 | require local::lib; |
20 | local::lib->import($dir1); |
21 | |
22 | # Create a script that has taint mode turned on, and tries to use a |
23 | # local lib to the same temp dir. |
24 | my ($fh, $filename) = tempfile('test_local_lib-XXXXX', DIR => Cwd::abs_path('t'), UNLINK => 1); |
25 | |
26 | print $fh <<EOM; |
27 | #!/usr/bin/perl -T |
28 | use strict; use warnings; |
29 | use local::lib '$dir1'; |
30 | my \$dir1 = "$dir1"; |
31 | if (grep { \$_ =~ m{^\$dir1/} } \@INC) { |
32 | exit 0; |
33 | } |
34 | exit 1 |
35 | EOM |
36 | close $fh; |
37 | |
38 | my $exit_val = system($^X, '-Ilib', '-T', $filename); |
39 | |
40 | is($exit_val >> 8, 0, 'test script exited with 0, local::lib dir found in @INC'); |