This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Introduction of d_pseudofork
[perl5.git] / t / run / switcht.t
1 #!./perl -t
2
3 BEGIN {
4     chdir 't';
5     @INC = '../lib';
6     require './test.pl';
7 }
8
9 plan tests => 11;
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
17 is( ${^TAINT}, -1, '${^TAINT} == -1' );
18
19 my $out = `$Perl -le "print q(Hello)"`;
20 is( $out, "Hello\n",                      '`` worked' );
21 like( $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/;
34 ok( open(FILE, ">$file"),   'open >' ) or DIE $!;
35 print FILE "Stuff\n";
36 close FILE;
37 like( $warning, qr/^Insecure dependency in open $Tmsg/, 'open > taint warn' );
38 ok( -e $file,   '   file written' );
39
40 unlink($file);
41 like( $warning, qr/^Insecure dependency in unlink $Tmsg/,
42                                                   'unlink() taint warn' );
43 ok( !-e $file,  'unlink worked' );
44
45 ok( !$^W,   "-t doesn't enable regular warnings" );