tempfile.t revision 1.1.1.1
1#!./perl
2
3BEGIN {
4    chdir 't' if -d 't';
5    require './test.pl';
6}
7use strict;
8
9my $prefix = 'tmp'.$$;
10
11sub skip_files{
12    my($skip,$to,$next) = @_;
13    my($last,$check);
14    my $cmp = $prefix . $to;
15
16    for( 1..$skip ){
17        $check = tempfile();
18        $last = $_;
19        if( $check eq $cmp && $_ != $skip ){
20            # let the next test pass
21            last;
22        }
23    }
24
25    my $common_mess = "skip $skip filenames to $to so that the next one will end with $next";
26    if( $last == $skip ){
27        if( $check eq $cmp ){
28            pass( $common_mess );
29        }else{
30            my($alpha) = $check =~ /\Atmp\d+([A-Z][A-Z]?)\Z/;
31            fail( $common_mess, "only skipped to $alpha" )
32        }
33    }else{
34        fail( $common_mess, "only skipped $last files" );
35    }
36}
37
38note("skipping the first filename because it is taken for use by _fresh_perl()");
39
40is( tempfile(), "${prefix}B");
41is( tempfile(), "${prefix}C");
42
43skip_files(22,'Y','Z');
44
45is( tempfile(), "${prefix}Z", 'Last single letter filename');
46is( tempfile(), "${prefix}AA", 'First double letter filename');
47
48skip_files(24,'AY','AZ');
49
50is( tempfile(), "${prefix}AZ");
51is( tempfile(), "${prefix}BA");
52
53skip_files(26 * 24 + 24,'ZY','ZZ');
54
55is( tempfile(), "${prefix}ZZ", 'Last available filename');
56ok( !eval{tempfile()}, 'Should bail after Last available filename' );
57my $err = "$@";
58like( $err, qr{^Can't find temporary file name starting}, 'check error string' );
59
60done_testing();
61