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