Make sure that tempfile() in t/test.pl removes the temp files
authorBrad Gilbert <b2gills@gmail.com>
Tue, 4 Feb 2014 17:55:28 +0000 (11:55 -0600)
committerTony Cook <tony@develop-help.com>
Thu, 13 Feb 2014 02:53:28 +0000 (13:53 +1100)
Run a program within t/test_pl/tempfile.t that uses tempfile() to make
sure that the temp file is removed when the tests are done.

t/test_pl/tempfile.t

index 881ecbf..d507d60 100644 (file)
@@ -75,4 +75,19 @@ ok( !eval{tempfile()}, 'Should bail after Last available filename' );
 my $err = "$@";
 like( $err, qr{^Can't find temporary file name starting}, 'check error string' );
 
+{
+    my $returned = runperl( progs => [
+        'require q[./test.pl];',
+        'my $t = tempfile();',
+        'print qq[$t|];',
+        'print open(FH,q[>],$t) ? qq[ok|] : qq[not ok|] ;',
+        'print -e $t ? qq[ok|] : qq[not ok|];',
+    ] );
+    my($filename,$opened,$existed) = split /\|/, $returned;
+
+    is( $opened, 'ok', "$filename created" );
+    is( $existed, 'ok', "$filename did exist" );
+    ok( !-e $filename, "$filename doesn't exist now" );
+}
+
 done_testing();