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