X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=catagits%2FCatalyst-Runtime.git;a=blobdiff_plain;f=t%2Funit_stats.t;h=3fc08d0b80354ff743a0100cacd9cb4597c99d1a;hp=e46baf43704b44539d6c5345ec67a9888b48f9e1;hb=4e93cdb6d9403718baff430bc1bdc3245aa5236f;hpb=2f3812528068bc1d9f7840067f0c03d36cd47e6d diff --git a/t/unit_stats.t b/t/unit_stats.t index e46baf4..3fc08d0 100644 --- a/t/unit_stats.t +++ b/t/unit_stats.t @@ -1,16 +1,19 @@ -#!/usr/bin/perl - +# HARNESS-NO-PRELOAD use strict; use warnings; -use Test::More tests => 12; -use Time::HiRes qw/gettimeofday/; +use Test::More tests => 13; +use Time::HiRes (); use Tree::Simple; my @fudge_t = ( 0, 0 ); BEGIN { no warnings; *Time::HiRes::gettimeofday = sub () { return @fudge_t }; + my $original_tv_interval = \&Time::HiRes::tv_interval; + *Time::HiRes::tv_interval = sub ($;@) { + return $original_tv_interval->($_[0], $_[1] || [Time::HiRes::gettimeofday()]); + }; } BEGIN { use_ok("Catalyst::Stats") }; @@ -19,6 +22,8 @@ BEGIN { use_ok("Catalyst::Stats") }; my $stats = Catalyst::Stats->new; is (ref($stats), "Catalyst::Stats", "new"); + is_deeply([ $stats->created ], [0, 0], "created time"); + my @expected; # level, string, time $fudge_t[0] = 1; @@ -69,6 +74,10 @@ BEGIN { use_ok("Catalyst::Stats") }; $stats->profile(comment => "interleave 2"); push(@expected, [ 4, "- interleave 2", 0.2, 0 ]); + $fudge_t[1] = 550000; + $stats->profile(begin => "begin with no end"); + push(@expected, [ 4, "begin with no end", 0.05, 1 ]); + $fudge_t[1] = 600000; # end badly nested block time $stats->profile(end => "badly nested block 1"); @@ -85,6 +94,8 @@ BEGIN { use_ok("Catalyst::Stats") }; my @report = $stats->report; is_deeply(\@report, \@expected, "report"); + # print scalar($stats->report); + is ($stats->elapsed, 14, "elapsed"); }