From: Tyler Riddle Date: Fri, 7 Dec 2012 17:49:25 +0000 (-0800) Subject: added tests for the logging class X-Git-Tag: v0.003001_01~37 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=c5133f85c8c09b6c705bfaf172c43b689020da81;p=scpubgit%2FObject-Remote.git added tests for the logging class --- diff --git a/t/lib/ORFeedbackLogger.pm b/t/lib/ORFeedbackLogger.pm new file mode 100644 index 0000000..9a0ac16 --- /dev/null +++ b/t/lib/ORFeedbackLogger.pm @@ -0,0 +1,32 @@ +package ORFeedbackLogger; + +use Test::More; +use Moo; + +extends 'Object::Remote::Logging::Logger'; + +has feedback_output => (is => 'rw' ); +has feedback_input => ( is => 'rw' ); + +sub reset { + my ($self) = @_; + $self->feedback_output(undef); + $self->feedback_input(undef); + + ok(! defined $self->feedback_output && ! defined $self->feedback_input, 'Reset successful'); +} + +sub _log { + my $self = shift; + + $self->feedback_input([@_]); + + $self->SUPER::_log(@_); +} + +sub _output { + my ($self, $rendered) = @_; + $self->feedback_output($rendered); +} + +1; diff --git a/t/logging.t b/t/logging.t new file mode 100644 index 0000000..4375cf9 --- /dev/null +++ b/t/logging.t @@ -0,0 +1,38 @@ +use strictures 1; +use Test::More; + +$ENV{OBJECT_REMOTE_TEST_LOGGER} = 1; + +BEGIN { + use Object::Remote::Logging qw( :log :dlog router arg_levels ); + is($Object::Remote::Logging::DID_INIT, 1, 'using logging class initializes it'); +} + +my $router = router(); +isa_ok($router, 'Object::Remote::Logging::Router'); +is($router, router(), 'Router object is a singleton'); + +my $levels = arg_levels(); +is(ref($levels), 'ARRAY', 'arg_levels returns array reference'); +ok(scalar(@$levels) > 0, 'arg_levels has at least one level in it'); + +#adds some noise into the string that's not significant just to be more thorough +my $selections_string = "Acme::Matt::Daemon \t *\t\t-Acme::POE::Knee"; +my %parsed_selections = Object::Remote::Logging::_parse_selections($selections_string); +my $selections_match = { '*' => 1, 'Acme::Matt::Daemon' => 1, 'Acme::POE::Knee' => 0 }; +is_deeply(\%parsed_selections, $selections_match, 'Selections parsed successfully' ); + +require 't/lib/ORFeedbackLogger.pm'; +my $logger = ORFeedbackLogger->new(level_names => $levels, min_level => 'trace'); +isa_ok($logger, 'ORFeedbackLogger'); +$router->connect($logger); + +$logger->reset; +log_info { "The quick brown fox jumped" }; +is($logger->feedback_output, "info: The quick brown fox jumped\n", 'log_info works'); + +$logger->reset; +Dlog_verbose { "over the lazy dog's $_" } 'back'; +is($logger->feedback_output, "verbose: over the lazy dog's \"back\"\n", 'Dlog_verbose works'); + +done_testing; \ No newline at end of file