From 4bb424bf9937a0dc7b29cda40657631607ffdeaa Mon Sep 17 00:00:00 2001 From: "Jonathan \"Duke\" Leto" Date: Wed, 12 Jan 2011 11:46:49 -0500 Subject: Add some tests for jitterbug::Emailer --- t/006_emailer.t | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 t/006_emailer.t (limited to 't/006_emailer.t') diff --git a/t/006_emailer.t b/t/006_emailer.t new file mode 100644 index 0000000..cc343d1 --- /dev/null +++ b/t/006_emailer.t @@ -0,0 +1,17 @@ +use strict; +use warnings; +use Test::Most tests => 3; +use Data::Dumper; + +use_ok "jitterbug::Emailer"; + +{ + my $conf = { foo => 'bar' }; + my $task = {}; + my $tap = "1..1\nok 1\n"; + my $e = jitterbug::Emailer->new($conf, $task, $tap); + + isa_ok($e,'jitterbug::Emailer'); + can_ok($e,qw/new run/); + +} -- cgit v1.2.3 From c16d34fa7b67ad1e5db7a098e74c5f711e222403 Mon Sep 17 00:00:00 2001 From: "Jonathan \"Duke\" Leto" Date: Wed, 12 Jan 2011 13:31:51 -0500 Subject: Fix some bugs in jitterbug::Emailer and add mocked test data --- t/006_emailer.t | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) (limited to 't/006_emailer.t') diff --git a/t/006_emailer.t b/t/006_emailer.t index cc343d1..2df25f1 100644 --- a/t/006_emailer.t +++ b/t/006_emailer.t @@ -2,12 +2,24 @@ use strict; use warnings; use Test::Most tests => 3; use Data::Dumper; +use Test::MockObject; use_ok "jitterbug::Emailer"; { - my $conf = { foo => 'bar' }; - my $task = {}; + my $conf = { jitterbug => { build_process => 'bar'} }; + my $commit = Test::MockObject->new; + my $project = Test::MockObject->new; + my $task = Test::MockObject->new; + + $project->mock('name', sub { 'ponie' }); + + $commit->mock('sha256', sub { 'c0decafe' }); + $commit->mock('content', sub { 'this should be JSON' } ); + + $task->mock('commit', sub { $commit }); + $task->mock('project', sub { $project }); + my $tap = "1..1\nok 1\n"; my $e = jitterbug::Emailer->new($conf, $task, $tap); -- cgit v1.2.3 From b2fe2456e476962c19cceb74b1d17fb0f22c3c3e Mon Sep 17 00:00:00 2001 From: "Jonathan \"Duke\" Leto" Date: Wed, 12 Jan 2011 10:56:48 -0800 Subject: More tests for jitterbug::Emailer --- t/006_emailer.t | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) (limited to 't/006_emailer.t') diff --git a/t/006_emailer.t b/t/006_emailer.t index 2df25f1..0dce025 100644 --- a/t/006_emailer.t +++ b/t/006_emailer.t @@ -1,29 +1,42 @@ use strict; use warnings; -use Test::Most tests => 3; +use Test::Most tests => 5; use Data::Dumper; use Test::MockObject; use_ok "jitterbug::Emailer"; { - my $conf = { jitterbug => { build_process => 'bar'} }; - my $commit = Test::MockObject->new; + my $buildconf = { + on_failure_from_email => 'bob@example.com', + on_failure_cc_email => 'steve@apple.com', + on_failure_subject_prefix => 'BLARG', + }; + + my $conf = { jitterbug => { build_process => $buildconf } }; + my $commit = Test::MockObject->new; my $project = Test::MockObject->new; - my $task = Test::MockObject->new; + my $task = Test::MockObject->new; $project->mock('name', sub { 'ponie' }); $commit->mock('sha256', sub { 'c0decafe' }); - $commit->mock('content', sub { 'this should be JSON' } ); + $commit->mock('content', sub { '{ }' } ); $task->mock('commit', sub { $commit }); $task->mock('project', sub { $project }); - my $tap = "1..1\nok 1\n"; + my $tap = "THIS IS TAP"; my $e = jitterbug::Emailer->new($conf, $task, $tap); isa_ok($e,'jitterbug::Emailer'); can_ok($e,qw/new run/); + $e->run; + my $email = $e->{'last_email_sent'}{'email'}; + like($email->body, qr/THIS IS TAP/, 'email body looks right'); + + my $header = $email->{'header'}; + isa_ok($header, 'Email::MIME::Header'); + } -- cgit v1.2.3 From ebc5a1d5adff8d041295b78a429a29ffb6b42d58 Mon Sep 17 00:00:00 2001 From: "Jonathan \"Duke\" Leto" Date: Wed, 12 Jan 2011 11:40:22 -0800 Subject: More jitterbug::Emailer tests --- t/006_emailer.t | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 't/006_emailer.t') diff --git a/t/006_emailer.t b/t/006_emailer.t index 0dce025..feffd38 100644 --- a/t/006_emailer.t +++ b/t/006_emailer.t @@ -1,6 +1,6 @@ use strict; use warnings; -use Test::Most tests => 5; +use Test::Most tests => 8; use Data::Dumper; use Test::MockObject; @@ -10,7 +10,7 @@ use_ok "jitterbug::Emailer"; my $buildconf = { on_failure_from_email => 'bob@example.com', on_failure_cc_email => 'steve@apple.com', - on_failure_subject_prefix => 'BLARG', + on_failure_subject_prefix => 'BLARG ', }; my $conf = { jitterbug => { build_process => $buildconf } }; @@ -39,4 +39,8 @@ use_ok "jitterbug::Emailer"; my $header = $email->{'header'}; isa_ok($header, 'Email::MIME::Header'); + is($header->header_raw('cc'), 'steve@apple.com', 'cc header'); + is($header->header_raw('subject'), 'BLARG ponie @ c0decafe', 'subject header'); + is($header->header_raw('from'), 'bob@example.com', 'from header'); + } -- cgit v1.2.3 From dddeaba05015d4040ab1aeb502a81e291e9c56a4 Mon Sep 17 00:00:00 2001 From: "Jonathan \"Duke\" Leto" Date: Tue, 18 Jan 2011 15:30:02 -0500 Subject: Refactor jitterbug::Emailer to get rid of some warnings and improve tests --- t/006_emailer.t | 50 +++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 47 insertions(+), 3 deletions(-) (limited to 't/006_emailer.t') diff --git a/t/006_emailer.t b/t/006_emailer.t index feffd38..9cdd14a 100644 --- a/t/006_emailer.t +++ b/t/006_emailer.t @@ -6,7 +6,7 @@ use Test::MockObject; use_ok "jitterbug::Emailer"; -{ +sub setup { my $buildconf = { on_failure_from_email => 'bob@example.com', on_failure_cc_email => 'steve@apple.com', @@ -21,11 +21,15 @@ use_ok "jitterbug::Emailer"; $project->mock('name', sub { 'ponie' }); $commit->mock('sha256', sub { 'c0decafe' }); - $commit->mock('content', sub { '{ }' } ); + $commit->mock('content', sub { '{ "message" : "blargly blarg" }' } ); $task->mock('commit', sub { $commit }); $task->mock('project', sub { $project }); + return ($conf, $commit, $project, $task); +} +{ + my ($conf, $commit, $project, $task) = setup(); my $tap = "THIS IS TAP"; my $e = jitterbug::Emailer->new($conf, $task, $tap); @@ -40,7 +44,47 @@ use_ok "jitterbug::Emailer"; isa_ok($header, 'Email::MIME::Header'); is($header->header_raw('cc'), 'steve@apple.com', 'cc header'); - is($header->header_raw('subject'), 'BLARG ponie @ c0decafe', 'subject header'); + like($header->header_raw('subject'), qr/BLARG ponie @ c0decafe blargly blarg/, 'subject header'); is($header->header_raw('from'), 'bob@example.com', 'from header'); +} + +{ + my $tap = < 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 +TAP } -- cgit v1.2.3 From ec1d053822687ebd35f319c9d47dd15e201e09dd Mon Sep 17 00:00:00 2001 From: "Jonathan \"Duke\" Leto" Date: Tue, 18 Jan 2011 17:34:41 -0500 Subject: Add ability to use test failure summary in failure email template --- t/006_emailer.t | 65 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 64 insertions(+), 1 deletion(-) (limited to 't/006_emailer.t') 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 = < 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 = < 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'); } -- cgit v1.2.3 From 266d5cca294a0a689e0c48753cea24b5ae001175 Mon Sep 17 00:00:00 2001 From: "Jonathan \"Duke\" Leto" Date: Wed, 19 Jan 2011 09:27:49 -0800 Subject: Try not to ire the SpamCop Elder Gods --- t/006_emailer.t | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 't/006_emailer.t') diff --git a/t/006_emailer.t b/t/006_emailer.t index 4c6a972..c5e090e 100644 --- a/t/006_emailer.t +++ b/t/006_emailer.t @@ -9,7 +9,7 @@ use_ok "jitterbug::Emailer"; sub setup { my $buildconf = { on_failure_from_email => 'bob@example.com', - on_failure_cc_email => 'steve@apple.com', + on_failure_cc_email => 'steve@example.com', on_failure_subject_prefix => 'BLARG ', on_failure_header => "Summary:\n%%SUMMARY%%", on_failure_footer => "FOOT", -- cgit v1.2.3 From 952325b718086602b836a165dfa4f5e72e5bed9e Mon Sep 17 00:00:00 2001 From: "Jonathan \"Duke\" Leto" Date: Wed, 19 Jan 2011 09:28:26 -0800 Subject: Fix a jitterbug::Emailer test --- t/006_emailer.t | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 't/006_emailer.t') diff --git a/t/006_emailer.t b/t/006_emailer.t index c5e090e..44dd328 100644 --- a/t/006_emailer.t +++ b/t/006_emailer.t @@ -45,7 +45,7 @@ sub setup { my $header = $email->{'header'}; isa_ok($header, 'Email::MIME::Header'); - is($header->header_raw('cc'), 'steve@apple.com', 'cc header'); + is($header->header_raw('cc'), 'steve@example.com', 'cc header'); like($header->header_raw('subject'), qr/BLARG ponie @ c0decafe blargly blarg/, 'subject header'); is($header->header_raw('from'), 'bob@example.com', 'from header'); } -- cgit v1.2.3