This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Added t/test_pl/tempfile.t
authorBrad Gilbert <b2gills@gmail.com>
Sun, 16 Sep 2012 20:28:01 +0000 (15:28 -0500)
committerFather Chrysostomos <sprout@cpan.org>
Tue, 25 Sep 2012 21:35:13 +0000 (14:35 -0700)
t/test_pl/tempfile.t [new file with mode: 0644]

diff --git a/t/test_pl/tempfile.t b/t/test_pl/tempfile.t
new file mode 100644 (file)
index 0000000..f384ba8
--- /dev/null
@@ -0,0 +1,39 @@
+#!./perl
+
+BEGIN {
+    chdir 't' if -d 't';
+    require './test.pl';
+}
+use strict;
+
+my $prefix = 'tmp'.$$;
+
+sub skip_files{
+  my($skip,$to) = @_;
+  note("skipping $skip filenames so that the next one will end with $to.");
+  tempfile() for 1..$skip;
+}
+
+note("skipping the first filename because it is taken for use by _fresh_perl()");
+
+is( tempfile(), "${prefix}B");
+is( tempfile(), "${prefix}C");
+
+skip_files(22,'Z');
+
+is( tempfile(), "${prefix}Z", 'Last single letter filename');
+is( tempfile(), "${prefix}AA", 'First double letter filename');
+
+skip_files(24,'AZ');
+
+is( tempfile(), "${prefix}AZ");
+is( tempfile(), "${prefix}BA");
+
+skip_files(26 * 24 + 24,'ZZ');
+
+is( tempfile(), "${prefix}ZZ", 'Last available filename');
+ok( !eval{tempfile()}, 'Should bail after Last available filename' );
+my $err = "$@";
+like( $err, qr{^Can't find temporary file name starting}, 'check error string' );
+
+done_testing();