Util/t/page_is_current.t

filter: Statementstmt 97.8% 45 / 46 Branchbran 44.4% 8 / 18 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 100% 6 / 6 Podpod n/a totaltotal 78.6% 59 / 75 CC 3 SCAR 4.3
CC
3
Cov
79%
END
2.1
next_sec
2.0
BEGIN
1.0
CRAP 1.5
« Report/t/nochecking.t ↑ Summary Util/t/labrea_whoami.t »
1 # Before `make install' is performed this script should be runnable with
2 # `make test'. After `make install' it should work as erl test.pl'
3  
4 ######################### We start with some black magic to print on failure.
5  
6 # Change 1..1 below to 1..last_test_to_print .
7 # (It may become useful if the test is moved to ./t subdirectory.)
8  
9 1 ▶BEGIN { $| = 1; print "1..6\n"; }
Subroutine BEGIN: called CC=1 SCAR=0.0
10 1 ▶END {print "not ok 1\n" unless $loaded;}
Subroutine END: called CC=2 SCAR=7.6
Branch: 1 branch
BranchTrueFalseTotal
unless $loaded 0 1 1
11 1 ▶use LaBrea::Tarpit::Util qw(
Subroutine BEGIN: called CC=1 SCAR=0.0
12 page_is_current
13 1 );
14 1 $loaded = 1;
15 1 print "ok 1\n";
16  
17 1 $test = 2;
18  
19 1 umask 027;
20 1 ▶if (-d 'tmp') { # clean up previous test runs
Branch: 1 branch
BranchTrueFalseTotal
if (-d 'tmp') { } 1 0 1
21 1 opendir(T,'tmp');
22 1 @_ = grep(!/^\./, readdir(T));
23 1 closedir T;
24 1 foreach(@_) {
25 2 unlink "tmp/$_";
26 }
27 } else {
28 0 ▶ mkdir 'tmp', 0750 unless (-e 'tmp' && -d 'tmp');
Branch: 1 branch
BranchTrueFalseTotal
unless -e "tmp" and -d "tmp" 0 0 0
Condition0%0/3
-e "tmp" and -d "tmp"
!ll&&!rl&&r
000
MC/DC0%0/2
-e "tmp" and -d "tmp"
-e "tmp" -d "tmp"
Truth table0%0/3
A and B
A= -e "tmp"B= -d "tmp"
ABresult
0X0
100
111
29 }
30  
31 5 ▶sub ok {
Subroutine ok: called CC=1 SCAR=0.0
32 5 print "ok $test\n";
33 5 ++$test;
34 }
35 1 ▶sub next_sec {
Subroutine next_sec: called CC=2 SCAR=7.0
36 1 my ($then) = @_;
37 1 my $now;
38 # wait for epoch
39 1 ▶ do { select(undef,undef,undef,0.1); $now = time }
Branch: 1 branch
BranchTrueFalseTotal
$then >= $now and do { do { select undef, undef, undef, "0.1"; $now = time } } 0 1 1
40 while ( $then >= $now );
41 1 $now;
42 }
43  
44 1 my $src = 'tmp/test.src';
45  
46 ## test 2
47 ## test for non-existent file
48 1 ▶print "found non-existent file\nnot "
Branch: 1 branch
BranchTrueFalseTotal
if page_is_current(0, $src) 0 1 1
49 if page_is_current(0,$src);
50 1 &ok;
51  
52 1 my $ctime = &next_sec(time);
53  
54 ## test 3
55 ## create test file
56 1 ▶print "failed to open $src\nnot "
Branch: 1 branch
BranchTrueFalseTotal
unless open F, '>' . $src 0 1 1
57 unless open(F,'>'.$src); # make the file
58 1 &ok;
59  
60 1 close F;
61  
62 1 my $file_time = page_is_current($ctime,$src);
63  
64 ## test 4
65 ## file should equal ctime
66 1 ▶print "expected $ctime\nne response $file_time\nnot "
Branch: 1 branch
BranchTrueFalseTotal
unless $file_time == $ctime 0 1 1
67 unless $file_time == $ctime;
68 1 &ok;
69  
70 1 --$ctime; # older
71 1 $file_time = page_is_current($ctime,$src);
72  
73 ## test 5
74 1 ▶print "expected $ctime\nne response $file_time\nnot "
Branch: 1 branch
BranchTrueFalseTotal
unless $file_time > $ctime 0 1 1
75 unless $file_time > $ctime;
76 1 &ok;
77  
78 1 $ctime +=2; # expire
79 1 $file_time = page_is_current($ctime,$src);
80  
81 ## test 6
82 1 ▶print "failed to expire\nnot "
Branch: 1 branch
BranchTrueFalseTotal
if $file_time 0 1 1
83 if $file_time;
84 1 &ok;
« Report/t/nochecking.t ↑ Summary Util/t/labrea_whoami.t »