Debian lenny version packages
[pkg-perl] / deb-src / libtest-harness-perl / libtest-harness-perl-3.12 / t / taint.t
1 #!/usr/bin/perl -w
2
3 BEGIN {
4     if ( $ENV{PERL_CORE} ) {
5         chdir 't';
6         @INC = ( '../lib', 'lib' );
7     }
8     else {
9         unshift @INC, 't/lib';
10     }
11 }
12
13 # Test that options in PERL5LIB and PERL5OPT are propogated to tainted
14 # tests
15
16 use strict;
17 use Test::More ( $^O eq 'VMS' ? ( skip_all => 'VMS' ) : ( tests => 3 ) );
18
19 use Config;
20 use TAP::Parser;
21
22 my $lib_path = join( ', ', map "'$_'", grep !ref, grep defined, @INC );
23
24 sub run_test_file {
25     my ( $test_template, @args ) = @_;
26
27     my $test_file = 'temp_test.tmp';
28
29     open TEST, ">$test_file" or die $!;
30     printf TEST $test_template, @args;
31     close TEST;
32
33     my $p = TAP::Parser->new( { source => $test_file } );
34     1 while $p->next;
35     ok !$p->has_problems;
36
37     unlink $test_file;
38 }
39
40 {
41     local $ENV{PERL5LIB} = join $Config{path_sep}, grep defined, 'wibble',
42       $ENV{PERL5LIB};
43     run_test_file( <<'END', $lib_path );
44 #!/usr/bin/perl -T
45
46 BEGIN { unshift @INC, ( %s ); }
47 use Test::More tests => 1;
48
49 ok grep(/^wibble$/, @INC) or diag join "\n", @INC;
50 END
51 }
52
53 {
54     my $perl5lib = $ENV{PERL5LIB};
55     local $ENV{PERL5LIB};
56     local $ENV{PERLLIB} = join $Config{path_sep}, grep defined, 'wibble',
57       $perl5lib;
58     run_test_file( <<'END', $lib_path );
59 #!/usr/bin/perl -T
60
61 BEGIN { unshift @INC, ( %s ); }
62 use Test::More tests => 1;
63
64 ok grep(/^wibble$/, @INC) or diag join "\n", @INC;
65 END
66 }
67
68 {
69     local $ENV{PERL5LIB} = join $Config{path_sep}, @INC;
70     local $ENV{PERL5OPT} = '-Mstrict';
71     run_test_file(<<'END');
72 #!/usr/bin/perl -T
73
74 print "1..1\n";
75 print $INC{'strict.pm'} ? "ok 1\n" : "not ok 1\n";
76 END
77 }
78
79 1;