[Rt-commit] rt branch, 4.0/test-warnings, created. rt-4.0.0-177-g6130a77

Shawn Moore sartak at bestpractical.com
Tue May 3 13:22:06 EDT 2011


The branch, 4.0/test-warnings has been created
        at  6130a77dc21e9d7518496d3c962249a1ab2b1693 (commit)

- Log -----------------------------------------------------------------
commit 6130a77dc21e9d7518496d3c962249a1ab2b1693
Author: Shawn M Moore <sartak at bestpractical.com>
Date:   Tue May 3 12:42:10 2011 -0400

    Replace some uses of $SIG{__WARN__} with Test::Warn

diff --git a/t/api/link.t b/t/api/link.t
index b110fc7..228ff91 100644
--- a/t/api/link.t
+++ b/t/api/link.t
@@ -1,15 +1,13 @@
-
 use strict;
 use warnings;
 
-use RT::Test nodata => 1, tests => 83;
+use RT::Test nodata => 1, tests => 80;
 use RT::Test::Web;
+use Test::Warn;
 
 use RT::Link;
 my $link = RT::Link->new(RT->SystemUser);
 
-use RT::Test::Web;
-
 ok (ref $link);
 isa_ok( $link, 'RT::Link');
 isa_ok( $link, 'RT::Base');
@@ -34,26 +32,23 @@ my $child = RT::Ticket->new(RT->SystemUser);
 ok $cid, 'created a ticket #'. $cid or diag "error: $msg";
 
 {
-    my @warnings;
-    local $SIG{__WARN__} = sub {
-        push @warnings, "@_";
-    };
-
+    my ($status, $msg);
     clean_links();
-    my ($status, $msg) = $parent->AddLink;
+
+    warning_like {
+        ($status, $msg) = $parent->AddLink;
+    } qr/Base or Target must be specified/, "warned about linking a ticket to itself";
     ok(!$status, "didn't create a link: $msg");
-    is(@warnings, 1, "one warning");
-    like(shift @warnings, qr/Base or Target must be specified/, "warned about linking a ticket to itself");
 
-    ($status, $msg) = $parent->AddLink( Base => $parent->id );
+    warning_like {
+        ($status, $msg) = $parent->AddLink( Base => $parent->id );
+    } qr/Can't link a ticket to itself/, "warned about linking a ticket to itself";
     ok(!$status, "didn't create a link: $msg");
-    is(@warnings, 1, "one warning");
-    like(shift @warnings, qr/Can't link a ticket to itself/, "warned about linking a ticket to itself");
 
-    ($status, $msg) = $parent->AddLink( Base => $parent->id, Type => 'HasMember' );
+    warning_like {
+        ($status, $msg) = $parent->AddLink( Base => $parent->id, Type => 'HasMember' );
+    } qr/Can't link a ticket to itself/, "warned about linking a ticket to itself";
     ok(!$status, "didn't create a link: $msg");
-    is(@warnings, 1, "one warning");
-    like(shift @warnings, qr/Can't link a ticket to itself/, "warned about linking a ticket to itself");
 }
 
 {
diff --git a/t/api/tickets_overlay_sql.t b/t/api/tickets_overlay_sql.t
index 0397d4b..e0e66d1 100644
--- a/t/api/tickets_overlay_sql.t
+++ b/t/api/tickets_overlay_sql.t
@@ -1,6 +1,7 @@
 
 use RT;
 use RT::Test tests => 20, config => 'Set( %FullTextSearch, Enable => 1 );';
+use Test::Warn;
 
 
 {
@@ -83,12 +84,12 @@ diag "Make sure we don't barf on invalid input for IS / IS NOT";
 }
 
 {
-    my $warnings;
-    local $SIG{__WARN__} = sub { $warnings .= "@_" };
+    my ($status, $msg);
 
-    my ($status, $msg) = $tix->FromSQL("Requestor.Signature LIKE 'foo'");
-    ok (!$status, "invalid query - Signature not valid") or diag("error: $msg");
-    like($warnings, qr/Invalid watcher subfield: 'Signature'/);
+    warning_like {
+        ($status, $msg) = $tix->FromSQL("Requestor.Signature LIKE 'foo'");
+    } qr/Invalid watcher subfield: 'Signature'/;
+    ok(!$status, "invalid query - Signature not valid") or diag("error: $msg");
 
     ($status, $msg) = $tix->FromSQL("Requestor.EmailAddress LIKE 'jesse'");
     ok ($status, "valid query") or diag("error: $msg");
diff --git a/t/mail/dashboards.t b/t/mail/dashboards.t
index 96ec745..31fe701 100644
--- a/t/mail/dashboards.t
+++ b/t/mail/dashboards.t
@@ -2,7 +2,8 @@
 use strict;
 use warnings;
 
-use RT::Test tests => 73;
+use RT::Test tests => 72;
+use Test::Warn;
 use RT::Dashboard::Mailer;
 
 my ($baseurl, $m) = RT::Test->started_ok;
@@ -176,17 +177,9 @@ ok($ok, $msg);
 ($ok, $msg) = $dashboard->Delete;
 ok($ok, $msg);
 
-do {
-    my @warnings;
-    local $SIG{__WARN__} = sub {
-        push @warnings, "@_";
-    };
-
+warning_like {
     RT::Dashboard::Mailer->MailDashboards(All => 1);
-
-    is(@warnings, 1, "one warning");
-    like($warnings[0], qr/Unable to load dashboard $dashboard_id of subscription $subscription_id for user root/);
-};
+} qr/Unable to load dashboard $dashboard_id of subscription $subscription_id for user root/;
 
 @mails = RT::Test->fetch_caught_mails;
 is(@mails, 1, "one mail for subscription failure");
diff --git a/t/ticket/linking.t b/t/ticket/linking.t
index b18340d..dd499bf 100644
--- a/t/ticket/linking.t
+++ b/t/ticket/linking.t
@@ -2,7 +2,8 @@
 use strict;
 use warnings;
 
-use RT::Test tests => 106;
+use RT::Test tests => 102;
+use Test::Warn;
 use_ok('RT');
 use_ok('RT::Ticket');
 use_ok('RT::ScripConditions');
@@ -194,15 +195,11 @@ ok ($id,$msg);
 
 diag('try link to itself');
 {
-    my @warnings;
-    local $SIG{__WARN__} = sub {
-        push @warnings, "@_";
-    };
-    my ($id, $msg) = $ticket->AddLink(Type => 'RefersTo', Target => $ticket->id);
+    warning_like {
+        ($id, $msg) = $ticket->AddLink(Type => 'RefersTo', Target => $ticket->id);
+    } qr/Can't link a ticket to itself/;
     ok(!$id, $msg);
     is(link_count($filename), 0, "scrips ok");
-    is(@warnings, 1, "one warning");
-    like("@warnings", qr/Can't link a ticket to itself/);
 }
 
 my $ticket2 = RT::Ticket->new(RT->SystemUser);
@@ -220,17 +217,12 @@ ok ($id,$msg);
 ok($id,$msg);
 is(link_count($filename), 1, "scrips ok");
 
-{
-    my @warnings;
-    local $SIG{__WARN__} = sub {
-        push @warnings, "@_";
-    };
+warnings_like {
     ($id,$msg) = $ticket->AddLink(Type => 'RefersTo', Target => -1);
-    ok(!$id,$msg);
-    is(@warnings, 2, "two warnings");
-    like($warnings[0], qr/Could not determine a URI scheme for -1/);
-    like($warnings[1], qr/Couldn't resolve '-1' into a URI/);
-}
+} [
+    qr/Could not determine a URI scheme for -1/,
+    qr/Couldn't resolve '-1' into a URI/,
+];
 
 ($id,$msg) = $ticket->AddLink(Type => 'RefersTo', Target => $ticket2->id);
 ok($id,$msg);
diff --git a/t/web/crypt-gnupg.t b/t/web/crypt-gnupg.t
index 9dd3d5c..6bdefda 100644
--- a/t/web/crypt-gnupg.t
+++ b/t/web/crypt-gnupg.t
@@ -7,6 +7,7 @@ use RT::Test::GnuPG
     passphrase    => 'recipient',
     'trust-model' => 'always',
 };
+use Test::Warn;
 
 use RT::Action::SendEmail;
 
@@ -352,18 +353,16 @@ To: general\@example.com
 hello
 MAIL
  
-my ($warnings, $status);
-{
-    local $SIG{__WARN__} = sub {
-        $warnings .= "@_";
-    };
-
+my $status;
+warning_like {
     ($status, $id) = RT::Test->send_via_mailgate($mail);
-}
+} [
+    qr/nokey\@example.com: skipped: public key not found/,
+    qr/Recipient 'nokey\@example.com' is unusable/,
+];
 
 is ($status >> 8, 0, "The mail gateway exited normally");
 ok ($id, "got id of a newly created ticket - $id");
-like($warnings, qr/nokey\@example.com: skipped: public key not found/);
 
 $tick = RT::Ticket->new( RT->SystemUser );
 $tick->Load( $id );

-----------------------------------------------------------------------


More information about the Rt-commit mailing list