summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJonathan "Duke" Leto <jonathan@leto.net>2011-01-18 17:34:41 -0500
committerJonathan "Duke" Leto <jonathan@leto.net>2011-01-18 17:34:41 -0500
commitec1d053822687ebd35f319c9d47dd15e201e09dd (patch)
tree2fdc21a42e6f7c606fdb8edad313562a7871182d
parentRefactor jitterbug::Emailer to get rid of some warnings and improve tests (diff)
downloadjitterbug-ec1d053822687ebd35f319c9d47dd15e201e09dd.tar.gz
Add ability to use test failure summary in failure email template
-rw-r--r--lib/jitterbug/Emailer.pm11
-rw-r--r--t/006_emailer.t65
2 files changed, 72 insertions, 4 deletions
diff --git a/lib/jitterbug/Emailer.pm b/lib/jitterbug/Emailer.pm
index 60837d6..7a8ed9e 100644
--- a/lib/jitterbug/Emailer.pm
+++ b/lib/jitterbug/Emailer.pm
@@ -22,13 +22,11 @@ sub _make_body {
no warnings 'uninitialized';
return <<BODY;
$header
-
Commit Message:
$message
TAP Output:
$tap
-
$footer
BODY
@@ -47,10 +45,17 @@ sub run {
my $header = $buildconf->{'on_failure_header'};
my $footer = $buildconf->{'on_failure_footer'};
my $body = _make_body($header,$message, $tap, $footer);
+ my $summary;
- # Expand placeholders in our on_failure header and footer
+ if ( $tap =~ m/^(Test Summary Report.*)/ms ) {
+ $summary = $1;
+ }
+
+ # Expand placeholders in our failure email
$body =~ s/%%PROJECT%%/$project/g;
$body =~ s/%%SHA1%%/$sha1/g;
+ $body =~ s/%%SUMMARY%%/$summary/g;
+
my $stuff = Email::Stuff->from($buildconf->{'on_failure_from_email'})
# bug in Email::Stuff brakes chaining if $email is empty
diff --git a/t/006_emailer.t b/t/006_emailer.t
index 9cdd14a..4c6a972 100644
--- a/t/006_emailer.t
+++ b/t/006_emailer.t
@@ -1,6 +1,6 @@
use strict;
use warnings;
-use Test::Most tests => 8;
+use Test::Most tests => 9;
use Data::Dumper;
use Test::MockObject;
@@ -11,6 +11,8 @@ sub setup {
on_failure_from_email => 'bob@example.com',
on_failure_cc_email => 'steve@apple.com',
on_failure_subject_prefix => 'BLARG ',
+ on_failure_header => "Summary:\n%%SUMMARY%%",
+ on_failure_footer => "FOOT",
};
my $conf = { jitterbug => { build_process => $buildconf } };
@@ -49,6 +51,7 @@ sub setup {
}
{
+ my ($conf, $commit, $project, $task) = setup();
my $tap = <<TAP;
Copying lib/Math/Primality/AKS.pm -> blib/lib/Math/Primality/AKS.pm
Copying lib/Math/Primality/BigPolynomial.pm -> blib/lib/Math/Primality/BigPolynomial.pm
@@ -86,5 +89,65 @@ Failed 1/11 test programs. 1/2498 subtests failed.
Files=11, Tests=2498, 3 wallclock secs ( 0.20 usr 0.04 sys + 2.99 cusr 0.18 csys = 3.41 CPU)
Result: FAIL
TAP
+ my $e = jitterbug::Emailer->new($conf, $task, $tap);
+ $e->run;
+ my $email = $e->{'last_email_sent'}{'email'};
+ my $body = <<EMAIL;
+Summary:
+Test Summary Report
+-------------------
+t/is_prime.t (Wstat: 256 Tests: 573 Failed: 1)
+Failed test: 5
+Non-zero exit status: 1
+Failed 1/11 test programs. 1/2498 subtests failed.
+Files=11, Tests=2498, 3 wallclock secs ( 0.20 usr 0.04 sys + 2.99 cusr 0.18 csys = 3.41 CPU)
+Result: FAIL
+
+Commit Message:
+blargly blarg
+
+TAP Output:
+Copying lib/Math/Primality/AKS.pm -> blib/lib/Math/Primality/AKS.pm
+Copying lib/Math/Primality/BigPolynomial.pm -> blib/lib/Math/Primality/BigPolynomial.pm
+Copying lib/Math/Primality.pm -> blib/lib/Math/Primality.pm
+Copying bin/primes.pl -> blib/script/primes.pl
+Copying bin/strong_psuedoprimes.pl -> blib/script/strong_psuedoprimes.pl
+# Testing Math::Primality 0.0401, Perl 5.010001, /usr/bin/perl
+t/00-load.t ......................
+1..1
+ok 1 - use Math::Primality;
+ok
+# Failed test '-1 is not prime'
+# at t/is_prime.t line 16.
+# Looks like you failed 1 test of 573.
+t/is_prime.t .....................
+1..6
+ok 1 - is_prime should handle Math::GMPz objects, three is prime
+ok 2 - 2 is prime
+ok 3 - 1 is not prime
+ok 4 - 0 is not prime
+not ok 5 - -1 is not prime
+ok 6 - blarg
+t/boilerplate.t ..................
+1..3
+ok 1 - README contains no boilerplate text
+ok 2 - Changes contains no boilerplate text
+ok 3 - lib/Math/Primality.pm contains no boilerplate text
+ok
+Test Summary Report
+-------------------
+t/is_prime.t (Wstat: 256 Tests: 573 Failed: 1)
+Failed test: 5
+Non-zero exit status: 1
+Failed 1/11 test programs. 1/2498 subtests failed.
+Files=11, Tests=2498, 3 wallclock secs ( 0.20 usr 0.04 sys + 2.99 cusr 0.18 csys = 3.41 CPU)
+Result: FAIL
+
+FOOT
+EMAIL
+
+ my $ebody = $email->body;
+ $ebody =~ s/\r\n/\n/g;
+ eq_or_diff($ebody, $body, 'email body has failure summary');
}