From 5eccd97ae65fe4e91991cec8d8034c09786096c4 Mon Sep 17 00:00:00 2001 From: Brad Gilbert Date: Tue, 4 Feb 2014 10:37:02 -0600 Subject: [PATCH] Add register_tempfile() to t/test.pl This convenience function causes files to be removed in the same way that tempfile() does. It uses the same variable that tempfile() does, to catch and warn on any collisions. --- t/test.pl | 22 ++++++++++++++++++++++ t/test_pl/tempfile.t | 5 ++++- 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/t/test.pl b/t/test.pl index 6808127..fc64f4a 100644 --- a/t/test.pl +++ b/t/test.pl @@ -869,6 +869,28 @@ sub tempfile { die "Can't find temporary file name starting \"tmp$$\""; } +# register_tempfile - Adds a list of files to be removed at the end of the current test file +# Arguments : +# a list of files to be removed later + +# returns a count of how many file names were actually added + +# Reuses %tmpfiles so that tempfile() will also skip any files added here +# even if the file doesn't exist yet. + +sub register_tempfile { + my $count = 0; + for( @_ ){ + if( $tmpfiles{$_} ){ + _print_stderr "# Temporary file '$_' already added\n"; + }else{ + $tmpfiles{$_} = 1; + $count = $count + 1; + } + } + return $count; +} + # This is the temporary file for _fresh_perl my $tmpfile = tempfile(); diff --git a/t/test_pl/tempfile.t b/t/test_pl/tempfile.t index 5c0e76e..881ecbf 100644 --- a/t/test_pl/tempfile.t +++ b/t/test_pl/tempfile.t @@ -55,7 +55,10 @@ is( tempfile(), "${prefix}C"); } } -skip_files(20,'Y','Z'); +ok( register_tempfile("${prefix}F"), 'registered the next file with register_tempfile' ); +is( tempfile(), "${prefix}G", 'tempfile() properly skips files added with register_tempfile()' ); + +skip_files(18,'Y','Z'); is( tempfile(), "${prefix}Z", 'Last single letter filename'); is( tempfile(), "${prefix}AA", 'First double letter filename'); -- 2.7.4