[Rt-commit] rt branch, 4.0/catch-test-file-warnings, created. rt-4.0.8-153-g60068e5
Thomas Sibley
trs at bestpractical.com
Thu Nov 8 18:25:42 EST 2012
The branch, 4.0/catch-test-file-warnings has been created
at 60068e50d565c1a06303ed7832fbf267ca59d1f8 (commit)
- Log -----------------------------------------------------------------
commit 60068e50d565c1a06303ed7832fbf267ca59d1f8
Author: Thomas Sibley <trs at bestpractical.com>
Date: Thu Nov 8 14:56:55 2012 -0800
Verify all tests are warnings clean using Test::NoWarnings
An additional test for each test file is run either in the existing END
block during test cleanup or in done_testing(), whichever comes first.
Whenever possible, the single additional test is automatically accounted
for by RT::Test. This means most test counts do not need to change.
Tests which declare a plan using Test::More and _also_ use RT::Test need
to manually account for the extra test themselves since the plan is
already output before RT::Test is ever called. This is mostly the
shredder tests.
diff --git a/lib/RT/Test.pm b/lib/RT/Test.pm
index 36f0f87..ce600b0 100644
--- a/lib/RT/Test.pm
+++ b/lib/RT/Test.pm
@@ -53,14 +53,16 @@ use warnings;
use base 'Test::More';
+require Test::NoWarnings;
use Socket;
use File::Temp qw(tempfile);
use File::Path qw(mkpath);
use File::Spec;
-our @EXPORT = qw(is_empty diag parse_mail works fails);
+our @EXPORT = qw(is_empty diag parse_mail works fails plan done_testing);
+my $check_warnings_in_end = 1;
my %tmp = (
directory => undef,
config => {
@@ -100,14 +102,14 @@ sub import {
# Spit out a plan (if we got one) *before* we load modules
if ( $args{'tests'} ) {
- $class->builder->plan( tests => $args{'tests'} )
+ plan( tests => $args{'tests'} )
unless $args{'tests'} eq 'no_declare';
}
elsif ( exists $args{'tests'} ) {
# do nothing if they say "tests => undef" - let them make the plan
}
elsif ( $args{'skip_all'} ) {
- $class->builder->plan(skip_all => $args{'skip_all'});
+ plan(skip_all => $args{'skip_all'});
}
else {
$class->builder->no_plan unless $class->builder->has_plan;
@@ -168,12 +170,15 @@ sub import {
}
Test::More->export_to_level($level);
+ Test::NoWarnings->export_to_level($level);
- # blow away their diag so we can redefine it without warning
+ # Blow away symbols we redefine to avoid warnings.
# better than "no warnings 'redefine'" because we might accidentally
# suppress a mistaken redefinition
no strict 'refs';
delete ${ caller($level) . '::' }{diag};
+ delete ${ caller($level) . '::' }{plan};
+ delete ${ caller($level) . '::' }{done_testing};
__PACKAGE__->export_to_level($level);
}
@@ -1521,15 +1526,38 @@ sub fails {
Test::More::ok(!$_[0], $_[1] || 'This should fail');
}
+sub plan {
+ my ($cmd, @args) = @_;
+ my $builder = RT::Test->builder;
+
+ if ($cmd eq "skip_all") {
+ $check_warnings_in_end = 0;
+ } elsif ($cmd eq "tests") {
+ # Increment the test count for the warnings check
+ $args[0]++;
+ }
+ $builder->plan($cmd, @args);
+}
+
+sub done_testing {
+ my $builder = RT::Test->builder;
+
+ Test::NoWarnings::had_no_warnings();
+ $check_warnings_in_end = 0;
+
+ $builder->done_testing(@_);
+}
+
END {
my $Test = RT::Test->builder;
return if $Test->{Original_Pid} != $$;
-
# we are in END block and should protect our exit code
# so calls below may call system or kill that clobbers $?
local $?;
+ Test::NoWarnings::had_no_warnings() if $check_warnings_in_end;
+
RT::Test->stop_server(1);
# not success
diff --git a/sbin/rt-test-dependencies.in b/sbin/rt-test-dependencies.in
index 378cea9..7f60538 100644
--- a/sbin/rt-test-dependencies.in
+++ b/sbin/rt-test-dependencies.in
@@ -294,6 +294,7 @@ Log::Dispatch::Perl
Test::WWW::Mechanize::PSGI
Plack::Middleware::Test::StashWarnings 0.06
Test::LongString
+Test::NoWarnings
.
$deps{'FASTCGI'} = [ text_to_hash( << '.') ];
diff --git a/t/lifecycles/unresolved-deps.t b/t/lifecycles/unresolved-deps.t
index d195d3b..02c1942 100644
--- a/t/lifecycles/unresolved-deps.t
+++ b/t/lifecycles/unresolved-deps.t
@@ -2,7 +2,7 @@ use strict;
use warnings;
use Data::Dumper;
-use Test::More tests => 15;
+use Test::More tests => 15 + 1; # plus one for warnings check
BEGIN {require 't/lifecycles/utils.pl'};
my $general = RT::Test->load_or_create_queue(
diff --git a/t/shredder/00load.t b/t/shredder/00load.t
index 21d5ef7..a78e5e4 100644
--- a/t/shredder/00load.t
+++ b/t/shredder/00load.t
@@ -1,7 +1,7 @@
use strict;
use warnings;
use File::Spec;
-use Test::More tests => 11;
+use Test::More tests => 11 + 1; # plus one for warnings check
use RT::Test nodb => 1;
BEGIN {
diff --git a/t/shredder/00skeleton.t b/t/shredder/00skeleton.t
index c23e064..9c6e3a1 100644
--- a/t/shredder/00skeleton.t
+++ b/t/shredder/00skeleton.t
@@ -4,7 +4,7 @@ use warnings;
use Test::Deep;
use File::Spec;
-use Test::More tests => 1;
+use Test::More tests => 1 + 1; # plus one for warnings check
use RT::Test ();
BEGIN {
my $shredder_utils = RT::Test::get_relocatable_file('utils.pl',
diff --git a/t/shredder/01basics.t b/t/shredder/01basics.t
index b0000b1..1fa9f75 100644
--- a/t/shredder/01basics.t
+++ b/t/shredder/01basics.t
@@ -4,7 +4,7 @@ use warnings;
use Test::Deep;
use File::Spec;
-use Test::More tests => 3;
+use Test::More tests => 3 + 1; # plus one for warnings check
use RT::Test ();
BEGIN {
my $shredder_utils = RT::Test::get_relocatable_file('utils.pl',
diff --git a/t/shredder/01ticket.t b/t/shredder/01ticket.t
index b834963..0a9da41 100644
--- a/t/shredder/01ticket.t
+++ b/t/shredder/01ticket.t
@@ -4,7 +4,7 @@ use warnings;
use Test::Deep;
use File::Spec;
-use Test::More tests => 15;
+use Test::More tests => 15 + 1; # plus one for warnings check
use RT::Test ();
diff --git a/t/shredder/02group_member.t b/t/shredder/02group_member.t
index 5952e1e..9dc4f61 100644
--- a/t/shredder/02group_member.t
+++ b/t/shredder/02group_member.t
@@ -4,7 +4,7 @@ use warnings;
use Test::Deep;
use File::Spec;
-use Test::More tests => 22;
+use Test::More tests => 22 + 1; # plus one for warnings check
use RT::Test ();
BEGIN {
my $shredder_utils = RT::Test::get_relocatable_file('utils.pl',
diff --git a/t/shredder/02queue.t b/t/shredder/02queue.t
index 7cfd378..dd55817 100644
--- a/t/shredder/02queue.t
+++ b/t/shredder/02queue.t
@@ -4,7 +4,7 @@ use warnings;
use Test::Deep;
use File::Spec;
-use Test::More tests => 16;
+use Test::More tests => 16 + 1; # plus one for warnings check
use RT::Test ();
BEGIN {
my $shredder_utils = RT::Test::get_relocatable_file('utils.pl',
diff --git a/t/shredder/02template.t b/t/shredder/02template.t
index 4d0cd4f..aeb318e 100644
--- a/t/shredder/02template.t
+++ b/t/shredder/02template.t
@@ -4,7 +4,7 @@ use warnings;
use Test::Deep;
use File::Spec;
-use Test::More tests => 7;
+use Test::More tests => 7 + 1; # plus one for warnings check
use RT::Test ();
BEGIN {
my $shredder_utils = RT::Test::get_relocatable_file('utils.pl',
diff --git a/t/shredder/02user.t b/t/shredder/02user.t
index d97511d..9f15770 100644
--- a/t/shredder/02user.t
+++ b/t/shredder/02user.t
@@ -4,7 +4,7 @@ use warnings;
use Test::Deep;
use File::Spec;
-use Test::More tests => 8;
+use Test::More tests => 8 + 1; # plus one for warnings check
use RT::Test ();
BEGIN {
my $shredder_utils = RT::Test::get_relocatable_file('utils.pl',
diff --git a/t/shredder/03plugin.t b/t/shredder/03plugin.t
index 4ba2fbf..15766cd 100644
--- a/t/shredder/03plugin.t
+++ b/t/shredder/03plugin.t
@@ -4,7 +4,7 @@ use warnings;
use Test::Deep;
use File::Spec;
-use Test::More tests => 28;
+use Test::More tests => 28 + 1; # plus one for warnings check
use RT::Test ();
BEGIN {
my $shredder_utils = RT::Test::get_relocatable_file('utils.pl',
diff --git a/t/shredder/03plugin_summary.t b/t/shredder/03plugin_summary.t
index ec3b6e9..d450c70 100644
--- a/t/shredder/03plugin_summary.t
+++ b/t/shredder/03plugin_summary.t
@@ -4,7 +4,7 @@ use warnings;
use Test::Deep;
use File::Spec;
-use Test::More tests => 4;
+use Test::More tests => 4 + 1; # plus one for warnings check
use RT::Test nodb => 1;
BEGIN {
my $shredder_utils = RT::Test::get_relocatable_file('utils.pl',
diff --git a/t/shredder/03plugin_tickets.t b/t/shredder/03plugin_tickets.t
index 256be1c..1579bc5 100644
--- a/t/shredder/03plugin_tickets.t
+++ b/t/shredder/03plugin_tickets.t
@@ -4,7 +4,7 @@ use warnings;
use Test::Deep;
use File::Spec;
-use Test::More tests => 44;
+use Test::More tests => 44 + 1; # plus one for warnings check
use RT::Test ();
BEGIN {
my $shredder_utils = RT::Test::get_relocatable_file('utils.pl',
diff --git a/t/shredder/03plugin_users.t b/t/shredder/03plugin_users.t
index ef75680..131ffa0 100644
--- a/t/shredder/03plugin_users.t
+++ b/t/shredder/03plugin_users.t
@@ -4,7 +4,7 @@ use warnings;
use Test::Deep;
use File::Spec;
-use Test::More tests => 21;
+use Test::More tests => 21 + 1; # plus one for warnings check
use RT::Test ();
BEGIN {
my $shredder_utils = RT::Test::get_relocatable_file('utils.pl',
diff --git a/t/web/compilation_errors.t b/t/web/compilation_errors.t
index 5e3ef58..0ae6ead 100644
--- a/t/web/compilation_errors.t
+++ b/t/web/compilation_errors.t
@@ -8,7 +8,7 @@ BEGIN {
}
my $tests = 8;
find( sub { wanted() and $tests += 4 }, 'share/html/' );
- plan tests => $tests;
+ plan tests => $tests + 1; # plus one for warnings check
}
-----------------------------------------------------------------------
More information about the Rt-commit
mailing list