From 8a448e8f96635a57f0291f93d29fc1258929a674 Mon Sep 17 00:00:00 2001 From: Colin Kuskie Date: Wed, 4 Aug 2010 19:57:44 -0700 Subject: [PATCH] Tests for methods that die. Strange tom-foolery to get $@ into the logged message... --- lib/WebGUI/Asset.pm | 14 +++++--------- t/Asset/dispatch.t | 14 ++++++++++++-- 2 files changed, 17 insertions(+), 11 deletions(-) diff --git a/lib/WebGUI/Asset.pm b/lib/WebGUI/Asset.pm index daf40b972..f894e35a6 100644 --- a/lib/WebGUI/Asset.pm +++ b/lib/WebGUI/Asset.pm @@ -572,11 +572,6 @@ the output from the www_view method. Any leftover part of the requested URL. -=head3 _view - -This option should only be used internally, when trying to call the view method when -the requested method has failed. - =cut sub dispatch { @@ -597,12 +592,11 @@ sub dispatch { my $output = eval { $self->$sub(); }; if (my $e = Exception::Class->caught('WebGUI::Error::ObjectNotFound::Template')) { #WebGUI::Error::ObjectNotFound::Template - warn "logged an exception"; $session->log->error(sprintf "%s templateId: %s assetId: %s", $e->error, $e->templateId, $e->assetId); } elsif ($@) { - warn "logged a warn: $@"; - $session->log->warn("Couldn't call method www_".$func." on asset for url: ".$session->url->getRequestedUrl." Root cause: ".$@); + my $message = $@; + $session->log->warn("Couldn't call method www_".$func." on asset for url: ".$session->url->getRequestedUrl." Root cause: ".$message); } return $output if $output || $viewing; ##No output, try the view method instead @@ -611,7 +605,9 @@ sub dispatch { $session->log->error(sprintf "%s templateId: %s assetId: %s", $e->error, $e->templateId, $e->assetId); } elsif ($@) { - $session->errorHandler->warn("Couldn't call method www_".$func." on asset for url: ".$session->url->getRequestedUrl." Root cause: ".$@); + warn "logged another warn: $@"; + my $message = $@; + $session->log->warn("Couldn't call method www_view on asset for url: ".$session->url->getRequestedUrl." Root cause: ".$@); } return $output; } diff --git a/t/Asset/dispatch.t b/t/Asset/dispatch.t index 94c9d3262..71e1b6787 100644 --- a/t/Asset/dispatch.t +++ b/t/Asset/dispatch.t @@ -66,6 +66,11 @@ sub www_brokenTemplate { ); } +sub www_dies { + my $self = shift; + die "...aside from that bullet\n"; +} + package main; my $tag = WebGUI::VersionTag->getWorking( $session ); @@ -74,7 +79,7 @@ WebGUI::Test->addToCleanup( $tag ); #---------------------------------------------------------------------------- # Tests -plan tests => 16; # Increment this number for each test you create +plan tests => 18; # Increment this number for each test you create #---------------------------------------------------------------------------- # Test dispatch @@ -136,7 +141,12 @@ $session->request->setup_body( { } ); WebGUI::Test->interceptLogging; is( $td->dispatch, "www_view", "if a query method throws a Template exception, view is returned instead" ); -is $WebGUI::Test::logger_error, 'Template not found templateId: This is a GUID assetId: '. $td->getId, 'logged an error'; +is $WebGUI::Test::logger_error, 'Template not found templateId: This is a GUID assetId: '. $td->getId, '... and logged an error'; +$session->request->setup_body( { + func => 'dies', +} ); +is( $td->dispatch, "www_view", "if a query method dies, view is returned instead" ); +is $WebGUI::Test::logger_warns, "Couldn't call method www_dies on asset for url: Root cause: ...aside from that bullet\n", '.. and logged a warn'; WebGUI::Test->restoreLogging; #vim:ft=perl