1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96
|
#!perl
use strict;
use warnings FATAL => 'all';
use Data::Dumper;
use Mail::Sendmail;
use Test::More tests => 9;
BEGIN { use_ok('Test::POP3') };
#########################
my $pc = 1;
my ($host, $user, $pass, $smtp, $email) = get_info();
# don't surprise/confuse the user
# we expect to fail some of these
$Test::Email::QUIET_DIAG = 1;
SKIP: {
skip 'No POP3 settings found', 8 unless $host;
my $test = Test::POP3->new({
host => $host,
user => $user,
pass => $pass,
});
# no tmpfiles
my $parser = $test->get_parser();
$parser->output_to_core(1);
# no messages
$test->delete_all();
my $msg_count = $test->get_email_count(1);
is($msg_count, 0, 'no messages');
# send 3 messages
sendmail(
to => $email,
from => $email,
subject => 'test 1',
message => 'message 1',
smtp => $smtp,
);
sleep 1;
sendmail(
to => $email,
from => $email,
subject => 'test 2',
message => 'message 2',
smtp => $smtp,
);
sleep 1;
sendmail(
to => $email,
from => $email,
subject => 'test 3',
message => 'message 3',
smtp => $smtp,
);
# then wait for them
is($test->wait_for_email_count(3), 3, 'found 3 messages');
# fail a single test
ok(!$test->_run_tests({
body => qr/4/,
}, 'should not see this'), 'one wrong arg fails');
# fail part of a multiple test
ok(!$test->_run_tests({
body => qr/5/,
subject => 'test 1',
}, 'should not see this'), 'some wrong args fail');
$test->ok({
body => qr/2/,
}, 'body regexp');
$test->ok({
body => 'message 3',
}, 'body string');
$test->ok({
body => qr/1/,
subject => 'test 1',
}, 'body and subject');
is($test->delete_all(), 0, 'no others to be deleted');
};
sub get_info {
return map $ENV{"TEST_POP3_$_"}, map uc, qw(host user pass smtp email);
}
__END__
|