App-JobLog
view release on metacpan or search on metacpan
#!/usr/bin/perl
#
# some tests that collect the output of commands via App::Cmd::Tester
use 5.006;
use strict;
use warnings;
use autodie;
use File::Path qw(remove_tree);
use File::Temp ();
use App::JobLog;
use App::JobLog::Config qw(log DIRECTORY);
use App::JobLog::Log::Line;
use App::JobLog::Log;
use App::JobLog::Time qw(tz);
use DateTime;
use File::Spec;
use IO::All -utf8;
use FileHandle;
use DateTime::TimeZone;
use POSIX qw(tzset);
use Test::More;
use App::Cmd::Tester;
use Test::Fatal;
# create a working directory
my $dir = File::Temp->newdir();
$ENV{ DIRECTORY() } = $dir;
# use a constant time zone so as to avoid crafting data to fit various datelight savings time adjustments
$ENV{'TZ'} = 'America/New_York';
tzset();
$App::JobLog::Config::tz =
DateTime::TimeZone->new( name => 'America/New_York' );
subtest 'basic test' => sub {
# make a big log
my $log = App::JobLog::Log->new;
my $start = make_date(qw(2011 1 1 0 0 0));
my $end = $start->clone->add( months => 1 );
my $t = $start->clone;
my $count = 1;
while ( $t <= $end ) {
$log->append_event( time => $t, description => 'foo' . $count++ );
$t->add( hours => 6 );
}
my $result = test_app( 'App::JobLog' => [qw(summary -W 2011/1)] );
is( $result->error, undef, 'threw no exceptions' );
};
subtest 'note summary' => sub {
# make a big log
'' > io log;
my $log = App::JobLog::Log->new;
my $start = make_date(qw(2011 1 1 0 0 0));
my $end = $start->clone->add( months => 1 );
my $t = $start->clone;
my $count = 1;
while ( $t <= $end ) {
my $method = $count % 2 ? 'append_event' : 'append_note';
$log->$method( time => $t, description => 'foo' . $count++ );
$t->add( hours => 6 );
}
my $result = test_app( 'App::JobLog' => [qw(summary -W --notes 2011/1)] );
is( $result->error, undef, 'threw no exceptions' );
like( $result->stdout, qr/foo/, 'found some notes' );
test_app( 'App::JobLog' => [qw(note testing)] );
$result = test_app( 'App::JobLog' => [qw(summary -W --notes today)] );
like( $result->stdout, qr/testing/, 'found appended note' );
};
subtest 'tags' => sub {
# make a big log
'' > io log;
my $log = App::JobLog::Log->new;
my $d = make_date(qw(2011 1 1 0 0 0));
$log->append_event( time => $d, tags => ['description'] );
$log->append_event( time => $d->clone->add( minutes => 1 ), done => 1 );
$d->add( days => 1 );
$log->append_note( time => $d, tags => ['note'] );
my $result = test_app( 'App::JobLog' => [qw(tags)] );
( run in 1.322 second using v1.01-cache-2.11-cpan-54e63673c56 )