[Jifty-commit] r4044 - in Test-WWW-Declare: lib/Test/WWW lib/Test/WWW/Declare t

jifty-commit at lists.jifty.org jifty-commit at lists.jifty.org
Tue Sep 4 15:36:29 EDT 2007


Author: sartak
Date: Tue Sep  4 15:36:27 2007
New Revision: 4044

Added:
   Test-WWW-Declare/t/13-flowless.t
Modified:
   Test-WWW-Declare/   (props changed)
   Test-WWW-Declare/lib/Test/WWW/Declare.pm
   Test-WWW-Declare/lib/Test/WWW/Declare/Tester.pm
   Test-WWW-Declare/t/04-fail.t
   Test-WWW-Declare/t/11-nested-flow-error.t

Log:
 r40538 at onn:  sartak | 2007-09-04 15:36:11 -0400
 Let users define tests without using flow at all. This still needs some work.
 Improve error diagnostics.


Modified: Test-WWW-Declare/lib/Test/WWW/Declare.pm
==============================================================================
--- Test-WWW-Declare/lib/Test/WWW/Declare.pm	(original)
+++ Test-WWW-Declare/lib/Test/WWW/Declare.pm	Tue Sep  4 15:36:27 2007
@@ -217,6 +217,11 @@
     my $url = shift;
 
     mech()->get($url);
+    if (!$IN_FLOW)
+    {
+        $BUILDER->ok(mech->success, "navigated to $url");
+    }
+
     return if mech->success;
 
     Carp::croak mech->status
@@ -236,14 +241,23 @@
     my $type = shift;
 
     if ($type eq 'button') {
-        return mech()->click_button(value => $link);
+        my $ok = mech()->click_button(value => $link);
+        $ok = $ok->is_success if $ok;
+        my $verb = ref($link) eq 'Regexp' ? "matching " : "";
+        $BUILDER->ok($ok, "Clicked button $verb$link") if !$IN_FLOW;
+        return $ok;
     }
     else {
         if (ref $link ne 'Regexp') {
             Carp::croak "click doesn't know what to do with a link type of "
               . ref($link);
         }
-        return follow_link(text_regex => $link);
+        my $ok;
+        my $response = mech()->follow_link(text_regex => $link);
+        $ok = 1 if $response && $response->is_success;
+        $BUILDER->ok($ok, "Clicked link matching $link") if !$IN_FLOW;
+        Carp::croak($response ? $response->as_string : "No link matching $link found") if !$ok;
+        return $ok;
     }
 }
 
@@ -321,7 +335,13 @@
         Carp::croak "No \$args{match} (yes this error needs to be fixed)";
     }
 
-    return 1 if ($match ? 1 : 0) ^ $args{negative};
+    my $ok = ($match ? 1 : 0) ^ $args{negative};
+    if (!$IN_FLOW) {
+        $BUILDER->ok($ok, join(' ', @output));
+        return $ok;
+    }
+
+    return 1 if $ok;
     Carp::croak join(' ', @output);
 }
 

Modified: Test-WWW-Declare/lib/Test/WWW/Declare/Tester.pm
==============================================================================
--- Test-WWW-Declare/lib/Test/WWW/Declare/Tester.pm	(original)
+++ Test-WWW-Declare/lib/Test/WWW/Declare/Tester.pm	Tue Sep  4 15:36:27 2007
@@ -101,6 +101,7 @@
 our $PORT = 12321;
 our $SERVER = Test::WWW::Declare::Tester::Server->new($PORT);
 our $PID = $SERVER->background or die "Cannot start the server";
+sleep 1;
 
 sub import_extra {
     Test::Tester->export_to_level(2);

Modified: Test-WWW-Declare/t/04-fail.t
==============================================================================
--- Test-WWW-Declare/t/04-fail.t	(original)
+++ Test-WWW-Declare/t/04-fail.t	Tue Sep  4 15:36:27 2007
@@ -29,6 +29,6 @@
 is($results[0]{name}, "basic connectivity", "1st test was flow");
 is($results[1]{name}, "should be run", "2nd test was flow");
 
-like($results[0]{diag}, qr/Content does not match \(?.*?\) at /, "reasonable error message for 'content should match' failing");
+like($results[0]{diag}, qr/404 Not Found/, "reasonable error message for 'content should match' failing");
 is($results[1]{diag}, '', "no errors/warnings on the second flow");
 

Modified: Test-WWW-Declare/t/11-nested-flow-error.t
==============================================================================
--- Test-WWW-Declare/t/11-nested-flow-error.t	(original)
+++ Test-WWW-Declare/t/11-nested-flow-error.t	Tue Sep  4 15:36:27 2007
@@ -36,5 +36,5 @@
 
 is($results[0]{diag}, '', 'no errors/warnings');
 
-is($results[1]{diag}, "Flow 'visit good' failed: follow_link couldn't find a link matching (text_regex, (?-xism:AAHHH!!!)) at t/11-nested-flow-error.t line 16\n", 'nested flow failing only reports once, and gives the right line number');
+is($results[1]{diag}, "Flow 'visit good' failed: No link matching (?-xism:AAHHH!!!) found at t/11-nested-flow-error.t line 16\n", 'nested flow failing only reports once, and gives the right line number');
 

Added: Test-WWW-Declare/t/13-flowless.t
==============================================================================
--- (empty file)
+++ Test-WWW-Declare/t/13-flowless.t	Tue Sep  4 15:36:27 2007
@@ -0,0 +1,34 @@
+#!perl
+use Test::WWW::Declare::Tester tests => 13;
+use warnings;
+use strict;
+
+my @results = run_tests(
+    sub {
+        session "check logins" => run {
+            get "http://localhost:$PORT/";
+            content should match qr{This is an index};
+            click href qr{good};
+            content should match qr{This is a good page}i;
+        };
+    }
+);
+
+shift @results; # Test::Tester gives 1-based arrays
+is(@results, 4, "had four tests");
+
+ok($results[0]{ok}, "1st test passed");
+ok($results[1]{ok}, "2st test passed");
+ok($results[2]{ok}, "3st test passed");
+ok($results[3]{ok}, "4st test passed");
+
+is($results[0]{diag}, '', 'no warnings/errors');
+is($results[1]{diag}, '', 'no warnings/errors');
+is($results[2]{diag}, '', 'no warnings/errors');
+is($results[3]{diag}, '', 'no warnings/errors');
+
+is($results[0]{name}, "navigated to http://localhost:$PORT/", "test name was correct");
+is($results[1]{name}, "Content does not match (?-xism:This is an index)", "test name was correct");
+is($results[2]{name}, "Clicked link matching (?-xism:good)", "test name was correct");
+is($results[3]{name}, "Content does not match (?i-xsm:This is a good page)", "test name was correct");
+


More information about the Jifty-commit mailing list