Commit | Line | Data |
317ea90d |
1 | #!./perl -t |
6537fe72 |
2 | |
3 | BEGIN { |
4 | chdir 't'; |
5 | @INC = '../lib'; |
6 | require './test.pl'; |
7 | } |
8 | |
36f064bc |
9 | plan tests => 13; |
6537fe72 |
10 | |
11 | my $Perl = which_perl(); |
12 | |
13 | my $warning; |
14 | local $SIG{__WARN__} = sub { $warning = join "\n", @_; }; |
15 | my $Tmsg = 'while running with -t switch'; |
16 | |
9aa05f58 |
17 | is( ${^TAINT}, -1, '${^TAINT} == -1' ); |
6537fe72 |
18 | |
dc459aad |
19 | my $out = `$Perl -le "print q(Hello)"`; |
6537fe72 |
20 | is( $out, "Hello\n", '`` worked' ); |
21 | like( $warning, qr/^Insecure .* $Tmsg/, ' taint warn' ); |
22 | |
23 | { |
24 | no warnings 'taint'; |
25 | $warning = ''; |
dc459aad |
26 | my $out = `$Perl -le "print q(Hello)"`; |
6537fe72 |
27 | is( $out, "Hello\n", '`` worked' ); |
28 | is( $warning, '', ' no warnings "taint"' ); |
29 | } |
30 | |
31 | # Get ourselves a tainted variable. |
2d90ac95 |
32 | my $filename = tempfile(); |
6537fe72 |
33 | $file = $0; |
2d90ac95 |
34 | $file =~ s/.*/$filename/; |
6537fe72 |
35 | ok( open(FILE, ">$file"), 'open >' ) or DIE $!; |
36 | print FILE "Stuff\n"; |
37 | close FILE; |
38 | like( $warning, qr/^Insecure dependency in open $Tmsg/, 'open > taint warn' ); |
39 | ok( -e $file, ' file written' ); |
40 | |
41 | unlink($file); |
42 | like( $warning, qr/^Insecure dependency in unlink $Tmsg/, |
43 | 'unlink() taint warn' ); |
44 | ok( !-e $file, 'unlink worked' ); |
317ea90d |
45 | |
46 | ok( !$^W, "-t doesn't enable regular warnings" ); |
36f064bc |
47 | |
48 | |
9685b823 |
49 | mkdir('ttdir'); |
50 | open(FH,'>','ttdir/ttest.pl')or DIE $!; |
36f064bc |
51 | print FH 'return 42'; |
52 | close FH or DIE $!; |
53 | |
54 | SKIP: { |
9685b823 |
55 | ($^O eq 'MSWin32') || skip('skip tainted do test with \ separator'); |
36f064bc |
56 | my $test = 0; |
9685b823 |
57 | $test = do '.\ttdir/ttest.pl'; |
58 | is($test, 42, 'Could "do" .\ttdir/ttest.pl'); |
36f064bc |
59 | } |
60 | { |
61 | my $test = 0; |
9685b823 |
62 | $test = do './ttdir/ttest.pl'; |
63 | is($test, 42, 'Could "do" ./ttdir/ttest.pl'); |
36f064bc |
64 | } |
9685b823 |
65 | unlink ('./ttdir/ttest.pl'); |
66 | rmdir ('ttdir'); |