1#!./perl -t
2
3BEGIN {
4    chdir 't';
5    @INC = '../lib';
6    require './test.pl';
7}
8
9plan tests => 11;
10
11my $Perl = which_perl();
12
13my $warning;
14local $SIG{__WARN__} = sub { $warning = join "\n", @_; };
15my $Tmsg = 'while running with -t switch';
16
17is( ${^TAINT}, -1, '${^TAINT} == -1' );
18
19my $out = `$Perl -le "print q(Hello)"`;
20is( $out, "Hello\n",                      '`` worked' );
21like( $warning, qr/^Insecure .* $Tmsg/, '    taint warn' );
22
23{
24    no warnings 'taint';
25    $warning = '';
26    my $out = `$Perl -le "print q(Hello)"`;
27    is( $out, "Hello\n",                      '`` worked' );
28    is( $warning, '',                       '   no warnings "taint"' );
29}
30
31# Get ourselves a tainted variable.
32$file = $0;
33$file =~ s/.*/some.tmp/;
34ok( open(FILE, ">$file"),   'open >' ) or DIE $!;
35print FILE "Stuff\n";
36close FILE;
37like( $warning, qr/^Insecure dependency in open $Tmsg/, 'open > taint warn' );
38ok( -e $file,   '   file written' );
39
40unlink($file);
41like( $warning, qr/^Insecure dependency in unlink $Tmsg/,
42                                                  'unlink() taint warn' );
43ok( !-e $file,  'unlink worked' );
44
45ok( !$^W,   "-t doesn't enable regular warnings" );
46