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