Fix test failures when running under CATALYST_DEBUG. RT#95358
Dagfinn Ilmari Mannsåker [Mon, 5 May 2014 20:54:43 +0000 (21:54 +0100)]
Changes
t/aggregate/live_engine_response_headers.t
t/lib/TestLogger.pm
t/psgi-log.t

diff --git a/Changes b/Changes
index 86c8a1f..fa58fa2 100644 (file)
--- a/Changes
+++ b/Changes
@@ -2,6 +2,7 @@
 
   - Fix spelling, grammar and structural errors in POD
   - Remove redundant ->setup call in t/head_middleware.t RT#95361
+  - Fix test failures when running under CATALYST_DEBUG. RT#95358
 
 5.90064 - 2014-05-05
   - Fix for mindless broken tests on Win32 (Haarg++).
index a0663e1..6cf9fdc 100644 (file)
@@ -37,8 +37,8 @@ foreach my $method (qw(HEAD GET)) {
             'HEAD method content is empty' );
     }
     elsif ( $method eq 'GET' ) {
-        # method name is echo'd back in content-body, which
-        # accounts for difference in content length.  In normal
+        # method name is echo'd back in content-body (twice under debug),
+        # which accounts for difference in content length.  In normal
         # cases the Content-Length should be the same regardless
         # of whether it's a GET or HEAD request.
         SKIP:
@@ -46,8 +46,10 @@ foreach my $method (qw(HEAD GET)) {
             if ( $ENV{CATALYST_SERVER} ) {
                 skip "Using remote server", 2;
             }
+            my $diff = TestApp->debug ? 2 : 1;
             is( $response->header('Content-Length'),
-                $content_length - 1, 'Response Header Content-Length' );
+                $content_length - $diff, 'Response Header Content-Length' )
+                or diag $response->content;
             is( length($response->content),
                 $response->header('Content-Length'),
                 'GET method content' );
index f1dc7e6..6c1a26e 100644 (file)
@@ -3,6 +3,7 @@ use strict;
 use warnings;
 
 our @LOGS;
+our @ILOGS;
 our @ELOGS;
 
 sub new {
@@ -14,6 +15,11 @@ sub debug {
     push(@LOGS, shift());
 }
 
+sub info {
+    shift;
+    push(@ILOGS, shift());
+}
+
 sub warn {
     shift;
     push(@ELOGS, shift());
index e010d07..9e269c3 100644 (file)
@@ -46,6 +46,8 @@ use HTTP::Request::Common;
     no Moose;
 }
 
+my $cmp = TestApp->debug ? '>=' : '==';
+
 #subtest "psgi.errors" => sub
 {
 
@@ -69,8 +71,8 @@ use HTTP::Request::Common;
         my $cb = shift;
         my $res = $cb->(GET "/log/debug");
         my @logs = $handle->logs;
-        is(scalar(@logs), 1, "psgi.errors: one event output");
-        like($logs[0], qr/debug$/, "psgi.errors: event matches test data");
+        cmp_ok(scalar(@logs), $cmp, 1, "psgi.errors: one event output");
+        like($logs[0], qr/debug$/m, "psgi.errors: event matches test data");
     };
 };
 
@@ -96,8 +98,9 @@ use HTTP::Request::Common;
     test_psgi $app, sub {
         my $cb = shift;
         my $res = $cb->(GET "/log/debug");
-        is(scalar(@logs), 1, "psgix.logger: one event logged");
-        is_deeply($logs[0], { level => 'debug', message => "debug" }, "psgix.logger: right stuff");
+        cmp_ok(scalar(@logs), $cmp, 1, "psgix.logger: one event logged");
+        is(scalar(grep { $_->{level} eq 'debug' and $_->{message} eq 'debug' } @logs),
+           1, "psgix.logger: right stuff");
     };
 };