From 31cb373d14e7fd0731e096f68ca0faf331f0cd77 Mon Sep 17 00:00:00 2001 From: Chris Kirke Date: Wed, 30 Dec 2015 23:21:09 -0600 Subject: [PATCH] more test coverage for Stats.pm --- lib/CHI/t/Stats.pm | 41 +++++++++++++++++++++++++++++++++++++++++ t/Stats.t | 3 +++ 2 files changed, 44 insertions(+) create mode 100644 lib/CHI/t/Stats.pm create mode 100644 t/Stats.t diff --git a/lib/CHI/t/Stats.pm b/lib/CHI/t/Stats.pm new file mode 100644 index 0000000..85579b4 --- /dev/null +++ b/lib/CHI/t/Stats.pm @@ -0,0 +1,41 @@ +package CHI::t::Stats; + +use strict; +use warnings; + +use Log::Any::Test; +use Log::Any qw($log); +use IO::Scalar; +use CHI::Test; +use base qw(CHI::Test::Class); + +sub test_stats : Tests { + + # use Log::Any::Test to avoid temporary files for stats + ok( CHI->stats->enable(), 'enable stats' ); + my $cache = CHI->new( driver => 'Memory', global => 1, namespace => __PACKAGE__ ); + isa_ok( $cache, 'CHI::Driver' ); + $cache->set( 'a', 1 ); + ok( CHI->stats->flush(), 'flush stats' ); + CHI->stats->disable(); + + # direct call for coverage, no other references + CHI->stats->format_time( time() ); + + # process collected stats + my $msgs = $log->msgs; + note( explain( $msgs ) ); + my $buffer = ''; + my $fh = IO::Scalar->new( \$buffer ); + foreach my $msg (@{$msgs}) { + $fh->print( $msg->{'message'} . "\n" ); + } + $fh->setpos( 0 ); + my $results = CHI->stats->parse_stats_logs( $fh ); + note( explain( $results ) ); + + return; + +} + +1; diff --git a/t/Stats.t b/t/Stats.t new file mode 100644 index 0000000..f1571ce --- /dev/null +++ b/t/Stats.t @@ -0,0 +1,3 @@ +#!/usr/bin/perl +use CHI::t::Stats; +CHI::t::Stats->runtests;