t/httpd-corner.t | 8 ++++---- t/indexlevels-mirror.t | 10 ++++------ t/mda.t | 46 +++++++++++++++++++++++----------------------- t/nntpd-tls.t | 2 +- t/solver_git.t | 9 +++++---- t/v2mirror.t | 10 +++++----- t/view.t | 12 ++++++------ t/www_listing.t | 4 ++-- diff --git a/t/httpd-corner.t b/t/httpd-corner.t index 551af2b21526c822e7f479186d668d4ed380be85..a8cdb2e97ae8d43c40557a81eda97f4b46797d8f 100644 --- a/t/httpd-corner.t +++ b/t/httpd-corner.t @@ -553,16 +553,16 @@ # filter out pipes inherited from the parent my @this = `lsof -p $$`; my $bad; - sub extract_inodes { + my $extract_inodes = sub { map {; my @f = split(' ', $_); my $inode = $f[-2]; $bad = $_ if $inode !~ /\A[0-9]+\z/; $inode => 1; } grep (/\bpipe\b/, @_); - } - my %child = extract_inodes(@lsof); - my %parent = extract_inodes(@this); + }; + my %child = $extract_inodes->(@lsof); + my %parent = $extract_inodes->(@this); skip("inode not in expected format: $bad", 1) if defined($bad); delete @child{(keys %parent)}; is_deeply([], [keys %child], 'no extra pipes with -W0'); diff --git a/t/indexlevels-mirror.t b/t/indexlevels-mirror.t index 3d4813bec9e814227b3dbc0c8f9480a066d50ce8..aae42510491d2d9759ce2fda2c58c0e1f5cfe9de 100644 --- a/t/indexlevels-mirror.t +++ b/t/indexlevels-mirror.t @@ -16,8 +16,6 @@ eval "require $mod"; plan skip_all => "$mod missing for $0" if $@; } -my @xcpdb = qw(-xcpdb -q); - my $mime = PublicInbox::MIME->create( header => [ From => 'a@example.com', @@ -29,7 +27,7 @@ body => "hello world\n", ); sub import_index_incremental { - my ($v, $level) = @_; + my ($v, $level, $mime) = @_; my $this = "pi-$v-$level-indexlevels"; my ($tmpdir, $for_destroy) = tmpdir(); local $ENV{PI_CONFIG} = "$tmpdir/config"; @@ -120,7 +118,7 @@ @rw_nums = map { $_->{num} } @{$ibx->over->query_ts(0, 0)}; is_deeply(\@rw_nums, [1], 'unindex NNTP article'.$v.$level); if ($level ne 'basic') { - ok(run_script([@xcpdb, $mirror]), "v$v xcpdb OK"); + ok(run_script(['-xcpdb', '-q', $mirror]), "v$v xcpdb OK"); is(PublicInbox::Admin::detect_indexlevel($ro_mirror), $level, 'indexlevel detectable by Admin after xcpdb v' .$v.$level); delete $ro_mirror->{$_} for (qw(over search)); @@ -167,13 +165,13 @@ 'indexlevel detectable by Admin '.$v.$level); } # we can probably cull some other tests -import_index_incremental($PI_TEST_VERSION, 'basic'); +import_index_incremental($PI_TEST_VERSION, 'basic', $mime); SKIP: { require PublicInbox::Search; PublicInbox::Search::load_xapian() or skip 'Search::Xapian missing', 2; foreach my $l (qw(medium full)) { - import_index_incremental($PI_TEST_VERSION, $l); + import_index_incremental($PI_TEST_VERSION, $l, $mime); } } diff --git a/t/mda.t b/t/mda.t index 47d061322744be3c8745b4f84f9b80c8f6bab94e..3686a97bbe42977b23cbbba428ec16f830cc8fdf 100644 --- a/t/mda.t +++ b/t/mda.t @@ -23,6 +23,23 @@ my $faildir = "$home/faildir/"; my $mime; my $git = PublicInbox::Git->new($maindir); +my $fail_bad_header = sub ($$$) { + my ($good_rev, $msg, $in) = @_; + my @f = glob("$faildir/*/*"); + unlink @f if @f; + my ($out, $err) = ("", ""); + my $opt = { 0 => \$in, 1 => \$out, 2 => \$err }; + local $ENV{PATH} = $main_path; + ok(run_script(['-mda'], undef, $opt), + "no error on undeliverable ($msg)"); + my $rev = $git->qx(qw(rev-list HEAD)); + chomp $rev; + is($rev, $good_rev, "bad revision not commited ($msg)"); + @f = glob("$faildir/*/*"); + is(scalar @f, 1, "faildir written to"); + [ $in, $out, $err ]; +}; + { ok(-x "$main_bin/spamc", "spamc ham mock found (run in top of source tree"); @@ -110,14 +127,14 @@ my @new = <$faildir/new/*>; is(scalar @new, 1, "PI_EMERGENCY is written to"); } - fail_bad_header($good_rev, "bad recipient", <<""); + $fail_bad_header->($good_rev, "bad recipient", <<""); From: Me To: You Message-Id: Subject: hihi Date: Thu, 01 Jan 1970 00:00:00 +0000 - my $fail = fail_bad_header($good_rev, "duplicate Message-ID", <<""); + my $fail = $fail_bad_header->($good_rev, "duplicate Message-ID", <<""); From: Me To: You Cc: $addr @@ -127,26 +144,26 @@ Date: Thu, 01 Jan 1970 00:00:00 +0000 like($fail->[2], qr/CONFLICT/, "duplicate Message-ID message"); - fail_bad_header($good_rev, "missing From:", <<""); + $fail_bad_header->($good_rev, "missing From:", <<""); To: $addr Message-ID: Subject: hihi Date: Thu, 01 Jan 1970 00:00:00 +0000 - fail_bad_header($good_rev, "short subject:", <<""); + $fail_bad_header->($good_rev, "short subject:", <<""); To: $addr From: cat\@example.com Message-ID: Subject: a Date: Thu, 01 Jan 1970 00:00:00 +0000 - fail_bad_header($good_rev, "no date", <<""); + $fail_bad_header->($good_rev, "no date", <<""); To: $addr From: u\@example.com Message-ID: Subject: hihi - fail_bad_header($good_rev, "bad date", <<""); + $fail_bad_header->($good_rev, "bad date", <<""); To: $addr From: u\@example.com Message-ID: @@ -329,20 +346,3 @@ like($err, qr/multiple List-ID/, 'warned about multiple List-ID'); } done_testing(); - -sub fail_bad_header { - my ($good_rev, $msg, $in) = @_; - my @f = glob("$faildir/*/*"); - unlink @f if @f; - my ($out, $err) = ("", ""); - my $opt = { 0 => \$in, 1 => \$out, 2 => \$err }; - local $ENV{PATH} = $main_path; - ok(run_script(['-mda'], undef, $opt), - "no error on undeliverable ($msg)"); - my $rev = $git->qx(qw(rev-list HEAD)); - chomp $rev; - is($rev, $good_rev, "bad revision not commited ($msg)"); - @f = glob("$faildir/*/*"); - is(scalar @f, 1, "faildir written to"); - [ $in, $out, $err ]; -} diff --git a/t/nntpd-tls.t b/t/nntpd-tls.t index bbcc04c0c0e063a35b1d7b018831b3d6ae9c0469..c6dceaaa660793b8f6ce67fa1b8f57cd081f26fc 100644 --- a/t/nntpd-tls.t +++ b/t/nntpd-tls.t @@ -28,7 +28,7 @@ require './t/common.perl'; require PublicInbox::InboxWritable; require PublicInbox::MIME; require PublicInbox::SearchIdx; -my $need_zlib; +our $need_zlib; eval { require Compress::Raw::Zlib } or $need_zlib = 'Compress::Raw::Zlib missing'; my $version = 2; # v2 needs newer git diff --git a/t/solver_git.t b/t/solver_git.t index 6bac17ead0cad4ddc9cc2a4d5fed802b8e155a6d..88f83bdb7ae28525b75c7e97bb3a374817930dc2 100644 --- a/t/solver_git.t +++ b/t/solver_git.t @@ -32,15 +32,16 @@ my $ibx = PublicInbox::Inbox->new($opts); my $im = PublicInbox::V2Writable->new($ibx, 1); $im->{parallel} = 0; -sub deliver_patch ($) { +my $deliver_patch = sub ($) { open my $fh, '<', $_[0] or die "open: $!"; my $mime = PublicInbox::MIME->new(do { local $/; <$fh> }); $im->add($mime); $im->done; -} +}; -deliver_patch('t/solve/0001-simple-mod.patch'); +$deliver_patch->('t/solve/0001-simple-mod.patch'); my $v1_0_0_tag = 'cb7c42b1e15577ed2215356a2bf925aef59cdd8d'; + my $git = PublicInbox::Git->new($git_dir); is('public-inbox 1.0.0', $git->commit_title($v1_0_0_tag), @@ -96,7 +97,7 @@ $solver = PublicInbox::SolverGit->new($ibx, sub { $res = $_[0] }); $solver->solve($psgi_env, $log, $git_v2_20_1_tag, {}); is($res, undef, 'no error on a tag not in our repo'); -deliver_patch('t/solve/0002-rename-with-modifications.patch'); +$deliver_patch->('t/solve/0002-rename-with-modifications.patch'); $solver = PublicInbox::SolverGit->new($ibx, sub { $res = $_[0] }); $solver->solve($psgi_env, $log, '0a92431', {}); ok($res, 'resolved without hints'); diff --git a/t/v2mirror.t b/t/v2mirror.t index a45a262e59dc7c16ee1b3c7564ddaae8d52e4155..213a5f1534d47e139840bf75920a93a9a7bfdb15 100644 --- a/t/v2mirror.t +++ b/t/v2mirror.t @@ -97,15 +97,15 @@ } $v2w->done; $ibx->cleanup; -sub fetch_each_epoch { +my $fetch_each_epoch = sub { foreach my $i (0..$epoch_max) { my $dir = "$tmpdir/m/git/$i.git"; is(system('git', "--git-dir=$dir", 'fetch', '-q'), 0, 'fetch successful'); } -} +}; -fetch_each_epoch(); +$fetch_each_epoch->(); my $mset = $mibx->search->reopen->query('m:15@example.com', {mset => 1}); is(scalar($mset->items), 0, 'new message not found in mirror, yet'); @@ -135,7 +135,7 @@ like($to_purge, qr/\A[a-f0-9]{40,}\z/, 'read blob to be purged'); $mset = $ibx->search->reopen->query('m:10@example.com', {mset => 1}); is(scalar($mset->items), 0, 'purged message gone from origin'); -fetch_each_epoch(); +$fetch_each_epoch->(); { $ibx->cleanup; PublicInbox::InboxWritable::cleanup($mibx); @@ -173,7 +173,7 @@ $mime->header_set('Subject', 'subject = 1'); ok($v2w->remove($mime), 'removed <1@example.com> from source'); $v2w->done; $ibx->cleanup; - fetch_each_epoch(); + $fetch_each_epoch->(); PublicInbox::InboxWritable::cleanup($mibx); my $cmd = [ "-index", "$tmpdir/m" ]; diff --git a/t/view.t b/t/view.t index 1de3a02cf2eaa717cd2c17f026aba87240a5b31a..92962b15f2007eeac9b3df438508edc5be94ea2f 100644 --- a/t/view.t +++ b/t/view.t @@ -24,8 +24,8 @@ www => Plack::Util::inline_object(style => sub { '' }), }; $ctx->{-inbox}->{-primary_address} = 'test@example.com'; -sub msg_html ($) { - my ($mime) = @_; +sub msg_html ($$) { + my ($ctx, $mime) = @_; my $s = ''; my $r = PublicInbox::View::msg_html($ctx, $mime); @@ -72,7 +72,7 @@ ], body => $body, )->as_string; my $mime = Email::MIME->new($s); - my $html = msg_html($mime); + my $html = msg_html($ctx, $mime); # ghetto tests like($html, qr! $parts, ); - my $html = msg_html($mime); + my $html = msg_html($ctx, $mime); like($html, qr/hi\n.*-- Attachment #2.*\nbye\n/s, "multipart split"); } @@ -131,7 +131,7 @@ ], parts => $parts, ); - my $html = msg_html($mime); + my $html = msg_html($ctx, $mime); like($html, qr!.*Attachment #2: foo&(?:amp|#38);\.patch --!, "parts split with filename"); } @@ -157,7 +157,7 @@ parts => $parts, ); my $orig = $mime->body_raw; - my $html = msg_html($mime); + my $html = msg_html($ctx, $mime); like($orig, qr/hi =3D bye=/, "our test used QP correctly"); like($html, qr/\bhi = bye\b/, "HTML output decoded QP"); } diff --git a/t/www_listing.t b/t/www_listing.t index c9201213c12482056b48984b2ac39a8c9ffeb8b1..e1263360c68f1d21d2ad325dfbaa6bc033881e9a 100644 --- a/t/www_listing.t +++ b/t/www_listing.t @@ -33,7 +33,7 @@ like(PublicInbox::WwwListing::fingerprint($bare), qr/\A[a-f0-9]{40}\z/, 'got fingerprint with non-empty repo'); sub tiny_test { - my ($host, $port) = @_; + my ($json, $host, $port) = @_; my $http = HTTP::Tiny->new; my $res = $http->get("http://$host:$port/manifest.js.gz"); is($res->{status}, 200, 'got manifest'); @@ -107,7 +107,7 @@ my $cmd = [ '-httpd', '-W0', "--stdout=$out", "--stderr=$err" ]; $td = start_script($cmd, $env, { 3 => $sock }); $sock = undef; - tiny_test($host, $port); + tiny_test($json, $host, $port); skip 'skipping grok-pull integration test', 2 if !which('grok-pull');