Subject: | improve portability of sendmail tests |
Email::Send's sendmail.t is often skipped when it could be run, given
some updating. The attached patch updates sendmail.t to be more likely
to be runnable.
--
rjbs
Subject: | es-sendmail-t.patch |
This test improves the number of cases in which all of the sendmail.t tests can
be run.
diff -ruN Email-Send-2.04/t/sendmail.t Email-Send-rjbs/t/sendmail.t
--- Email-Send-2.04/t/sendmail.t 2006-01-28 16:30:46.000000000 -0500
+++ Email-Send-rjbs/t/sendmail.t 2006-02-03 18:26:18.000000000 -0500
@@ -50,12 +50,31 @@
like( $return, qr/cannot execute/, 'error message says what we expect' );
}
+my $has_FileTemp = eval { require File::Temp; };
+
SKIP:
{
- skip 'Cannot run this test unless current perl is at /usr/bin/perl', 1
- unless -x '/usr/bin/perl' && $^X eq '/usr/bin/perl';
+ skip 'Cannot run this test unless current perl is -x', 1 unless -x $^X;
+
+ skip 'Cannot run this test without File::Temp', 1 unless $has_FileTemp;
+ my $tempdir = File::Temp::tempdir();
+
+ require File::Spec;
+
+ my $error = "can't prepare executable test script";
+
+ my $filename = File::Spec->catfile($tempdir, "executable");
+ open my $fh, ">", $filename or skip $error, 1;
+
+ open my $exec, "<", './util/executable' or skip $error, 1;
+
+ print {$fh} "#!$^X\n" or skip $error, 1;
+ print {$fh} <$exec> or skip $error, 1;
+ close $fh or skip $error, 1;
- local $Email::Send::Sendmail::SENDMAIL = './util/executable';
+ chmod 0755, $filename;
+
+ local $Email::Send::Sendmail::SENDMAIL = $filename;
my $sender = Email::Send->new({mailer => 'Sendmail'});
my $return = $sender->send($email);
ok( $return, 'send() succeeded with executable $SENDMAIL' );
@@ -63,10 +82,26 @@
SKIP:
{
- skip 'Cannot run this test unless current perl is at /usr/bin/perl', 2
- unless -x '/usr/bin/perl' && $^X eq '/usr/bin/perl';
+ skip 'Cannot run this test unless current perl is -x', 1 unless -x $^X;
+
+ skip 'Cannot run this test without File::Temp', 1 unless $has_FileTemp;
+ my $tempdir = File::Temp::tempdir();
+
+ require File::Spec;
+
+ my $error = "can't prepare executable test script";
+
+ my $filename = File::Spec->catfile($tempdir, "sendmail");
+ open my $sendmail_fh, ">", $filename or skip $error, 1;
+ open my $template_fh, "<", './util/sendmail' or skip $error, 1;
+
+ print {$sendmail_fh} "#!$^X\n" or skip $error, 1;
+ print {$sendmail_fh} <$template_fh> or skip $error, 1;
+ close $sendmail_fh or skip $error, 1;
+
+ chmod 0755, $filename;
- local $ENV{PATH} = './util';
+ local $ENV{PATH} = $tempdir;
my $sender = Email::Send->new({mailer => 'Sendmail'});
my $return = $sender->send($email);
ok( $return, 'send() succeeded with executable sendmail in path' );