xref: /onnv-gate/usr/src/cmd/perl/5.8.4/distrib/lib/Memoize/t/expfile.t (revision 0:68f95e015346)
1*0Sstevel@tonic-gate#!/usr/bin/perl
2*0Sstevel@tonic-gate
3*0Sstevel@tonic-gateuse lib '..';
4*0Sstevel@tonic-gateuse Memoize;
5*0Sstevel@tonic-gate
6*0Sstevel@tonic-gatemy $n = 0;
7*0Sstevel@tonic-gate$|=1;
8*0Sstevel@tonic-gate
9*0Sstevel@tonic-gate
10*0Sstevel@tonic-gateif (-e '.fast') {
11*0Sstevel@tonic-gate  print "1..0\n";
12*0Sstevel@tonic-gate  exit 0;
13*0Sstevel@tonic-gate}
14*0Sstevel@tonic-gate
15*0Sstevel@tonic-gateprint "1..12\n";
16*0Sstevel@tonic-gate# (1)
17*0Sstevel@tonic-gate++$n; print "ok $n\n";
18*0Sstevel@tonic-gate
19*0Sstevel@tonic-gatemy $READFILE_CALLS = 0;
20*0Sstevel@tonic-gatemy $FILE = './TESTFILE';
21*0Sstevel@tonic-gate
22*0Sstevel@tonic-gatesub writefile {
23*0Sstevel@tonic-gate  my $FILE = shift;
24*0Sstevel@tonic-gate  open F, "> $FILE" or die "Couldn't write temporary file $FILE: $!";
25*0Sstevel@tonic-gate  print F scalar(localtime), "\n";
26*0Sstevel@tonic-gate  close F;
27*0Sstevel@tonic-gate}
28*0Sstevel@tonic-gate
29*0Sstevel@tonic-gatesub readfile {
30*0Sstevel@tonic-gate  $READFILE_CALLS++;
31*0Sstevel@tonic-gate  my $FILE = shift;
32*0Sstevel@tonic-gate  open F, "< $FILE" or die "Couldn't write temporary file $FILE: $!";
33*0Sstevel@tonic-gate  my $data = <F>;
34*0Sstevel@tonic-gate  close F;
35*0Sstevel@tonic-gate  $data;
36*0Sstevel@tonic-gate}
37*0Sstevel@tonic-gate
38*0Sstevel@tonic-gaterequire Memoize::ExpireFile;
39*0Sstevel@tonic-gate# (2)
40*0Sstevel@tonic-gate++$n; print "ok $n\n";
41*0Sstevel@tonic-gate
42*0Sstevel@tonic-gatetie my %cache => 'Memoize::ExpireFile';
43*0Sstevel@tonic-gatememoize 'readfile',
44*0Sstevel@tonic-gate    SCALAR_CACHE => [HASH => \%cache],
45*0Sstevel@tonic-gate    LIST_CACHE => 'FAULT'
46*0Sstevel@tonic-gate    ;
47*0Sstevel@tonic-gate
48*0Sstevel@tonic-gate# (3)
49*0Sstevel@tonic-gate++$n; print "ok $n\n";
50*0Sstevel@tonic-gate
51*0Sstevel@tonic-gate# (4)
52*0Sstevel@tonic-gatewritefile($FILE);
53*0Sstevel@tonic-gate++$n; print "ok $n\n";
54*0Sstevel@tonic-gatesleep 4;
55*0Sstevel@tonic-gate
56*0Sstevel@tonic-gate# (5-6)
57*0Sstevel@tonic-gatemy $t1 = readfile($FILE);
58*0Sstevel@tonic-gate++$n; print "ok $n\n";
59*0Sstevel@tonic-gate++$n; print ((($READFILE_CALLS == 1) ? '' : 'not '), "ok $n\n");
60*0Sstevel@tonic-gate
61*0Sstevel@tonic-gate# (7-9)
62*0Sstevel@tonic-gatemy $t2 = readfile($FILE);
63*0Sstevel@tonic-gate++$n; print "ok $n\n";
64*0Sstevel@tonic-gate++$n; print ((($READFILE_CALLS == 1) ? '' : 'not '), "ok $n\n");
65*0Sstevel@tonic-gate++$n; print ((($t1 eq $t2) ? '' : 'not '), "ok $n\n");
66*0Sstevel@tonic-gate
67*0Sstevel@tonic-gate# (10-12)
68*0Sstevel@tonic-gatesleep 4;
69*0Sstevel@tonic-gatewritefile($FILE);
70*0Sstevel@tonic-gatemy $t3 = readfile($FILE);
71*0Sstevel@tonic-gate++$n; print "ok $n\n";
72*0Sstevel@tonic-gate++$n; print ((($READFILE_CALLS == 2) ? '' : 'not '), "ok $n\n");
73*0Sstevel@tonic-gate++$n; print ((($t1 ne $t3) ? '' : 'not '), "ok $n\n");
74*0Sstevel@tonic-gate
75*0Sstevel@tonic-gateEND { 1 while unlink $FILE }
76