6 use Test::More tests => 6;
7 use Time::HiRes qw/gettimeofday/;
9 my @fudge_t = ( 0, 0 );
12 *Time::HiRes::gettimeofday = sub () { return @fudge_t };
15 BEGIN { use_ok("Catalyst::Stats") };
18 my $stats = Catalyst::Stats->new;
19 is (ref($stats), "Catalyst::Stats", "new");
21 my @expected; # level, string, time
24 ok($stats->profile("single comment arg"), "profile");
25 push(@expected, [ 0, "- single comment arg", 1, 0 ]);
28 $stats->profile(comment => "hash comment arg");
29 push(@expected, [ 0, "- hash comment arg", 2, 0 ]);
32 $stats->profile(begin => "block", comment => "start block");
33 push(@expected, [ 0, "block - start block", 4, 1 ]);
37 $stats->profile("inside block");
38 push(@expected, [ 1, "- inside block", 1, 0 ]);
41 my $uid = $stats->profile(begin => "nested block", uid => "boo");
42 push(@expected, [ 1, "nested block", 0.7, 1 ]);
43 is ($uid, "boo", "set UID");
47 $stats->profile("this shouldn't appear");
51 $stats->profile(begin => "double nested block 1");
52 push(@expected, [ 2, "double nested block 1", 0.2, 1 ]);
54 $stats->profile(comment => "attach to uid", parent => $uid);
57 $stats->profile(begin => "badly nested block 1");
58 push(@expected, [ 3, "badly nested block 1", 0.35, 1 ]);
61 $stats->profile(comment => "interleave 1");
62 push(@expected, [ 4, "- interleave 1", 0.05, 0 ]);
64 $fudge_t[1] = 400000; # end double nested block time
65 $stats->profile(end => "double nested block 1");
68 $stats->profile(comment => "interleave 2");
69 push(@expected, [ 4, "- interleave 2", 0.2, 0 ]);
71 $fudge_t[1] = 600000; # end badly nested block time
72 $stats->profile(end => "badly nested block 1");
74 $fudge_t[1] = 800000; # end nested block time
75 $stats->profile(end => "nested block");
77 $fudge_t[0] = 14; # end block time
79 $stats->profile(end => "block", comment => "end block");
81 push(@expected, [ 2, "- attach to uid", 0.1, 0 ]);
84 my @report = $stats->report;
85 is_deeply(\@report, \@expected, "report");
87 is ($stats->elapsed, 14, "elapsed");