From 1ea8e7985066277acceb1447e2e8c30bd2d09b0b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ask=20Bj=C3=B8rn=20Hansen?= Date: Thu, 2 Apr 2009 23:30:20 -0700 Subject: [PATCH] Add a few more tests and a 'testcover' make target --- .gitignore | 3 +++ Makefile.PL | 11 ++++++++++- t/addresses.t | 3 ++- t/helo.t | 2 +- t/misc.t | 29 +++++++++++++++++++++++++++++ t/rset.t | 13 +++++++++++++ 6 files changed, 58 insertions(+), 3 deletions(-) create mode 100644 t/misc.t create mode 100644 t/rset.t diff --git a/.gitignore b/.gitignore index 57f7c7c..4aa7b4a 100644 --- a/.gitignore +++ b/.gitignore @@ -3,5 +3,8 @@ pm_to_blib blib/ Makefile Makefile.[a-z]* + *~ *.bak + +cover_db/ diff --git a/Makefile.PL b/Makefile.PL index 26e3bc3..321e72b 100644 --- a/Makefile.PL +++ b/Makefile.PL @@ -15,7 +15,7 @@ WriteMakefile( 'Time::HiRes' => 0, }, ABSTRACT => 'Flexible smtpd daemon written in Perl', - AUTHOR => 'Ask Bjorn Hansen ', + AUTHOR => 'Ask Bjoern Hansen ', EXE_FILES => [qw(qpsmtpd qpsmtpd-forkserver qpsmtpd-prefork qpsmtpd-async)], ); @@ -25,3 +25,12 @@ sub MY::libscan { return $path; } +sub MY::postamble { + qq[ +testcover : +\t cover -delete && \\ + HARNESS_PERL_SWITCHES=-MDevel::Cover \$(MAKE) test && \\ + cover +] + +} diff --git a/t/addresses.t b/t/addresses.t index c74a534..5fbc375 100644 --- a/t/addresses.t +++ b/t/addresses.t @@ -1,6 +1,7 @@ -use Test::More qw(no_plan); +use Test::More tests => 23; use strict; use lib 't'; + use_ok('Test::Qpsmtpd'); ok(my ($smtpd, $conn) = Test::Qpsmtpd->new_conn(), "get new connection"); diff --git a/t/helo.t b/t/helo.t index efe1381..f45680e 100644 --- a/t/helo.t +++ b/t/helo.t @@ -1,4 +1,4 @@ -use Test::More qw(no_plan); +use Test::More tests => 12; use strict; use lib 't'; use_ok('Test::Qpsmtpd'); diff --git a/t/misc.t b/t/misc.t new file mode 100644 index 0000000..96b80f8 --- /dev/null +++ b/t/misc.t @@ -0,0 +1,29 @@ +use Test::More tests => 14; +use strict; +use lib 't'; +use_ok('Test::Qpsmtpd'); + +ok(my ($smtpd, $conn) = Test::Qpsmtpd->new_conn(), "get new connection"); + +# check_spamhelo plugin +is(($smtpd->command('HELO yahoo.com'))[0], 550, 'HELO yahoo.com'); + + +# fault method +is(($smtpd->command('HELO localhost'))[0], 250, 'HELO localhost'); +is(($smtpd->fault)->[0], 451, 'fault returns 451'); +is(($smtpd->fault("test message"))->[1], + "Internal error - try again later - test message", + 'returns the input message' + ); + + +# vrfy command +is(($smtpd->command('VRFY '))[0], 252, 'VRFY command'); + +# plugins/count_unrecognized_commands +is(($smtpd->command('nonsense'))[0], 500, 'bad command 1'); +is(($smtpd->command('nonsense'))[0], 500, 'bad command 2'); +is(($smtpd->command('nonsense'))[0], 500, 'bad command 3'); +is(($smtpd->command('nonsense'))[0], 521, 'bad command 4'); + diff --git a/t/rset.t b/t/rset.t new file mode 100644 index 0000000..ae1e462 --- /dev/null +++ b/t/rset.t @@ -0,0 +1,13 @@ +use Test::More tests => 10; +use strict; +use lib 't'; + +use_ok('Test::Qpsmtpd'); + +ok(my ($smtpd, $conn) = Test::Qpsmtpd->new_conn(), "get new connection"); +is(($smtpd->command('EHLO localhost'))[0], 250, 'EHLO localhost'); + +is(($smtpd->command('MAIL FROM:'))[0], 250, 'MAIL FROM:'); +is($smtpd->transaction->sender->address, 'ask@perl.org', 'got the right sender'); +is(($smtpd->command('RSET'))[0], 250, 'RSET'); +is($smtpd->transaction->sender, undef, 'No sender stored after rset');