Make the va_copy() test not to be so talkative.
[p5sagit/p5-mst-13.2.git] / t / lib / ftmp-tempfile.t
CommitLineData
51fc852f 1#!/usr/local/bin/perl -w
262eb13a 2# Test for File::Temp - tempfile function
3
e2cf2bdb 4BEGIN {
5 chdir 't' if -d 't';
20822f61 6 @INC = '../lib';
e2cf2bdb 7 require Test; import Test;
51fc852f 8 plan(tests => 16);
e2cf2bdb 9}
10
262eb13a 11use strict;
262eb13a 12use File::Spec;
262eb13a 13
14# Will need to check that all files were unlinked correctly
51fc852f 15# Set up an END block here to do it
16
17# Arrays containing list of dirs/files to test
18my (@files, @dirs, @still_there);
19
20# And a test for files that should still be around
21# These are tidied up
22END {
23 foreach (@still_there) {
24 ok( -f $_ );
25 ok( unlink( $_ ) );
26 ok( !(-f $_) );
27 }
28}
262eb13a 29
30# Loop over an array hoping that the files dont exist
1c19c868 31END { foreach (@files) { ok( !(-e $_) )} }
262eb13a 32
33# And a test for directories
51fc852f 34END { foreach (@dirs) { ok( !(-d $_) )} }
1c19c868 35
36# Need to make sure that the END blocks are setup before
37# the ones that File::Temp configures since END blocks are evaluated
38# in revers order and we need to check the files *after* File::Temp
39# removes them
40use File::Temp qw/ tempfile tempdir/;
41
42# Now we start the tests properly
43ok(1);
262eb13a 44
45
46# Tempfile
47# Open tempfile in some directory, unlink at end
48my ($fh, $tempfile) = tempfile(
49 UNLINK => 1,
50 SUFFIX => '.txt',
51 );
52
53ok( (-f $tempfile) );
54push(@files, $tempfile);
55
56# TEMPDIR test
57# Create temp directory in current dir
58my $template = 'tmpdirXXXXXX';
59print "# Template: $template\n";
60my $tempdir = tempdir( $template ,
61 DIR => File::Spec->curdir,
62 CLEANUP => 1,
63 );
64
65print "# TEMPDIR: $tempdir\n";
66
67ok( (-d $tempdir) );
68push(@dirs, $tempdir);
69
70# Create file in the temp dir
71($fh, $tempfile) = tempfile(
72 DIR => $tempdir,
73 UNLINK => 1,
74 SUFFIX => '.dat',
75 );
76
77print "# TEMPFILE: Created $tempfile\n";
78
79ok( (-f $tempfile));
80push(@files, $tempfile);
81
82# Test tempfile
83# ..and again
84($fh, $tempfile) = tempfile(
85 DIR => $tempdir,
86 );
87
88
89ok( (-f $tempfile ));
90push(@files, $tempfile);
91
92print "# TEMPFILE: Created $tempfile\n";
93
94# and another (with template)
95
96($fh, $tempfile) = tempfile( 'helloXXXXXXX',
97 DIR => $tempdir,
98 UNLINK => 1,
99 SUFFIX => '.dat',
100 );
101
102print "# TEMPFILE: Created $tempfile\n";
103
104ok( (-f $tempfile) );
105push(@files, $tempfile);
106
51fc852f 107
108# Create a temporary file that should stay around after
109# it has been closed
110($fh, $tempfile) = tempfile( 'permXXXXXXX', UNLINK => 0 );
111print "# TEMPFILE: Created $tempfile\n";
112ok( -f $tempfile );
113ok( close( $fh ) );
114push( @still_there, $tempfile); # check at END
115
1c19c868 116# Now END block will execute to test the removal of directories
117