#!/usr/bin/perl use strict; use warnings; use Data::Dumper; use Test::More; use Test::Output; use lib 't'; use lib 'lib'; # test lib/Qpsmtpd/SMTP (vs site_perl) use_ok('Test::Qpsmtpd'); use_ok('Qpsmtpd::SMTP'); ok(my $smtp = Qpsmtpd::SMTP->new(), "new smtp"); ok(my ($smtpd, $conn) = Test::Qpsmtpd->new_conn(), "get new connection"); __new(); __fault(); done_testing(); sub __new { isa_ok( $smtp, 'Qpsmtpd::SMTP' ); ok( $smtp->{_commands}, "valid commands populated"); $smtp = Qpsmtpd::SMTP->new( key => 'val' ); cmp_ok( $smtp->{args}{key}, 'eq', 'val', "new with args"); } sub __fault { my $fault; stderr_like { $fault = $smtpd->fault } qr/program fault - command not performed.*Last system error:/ms, 'fault outputs proper warning to STDOUT'; is($fault->[0], 451, 'fault returns 451'); stderr_like { $fault = $smtpd->fault('test message') } qr/test message.*Last system error/ms, 'fault outputs proper custom warning to STDOUT'; is($fault->[1], 'Internal error - try again later - test message', 'returns the input message'); }