Add core test boilerplates
[p5sagit/p5-mst-13.2.git] / lib / FileCache / t / 02maxopen.t
1 #!./perl
2
3 BEGIN {
4    if( $ENV{PERL_CORE} ) {
5         chdir 't' if -d 't';
6         @INC = qw(../lib);
7     }
8 }
9
10 use FileCache maxopen=>2;
11 use Test;
12 use vars qw(@files);
13 BEGIN {
14     @files = qw(foo bar baz quux);
15     chdir 't' if -d 't';
16
17     #For tests within the perl distribution
18     @INC = '../lib' if -d '../lib';
19     END;
20     plan tests=>5;
21 }
22 END{
23   1 while unlink @files;
24 }
25
26 {# Test 2: that we actually adhere to maxopen
27   for my $path ( @files ){
28     cacheout $path;
29     print $path "$path 1\n";
30   }
31   
32   my @cat;
33   for my $path ( @files ){
34     ok(fileno($path) || $path =~ /^(?:foo|bar)$/);
35     next unless fileno($path);
36     print $path "$path 2\n";
37     close($path);
38     open($path, $path);
39     <$path>;
40     push @cat, <$path>;
41     close($path);
42   }
43   ok( grep(/^(?:baz|quux) 2$/, @cat) == 2 );
44 }