5 unshift @INC, '../lib';
8 # Test for File::Temp - Security levels
10 # Some of the security checking will not work on all platforms
11 # Test a simple open in the cwd and tmpdir foreach of the
16 BEGIN { plan tests => 13}
19 use File::Temp qw/ tempfile unlink0 /;
22 # The high security tests must currently be skipped on Windows
23 my $skipplat = ( $^O eq 'MSWin32' ? 1 : 0 );
25 # Can not run high security tests in perls before 5.6.0
26 my $skipperl = ($] < 5.006 ? 1 : 0 );
28 # Determine whether we need to skip things and why
31 $skip = "Skip Not supported on this platform";
33 $skip = "Skip Perl version must be v5.6.0 for these tests";
37 print "# We will be skipping some tests : $skip\n" if $skip;
39 # start off with basic checking
41 File::Temp->safe_level( File::Temp::STANDARD );
43 print "# Testing with STANDARD security...\n";
49 File::Temp->safe_level( File::Temp::MEDIUM )
52 print "# Testing with MEDIUM security...\n";
54 # Now we need to start skipping tests
55 &test_security($skip);
59 File::Temp->safe_level( File::Temp::HIGH )
62 print "# Testing with HIGH security...\n";
64 &test_security($skip);
68 # Subroutine to open two temporary files.
69 # one is opened in the current dir and the other in the temp dir
73 # Read in the skip flag
76 # If we are skipping we need to simply fake the correct number
77 # of tests -- we dont use skip since the tempfile() commands will
78 # fail with MEDIUM/HIGH security before the skip() command would be run
84 # plus we need an end block so the tests come out in the right order
85 eval q{ END { skip($skip,1); skip($skip,1) } 1; } || die;
91 # End blocks are evaluated in reverse order
92 # If I want to check that the file was unlinked by the autmoatic
93 # feature of the module I have to set up the end block before
95 # Use quoted end block to retain access to lexicals
98 eval q{ END { foreach (@files) { ok( !(-e $_) )} } 1; } || die;
101 my $template = "temptestXXXXXXXX";
102 my ($fh1, $fname1) = tempfile ( $template,
103 DIR => File::Spec->curdir,
106 print "# Fname1 = $fname1\n";
110 my ($fh2, $fname2) = tempfile ($template, UNLINK => 1 );
114 # Store filenames for the end block
115 push(@files, $fname1, $fname2);