]> Sergey Matveev's repositories - public-inbox.git/blobdiff - t/mda.t
testcommon: spawn-aware system() and qx[] workalikes
[public-inbox.git] / t / mda.t
diff --git a/t/mda.t b/t/mda.t
index 4556e3234e9c7adfc6682aa7cff6bde9ba8f7563..dc6916169cbab1c2ba964f87e8048f68a1570f11 100644 (file)
--- a/t/mda.t
+++ b/t/mda.t
@@ -1,4 +1,4 @@
-# Copyright (C) 2014-2019 all contributors <meta@public-inbox.org>
+# Copyright (C) 2014-2020 all contributors <meta@public-inbox.org>
 # License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
 use strict;
 use warnings;
@@ -7,7 +7,9 @@ use Email::MIME;
 use Cwd qw(getcwd);
 use PublicInbox::MID qw(mid2path);
 use PublicInbox::Git;
+use PublicInbox::InboxWritable;
 use PublicInbox::TestCommon;
+use PublicInbox::Import;
 my ($tmpdir, $for_destroy) = tmpdir();
 my $home = "$tmpdir/pi-home";
 my $pi_home = "$home/.public-inbox";
@@ -34,7 +36,7 @@ my $fail_bad_header = sub ($$$) {
                "no error on undeliverable ($msg)");
        my $rev = $git->qx(qw(rev-list HEAD));
        chomp $rev;
-       is($rev, $good_rev, "bad revision not commited ($msg)");
+       is($rev, $good_rev, "bad revision not committed ($msg)");
        @f = glob("$faildir/*/*");
        is(scalar @f, 1, "faildir written to");
        [ $in, $out, $err ];
@@ -47,28 +49,24 @@ my $fail_bad_header = sub ($$$) {
                "spamc mock found (run in top of source tree");
        is(1, mkdir($home, 0755), "setup ~/ for testing");
        is(1, mkdir($pi_home, 0755), "setup ~/.public-inbox");
-       is(0, system(qw(git init -q --bare), $maindir), "git init (main)");
+       PublicInbox::Import::init_bare($maindir);
 
-       my %cfg = (
-               "$cfgpfx.address" => $addr,
-               "$cfgpfx.inboxdir" => $maindir,
-       );
-       while (my ($k,$v) = each %cfg) {
-               is(0, system(qw(git config --file), $pi_config, $k, $v),
-                       "setup $k");
-       }
+       open my $fh, '>>', $pi_config or die;
+       print $fh <<EOF or die;
+[publicinbox "test"]
+       address = $addr
+       inboxdir = $maindir
+EOF
+       close $fh or die;
 }
 
 local $ENV{GIT_COMMITTER_NAME} = eval {
        use PublicInbox::MDA;
        use PublicInbox::Address;
        use Encode qw/encode/;
-       my $mbox = 't/utf8.mbox';
-       open(my $fh, '<', $mbox) or die "failed to open mbox: $mbox\n";
-       my $str = eval { local $/; <$fh> };
-       close $fh;
-       my $msg = Email::MIME->new($str);
-
+       my $eml = 't/utf8.eml';
+       my $msg = PublicInbox::InboxWritable::mime_from_path($eml) or
+               die "failed to open $eml: $!";
        my $from = $msg->header('From');
        my ($author) = PublicInbox::Address::names($from);
        my ($email) = PublicInbox::Address::emails($from);
@@ -300,7 +298,7 @@ Subject: this message will be trained as spam
 Date: Thu, 01 Jan 1970 00:00:00 +0000
 
 EOF
-       system(qw(git config --file), $pi_config, "$cfgpfx.listid", $list_id);
+       xsys(qw(git config --file), $pi_config, "$cfgpfx.listid", $list_id);
        $? == 0 or die "failed to set listid $?";
        my $in = $simple->as_string;
        ok(run_script(['-mda'], undef, { 0 => \$in }),