From 3c313f9034aac96182e2efdc2f92c40803626f32 Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Wed, 18 Dec 2019 03:36:44 +0000 Subject: tests: move t/common.perl to PublicInbox::TestCommon We want to be able to use run_script with *.t files, so t/common.perl putting subs into the top-level "main" namespace won't work. Instead, make it a module which uses Exporter like other libraries. --- t/admin.t | 2 +- t/altid.t | 2 +- t/altid_v2.t | 2 +- t/cgi.t | 2 +- t/common.perl | 285 ---------------------------------------------- t/config.t | 2 +- t/convert-compact.t | 2 +- t/edit.t | 2 +- t/emergency.t | 2 +- t/feed.t | 2 +- t/filter_rubylang.t | 2 +- t/git.t | 2 +- t/html_index.t | 2 +- t/httpd-corner.t | 2 +- t/httpd-https.t | 2 +- t/httpd-unix.t | 2 +- t/httpd.t | 2 +- t/import.t | 2 +- t/indexlevels-mirror.t | 2 +- t/init.t | 2 +- t/mda.t | 2 +- t/mda_filter_rubylang.t | 2 +- t/msgmap.t | 2 +- t/nntpd-tls.t | 2 +- t/nntpd.t | 2 +- t/nulsubject.t | 2 +- t/over.t | 2 +- t/plack.t | 2 +- t/psgi_attach.t | 2 +- t/psgi_bad_mids.t | 2 +- t/psgi_mount.t | 2 +- t/psgi_multipart_not.t | 2 +- t/psgi_scan_all.t | 2 +- t/psgi_search.t | 2 +- t/psgi_text.t | 2 +- t/psgi_v2.t | 2 +- t/purge.t | 2 +- t/replace.t | 2 +- t/search-thr-index.t | 2 +- t/search.t | 2 +- t/solver_git.t | 2 +- t/spamcheck_spamc.t | 2 +- t/v1-add-remove-add.t | 2 +- t/v1reindex.t | 2 +- t/v2-add-remove-add.t | 2 +- t/v2mda.t | 2 +- t/v2mirror.t | 2 +- t/v2reindex.t | 2 +- t/v2writable.t | 2 +- t/watch_filter_rubylang.t | 2 +- t/watch_maildir.t | 2 +- t/watch_maildir_v2.t | 2 +- t/www_listing.t | 2 +- t/xcpdb-reshard.t | 2 +- 54 files changed, 53 insertions(+), 338 deletions(-) delete mode 100644 t/common.perl (limited to 't') diff --git a/t/admin.t b/t/admin.t index 6458982b..b517d2f8 100644 --- a/t/admin.t +++ b/t/admin.t @@ -3,7 +3,7 @@ use strict; use warnings; use Test::More; -require './t/common.perl'; +use PublicInbox::TestCommon; use_ok 'PublicInbox::Admin', qw(resolve_repo_dir); my ($tmpdir, $for_destroy) = tmpdir(); my $git_dir = "$tmpdir/v1"; diff --git a/t/altid.t b/t/altid.t index 86e7f9de..fc5bcbc2 100644 --- a/t/altid.t +++ b/t/altid.t @@ -3,7 +3,7 @@ use strict; use warnings; use Test::More; -require './t/common.perl'; +use PublicInbox::TestCommon; foreach my $mod (qw(DBD::SQLite Search::Xapian)) { eval "require $mod"; plan skip_all => "$mod missing for altid.t" if $@; diff --git a/t/altid_v2.t b/t/altid_v2.t index 9e152fc4..5bd62e13 100644 --- a/t/altid_v2.t +++ b/t/altid_v2.t @@ -3,7 +3,7 @@ use strict; use warnings; use Test::More; -require './t/common.perl'; +use PublicInbox::TestCommon; require_git(2.6); foreach my $mod (qw(DBD::SQLite Search::Xapian)) { eval "require $mod"; diff --git a/t/cgi.t b/t/cgi.t index 62cea499..424b738e 100644 --- a/t/cgi.t +++ b/t/cgi.t @@ -6,7 +6,7 @@ use strict; use warnings; use Test::More; use Email::MIME; -require './t/common.perl'; +use PublicInbox::TestCommon; my ($tmpdir, $for_destroy) = tmpdir(); my $home = "$tmpdir/pi-home"; my $pi_home = "$home/.public-inbox"; diff --git a/t/common.perl b/t/common.perl deleted file mode 100644 index 288a0a19..00000000 --- a/t/common.perl +++ /dev/null @@ -1,285 +0,0 @@ -# Copyright (C) 2015-2019 all contributors -# License: AGPL-3.0+ - -use Fcntl qw(FD_CLOEXEC F_SETFD F_GETFD :seek); -use POSIX qw(dup2); -use strict; -use warnings; -use IO::Socket::INET; - -sub tmpdir (;$) { - my ($base) = @_; - require File::Temp; - unless (defined $base) { - ($base) = ($0 =~ m!\b([^/]+)\.[^\.]+\z!); - } - my $tmpdir = File::Temp->newdir("pi-$base-$$-XXXXXX", TMPDIR => 1); - ($tmpdir->dirname, $tmpdir); -} - -sub tcp_server () { - IO::Socket::INET->new( - LocalAddr => '127.0.0.1', - ReuseAddr => 1, - Proto => 'tcp', - Type => Socket::SOCK_STREAM(), - Listen => 1024, - Blocking => 0, - ) -} - -sub tcp_connect { - my ($dest, %opt) = @_; - my $s = IO::Socket::INET->new( - Proto => 'tcp', - Type => Socket::SOCK_STREAM(), - PeerAddr => $dest->sockhost . ':' . $dest->sockport, - %opt, - ); - $s->autoflush(1); - $s; -} - -sub require_git ($;$) { - my ($req, $maybe) = @_; - my ($req_maj, $req_min) = split(/\./, $req); - my ($cur_maj, $cur_min) = (`git --version` =~ /version (\d+)\.(\d+)/); - - my $req_int = ($req_maj << 24) | ($req_min << 16); - my $cur_int = ($cur_maj << 24) | ($cur_min << 16); - if ($cur_int < $req_int) { - return 0 if $maybe; - plan skip_all => "git $req+ required, have $cur_maj.$cur_min"; - } - 1; -} - -sub key2script ($) { - my ($key) = @_; - return $key if $key =~ m!\A/!; - # n.b. we may have scripts which don't start with "public-inbox" in - # the future: - $key =~ s/\A([-\.])/public-inbox$1/; - 'blib/script/'.$key; -} - -sub _prepare_redirects ($) { - my ($fhref) = @_; - my @x = ([ \*STDIN, '<&' ], [ \*STDOUT, '>&' ], [ \*STDERR, '>&' ]); - for (my $fd = 0; $fd <= $#x; $fd++) { - my $fh = $fhref->[$fd] or next; - my ($oldfh, $mode) = @{$x[$fd]}; - open $oldfh, $mode, $fh or die "$$oldfh $mode redirect: $!"; - } -} - -# $opt->{run_mode} (or $ENV{TEST_RUN_MODE}) allows chosing between -# three ways to spawn our own short-lived Perl scripts for testing: -# -# 0 - (fork|vfork) + execve, the most realistic but slowest -# 1 - preloading and running in a forked subprocess (fast) -# 2 - preloading and running in current process (slightly faster than 1) -# -# 2 is not compatible with scripts which use "exit" (which we'll try to -# avoid in the future). -# The default is 2. -our $run_script_exit_code; -sub RUN_SCRIPT_EXIT () { "RUN_SCRIPT_EXIT\n" }; -sub run_script_exit (;$) { - $run_script_exit_code = $_[0] // 0; - die RUN_SCRIPT_EXIT; -} - -my %cached_scripts; -sub key2sub ($) { - my ($key) = @_; - $cached_scripts{$key} //= do { - my $f = key2script($key); - open my $fh, '<', $f or die "open $f: $!"; - my $str = do { local $/; <$fh> }; - my ($fc, $rest) = ($key =~ m/([a-z])([a-z0-9]+)\z/); - $fc = uc($fc); - my $pkg = "PublicInbox::TestScript::$fc$rest"; - eval <can('main'); - } -} - -sub _run_sub ($$$) { - my ($sub, $key, $argv) = @_; - local @ARGV = @$argv; - $run_script_exit_code = undef; - my $exit_code = eval { $sub->(@$argv) }; - if ($@ eq RUN_SCRIPT_EXIT) { - $@ = ''; - $exit_code = $run_script_exit_code; - $? = ($exit_code << 8); - } elsif (defined($exit_code)) { - $? = ($exit_code << 8); - } elsif ($@) { # mimic die() behavior when uncaught - warn "E: eval-ed $key: $@\n"; - $? = ($! << 8) if $!; - $? = (255 << 8) if $? == 0; - } else { - die "BUG: eval-ed $key: no exit code or \$@\n"; - } -} - -sub run_script ($;$$) { - my ($cmd, $env, $opt) = @_; - my ($key, @argv) = @$cmd; - my $run_mode = $ENV{TEST_RUN_MODE} // $opt->{run_mode} // 1; - my $sub = $run_mode == 0 ? undef : key2sub($key); - my $fhref = []; - my $spawn_opt = {}; - for my $fd (0..2) { - my $redir = $opt->{$fd}; - next unless ref($redir); - open my $fh, '+>', undef or die "open: $!"; - $fhref->[$fd] = $fh; - $spawn_opt->{$fd} = fileno($fh); - next if $fd > 0; - $fh->autoflush(1); - print $fh $$redir or die "print: $!"; - seek($fh, 0, SEEK_SET) or die "seek: $!"; - } - if ($run_mode == 0) { - # spawn an independent new process, like real-world use cases: - require PublicInbox::Spawn; - my $cmd = [ key2script($key), @argv ]; - my $pid = PublicInbox::Spawn::spawn($cmd, $env, $spawn_opt); - defined($pid) or die "spawn: $!"; - if (defined $pid) { - my $r = waitpid($pid, 0); - defined($r) or die "waitpid: $!"; - $r == $pid or die "waitpid: expected $pid, got $r"; - } - } else { # localize and run everything in the same process: - local *STDIN = *STDIN; - local *STDOUT = *STDOUT; - local *STDERR = *STDERR; - local %ENV = $env ? (%ENV, %$env) : %ENV; - local %SIG = %SIG; - local $0 = join(' ', @$cmd); - _prepare_redirects($fhref); - _run_sub($sub, $key, \@argv); - } - - # slurp the redirects back into user-supplied strings - for my $fd (1..2) { - my $fh = $fhref->[$fd] or next; - seek($fh, 0, SEEK_SET) or die "seek: $!"; - my $redir = $opt->{$fd}; - local $/; - $$redir = <$fh>; - } - $? == 0; -} - -sub wait_for_tail () { sleep(2) } - -sub start_script { - my ($cmd, $env, $opt) = @_; - my ($key, @argv) = @$cmd; - my $run_mode = $ENV{TEST_RUN_MODE} // $opt->{run_mode} // 1; - my $sub = $run_mode == 0 ? undef : key2sub($key); - my $tail_pid; - if (my $tail_cmd = $ENV{TAIL}) { - my @paths; - for (@argv) { - next unless /\A--std(?:err|out)=(.+)\z/; - push @paths, $1; - } - if (@paths) { - defined($tail_pid = fork) or die "fork: $!\n"; - if ($tail_pid == 0) { - # make sure files exist, first - open my $fh, '>>', $_ for @paths; - open(STDOUT, '>&STDERR') or die "1>&2: $!"; - exec(split(' ', $tail_cmd), @paths); - die "$tail_cmd failed: $!"; - } - wait_for_tail(); - } - } - defined(my $pid = fork) or die "fork: $!\n"; - if ($pid == 0) { - # pretend to be systemd (cf. sd_listen_fds(3)) - # 3 == SD_LISTEN_FDS_START - my $fd; - for ($fd = 0; 1; $fd++) { - my $s = $opt->{$fd}; - last if $fd >= 3 && !defined($s); - next unless $s; - my $fl = fcntl($s, F_GETFD, 0); - if (($fl & FD_CLOEXEC) != FD_CLOEXEC) { - warn "got FD:".fileno($s)." w/o CLOEXEC\n"; - } - fcntl($s, F_SETFD, $fl &= ~FD_CLOEXEC); - dup2(fileno($s), $fd) or die "dup2 failed: $!\n"; - } - %ENV = (%ENV, %$env) if $env; - my $fds = $fd - 3; - if ($fds > 0) { - $ENV{LISTEN_PID} = $$; - $ENV{LISTEN_FDS} = $fds; - } - $0 = join(' ', @$cmd); - if ($sub) { - _run_sub($sub, $key, \@argv); - POSIX::_exit($? >> 8); - } else { - exec(key2script($key), @argv); - die "FAIL: ",join(' ', $key, @argv), ": $!\n"; - } - } - TestProcess->new($pid, $tail_pid); -} - -package TestProcess; -use strict; - -# prevent new threads from inheriting these objects -sub CLONE_SKIP { 1 } - -sub new { - my ($klass, $pid, $tail_pid) = @_; - bless { pid => $pid, tail_pid => $tail_pid, owner => $$ }, $klass; -} - -sub kill { - my ($self, $sig) = @_; - CORE::kill($sig // 'TERM', $self->{pid}); -} - -sub join { - my ($self) = @_; - my $pid = delete $self->{pid} or return; - my $ret = waitpid($pid, 0); - defined($ret) or die "waitpid($pid): $!"; - $ret == $pid or die "waitpid($pid) != $ret"; -} - -sub DESTROY { - my ($self) = @_; - return if $self->{owner} != $$; - if (my $tail = delete $self->{tail_pid}) { - ::wait_for_tail(); - CORE::kill('TERM', $tail); - } - my $pid = delete $self->{pid} or return; - CORE::kill('TERM', $pid); -} - -1; diff --git a/t/config.t b/t/config.t index ade2e796..db3f9b2a 100644 --- a/t/config.t +++ b/t/config.t @@ -4,7 +4,7 @@ use strict; use warnings; use Test::More; use PublicInbox::Config; -require './t/common.perl'; +use PublicInbox::TestCommon; my ($tmpdir, $for_destroy) = tmpdir(); { diff --git a/t/convert-compact.t b/t/convert-compact.t index b8dc5ed5..c6da64ea 100644 --- a/t/convert-compact.t +++ b/t/convert-compact.t @@ -5,7 +5,7 @@ use warnings; use Test::More; use PublicInbox::MIME; use PublicInbox::Spawn qw(which); -require './t/common.perl'; +use PublicInbox::TestCommon; require_git(2.6); my @mods = qw(DBD::SQLite Search::Xapian); foreach my $mod (@mods) { diff --git a/t/edit.t b/t/edit.t index 122aa19f..9a78b45d 100644 --- a/t/edit.t +++ b/t/edit.t @@ -4,7 +4,7 @@ use strict; use warnings; use Test::More; -require './t/common.perl'; +use PublicInbox::TestCommon; require_git(2.6); require PublicInbox::Inbox; require PublicInbox::InboxWritable; diff --git a/t/emergency.t b/t/emergency.t index d6c7b6d5..1cb1098d 100644 --- a/t/emergency.t +++ b/t/emergency.t @@ -3,7 +3,7 @@ use strict; use warnings; use Test::More; -require './t/common.perl'; +use PublicInbox::TestCommon; my ($tmpdir, $for_destroy) = tmpdir(); use_ok 'PublicInbox::Emergency'; diff --git a/t/feed.t b/t/feed.t index daf97a72..97468c73 100644 --- a/t/feed.t +++ b/t/feed.t @@ -10,7 +10,7 @@ use PublicInbox::Import; use PublicInbox::Config; use PublicInbox::Inbox; my $have_xml_feed = eval { require XML::Feed; 1 }; -require './t/common.perl'; +use PublicInbox::TestCommon; sub string_feed { my $res = PublicInbox::Feed::generate($_[0]); diff --git a/t/filter_rubylang.t b/t/filter_rubylang.t index 33753925..576cbdeb 100644 --- a/t/filter_rubylang.t +++ b/t/filter_rubylang.t @@ -4,7 +4,7 @@ use strict; use warnings; use Test::More; use Email::MIME; -require './t/common.perl'; +use PublicInbox::TestCommon; use_ok 'PublicInbox::Filter::RubyLang'; my $f = PublicInbox::Filter::RubyLang->new; diff --git a/t/git.t b/t/git.t index cc4fc591..d4694f44 100644 --- a/t/git.t +++ b/t/git.t @@ -3,7 +3,7 @@ use strict; use warnings; use Test::More; -require './t/common.perl'; +use PublicInbox::TestCommon; my ($dir, $for_destroy) = tmpdir(); use PublicInbox::Spawn qw(popen_rd); diff --git a/t/html_index.t b/t/html_index.t index 51ea9a25..55aa6dc7 100644 --- a/t/html_index.t +++ b/t/html_index.t @@ -8,7 +8,7 @@ use PublicInbox::Feed; use PublicInbox::Git; use PublicInbox::Import; use PublicInbox::Inbox; -require './t/common.perl'; +use PublicInbox::TestCommon; my ($tmpdir, $for_destroy) = tmpdir(); my $git_dir = "$tmpdir/gittest"; my $ibx = PublicInbox::Inbox->new({ diff --git a/t/httpd-corner.t b/t/httpd-corner.t index a8cdb2e9..fb3ffcf1 100644 --- a/t/httpd-corner.t +++ b/t/httpd-corner.t @@ -19,7 +19,7 @@ use IO::Socket::UNIX; use Fcntl qw(:seek); use Socket qw(IPPROTO_TCP TCP_NODELAY SOL_SOCKET); use POSIX qw(mkfifo); -require './t/common.perl'; +use PublicInbox::TestCommon; my ($tmpdir, $for_destroy) = tmpdir(); my $fifo = "$tmpdir/fifo"; ok(defined mkfifo($fifo, 0777), 'created FIFO'); diff --git a/t/httpd-https.t b/t/httpd-https.t index de74c20e..1d2e4d5c 100644 --- a/t/httpd-https.t +++ b/t/httpd-https.t @@ -17,7 +17,7 @@ unless (-r $key && -r $cert) { } use_ok 'PublicInbox::TLS'; use_ok 'IO::Socket::SSL'; -require './t/common.perl'; +use PublicInbox::TestCommon; my $psgi = "./t/httpd-corner.psgi"; my ($tmpdir, $for_destroy) = tmpdir(); my $err = "$tmpdir/stderr.log"; diff --git a/t/httpd-unix.t b/t/httpd-unix.t index 2c8f8d6b..bd4ee12e 100644 --- a/t/httpd-unix.t +++ b/t/httpd-unix.t @@ -4,7 +4,7 @@ use strict; use warnings; use Test::More; -require './t/common.perl'; +use PublicInbox::TestCommon; use Errno qw(EADDRINUSE); foreach my $mod (qw(Plack::Util Plack::Builder HTTP::Date HTTP::Status)) { diff --git a/t/httpd.t b/t/httpd.t index f0b4efb4..517329fb 100644 --- a/t/httpd.t +++ b/t/httpd.t @@ -9,7 +9,7 @@ foreach my $mod (qw(Plack::Util Plack::Builder HTTP::Date HTTP::Status)) { plan skip_all => "$mod missing for httpd.t" if $@; } use Socket qw(IPPROTO_TCP SOL_SOCKET); -require './t/common.perl'; +use PublicInbox::TestCommon; # FIXME: too much setup my ($tmpdir, $for_destroy) = tmpdir(); diff --git a/t/import.t b/t/import.t index 2f5b08a5..3cf7e2d2 100644 --- a/t/import.t +++ b/t/import.t @@ -10,7 +10,7 @@ use PublicInbox::Spawn qw(spawn); use IO::File; use Fcntl qw(:DEFAULT); use File::Temp qw/tempfile/; -require './t/common.perl'; +use PublicInbox::TestCommon; my ($dir, $for_destroy) = tmpdir(); is(system(qw(git init -q --bare), $dir), 0, 'git init successful'); diff --git a/t/indexlevels-mirror.t b/t/indexlevels-mirror.t index aae42510..876abd2c 100644 --- a/t/indexlevels-mirror.t +++ b/t/indexlevels-mirror.t @@ -7,7 +7,7 @@ use PublicInbox::MIME; use PublicInbox::Inbox; use PublicInbox::InboxWritable; require PublicInbox::Admin; -require './t/common.perl'; +use PublicInbox::TestCommon; my $PI_TEST_VERSION = $ENV{PI_TEST_VERSION} || 2; require_git('2.6') if $PI_TEST_VERSION == 2; diff --git a/t/init.t b/t/init.t index 16550868..f70d1c20 100644 --- a/t/init.t +++ b/t/init.t @@ -4,7 +4,7 @@ use strict; use warnings; use Test::More; use PublicInbox::Config; -require './t/common.perl'; +use PublicInbox::TestCommon; use File::Basename; my ($tmpdir, $for_destroy) = tmpdir(); sub quiet_fail { diff --git a/t/mda.t b/t/mda.t index 3686a97b..4556e323 100644 --- a/t/mda.t +++ b/t/mda.t @@ -7,7 +7,7 @@ use Email::MIME; use Cwd qw(getcwd); use PublicInbox::MID qw(mid2path); use PublicInbox::Git; -require './t/common.perl'; +use PublicInbox::TestCommon; my ($tmpdir, $for_destroy) = tmpdir(); my $home = "$tmpdir/pi-home"; my $pi_home = "$home/.public-inbox"; diff --git a/t/mda_filter_rubylang.t b/t/mda_filter_rubylang.t index ce17d5a9..a5b6af3c 100644 --- a/t/mda_filter_rubylang.t +++ b/t/mda_filter_rubylang.t @@ -5,7 +5,7 @@ use warnings; use Test::More; use PublicInbox::MIME; use PublicInbox::Config; -require './t/common.perl'; +use PublicInbox::TestCommon; require_git(2.6); my @mods = qw(DBD::SQLite Search::Xapian); foreach my $mod (@mods) { diff --git a/t/msgmap.t b/t/msgmap.t index 7fcd131a..6edeed56 100644 --- a/t/msgmap.t +++ b/t/msgmap.t @@ -3,7 +3,7 @@ use strict; use warnings; use Test::More; -require './t/common.perl'; +use PublicInbox::TestCommon; foreach my $mod (qw(DBD::SQLite)) { eval "require $mod"; diff --git a/t/nntpd-tls.t b/t/nntpd-tls.t index c6dceaaa..25b7bd1c 100644 --- a/t/nntpd-tls.t +++ b/t/nntpd-tls.t @@ -24,7 +24,7 @@ unless (-r $key && -r $cert) { use_ok 'PublicInbox::TLS'; use_ok 'IO::Socket::SSL'; -require './t/common.perl'; +use PublicInbox::TestCommon; require PublicInbox::InboxWritable; require PublicInbox::MIME; require PublicInbox::SearchIdx; diff --git a/t/nntpd.t b/t/nntpd.t index 5b697344..30f3fb9c 100644 --- a/t/nntpd.t +++ b/t/nntpd.t @@ -15,7 +15,7 @@ use IO::Socket; use Socket qw(IPPROTO_TCP TCP_NODELAY); use Net::NNTP; use Sys::Hostname; -require './t/common.perl'; +use PublicInbox::TestCommon; # FIXME: make easier to test both versions my $version = $ENV{PI_TEST_VERSION} || 2; diff --git a/t/nulsubject.t b/t/nulsubject.t index 617997c0..45f95a9e 100644 --- a/t/nulsubject.t +++ b/t/nulsubject.t @@ -3,7 +3,7 @@ use strict; use warnings; use Test::More; -require './t/common.perl'; +use PublicInbox::TestCommon; use_ok 'PublicInbox::Import'; use_ok 'PublicInbox::Git'; diff --git a/t/over.t b/t/over.t index 27168a33..5e33a0b0 100644 --- a/t/over.t +++ b/t/over.t @@ -4,7 +4,7 @@ use strict; use warnings; use Test::More; use Compress::Zlib qw(compress); -require './t/common.perl'; +use PublicInbox::TestCommon; foreach my $mod (qw(DBD::SQLite)) { eval "require $mod"; plan skip_all => "$mod missing for over.t" if $@; diff --git a/t/plack.t b/t/plack.t index 6023a419..c9a2cf79 100644 --- a/t/plack.t +++ b/t/plack.t @@ -4,7 +4,7 @@ use strict; use warnings; use Test::More; use Email::MIME; -require './t/common.perl'; +use PublicInbox::TestCommon; my $psgi = "./examples/public-inbox.psgi"; my ($tmpdir, $for_destroy) = tmpdir(); my $pi_config = "$tmpdir/config"; diff --git a/t/psgi_attach.t b/t/psgi_attach.t index 45f05bac..5a7129f9 100644 --- a/t/psgi_attach.t +++ b/t/psgi_attach.t @@ -4,7 +4,7 @@ use strict; use warnings; use Test::More; use Email::MIME; -require './t/common.perl'; +use PublicInbox::TestCommon; my ($tmpdir, $for_destroy) = tmpdir(); my $maindir = "$tmpdir/main.git"; my $addr = 'test-public@example.com'; diff --git a/t/psgi_bad_mids.t b/t/psgi_bad_mids.t index 0e8fa114..b22f3652 100644 --- a/t/psgi_bad_mids.t +++ b/t/psgi_bad_mids.t @@ -6,7 +6,7 @@ use Test::More; use PublicInbox::MIME; use PublicInbox::Config; use PublicInbox::WWW; -require './t/common.perl'; +use PublicInbox::TestCommon; my @mods = qw(DBD::SQLite HTTP::Request::Common Plack::Test URI::Escape Plack::Builder); foreach my $mod (@mods) { diff --git a/t/psgi_mount.t b/t/psgi_mount.t index ca573e1e..a2621a2a 100644 --- a/t/psgi_mount.t +++ b/t/psgi_mount.t @@ -4,7 +4,7 @@ use strict; use warnings; use Test::More; use Email::MIME; -require './t/common.perl'; +use PublicInbox::TestCommon; my ($tmpdir, $for_destroy) = tmpdir(); my $maindir = "$tmpdir/main.git"; my $addr = 'test-public@example.com'; diff --git a/t/psgi_multipart_not.t b/t/psgi_multipart_not.t index d3489f2d..9384d14a 100644 --- a/t/psgi_multipart_not.t +++ b/t/psgi_multipart_not.t @@ -6,7 +6,7 @@ use Test::More; use Email::MIME; use PublicInbox::Config; use PublicInbox::WWW; -require './t/common.perl'; +use PublicInbox::TestCommon; my @mods = qw(DBD::SQLite Search::Xapian HTTP::Request::Common Plack::Test URI::Escape Plack::Builder Plack::Test); foreach my $mod (@mods) { diff --git a/t/psgi_scan_all.t b/t/psgi_scan_all.t index 5d4cc263..fa636d32 100644 --- a/t/psgi_scan_all.t +++ b/t/psgi_scan_all.t @@ -5,7 +5,7 @@ use warnings; use Test::More; use Email::MIME; use PublicInbox::Config; -require './t/common.perl'; +use PublicInbox::TestCommon; my @mods = qw(HTTP::Request::Common Plack::Test URI::Escape DBD::SQLite); foreach my $mod (@mods) { eval "require $mod"; diff --git a/t/psgi_search.t b/t/psgi_search.t index 0c430aea..d1050437 100644 --- a/t/psgi_search.t +++ b/t/psgi_search.t @@ -9,7 +9,7 @@ use PublicInbox::Inbox; use PublicInbox::InboxWritable; use PublicInbox::WWW; use bytes (); # only for bytes::length -require './t/common.perl'; +use PublicInbox::TestCommon; my @mods = qw(DBD::SQLite Search::Xapian HTTP::Request::Common Plack::Test URI::Escape Plack::Builder); foreach my $mod (@mods) { diff --git a/t/psgi_text.t b/t/psgi_text.t index b9564181..ee4d9f14 100644 --- a/t/psgi_text.t +++ b/t/psgi_text.t @@ -4,7 +4,7 @@ use strict; use warnings; use Test::More; use Email::MIME; -require './t/common.perl'; +use PublicInbox::TestCommon; my ($tmpdir, $for_destroy) = tmpdir(); my $maindir = "$tmpdir/main.git"; my $addr = 'test-public@example.com'; diff --git a/t/psgi_v2.t b/t/psgi_v2.t index 1163e2bf..8e81e89b 100644 --- a/t/psgi_v2.t +++ b/t/psgi_v2.t @@ -3,7 +3,7 @@ use strict; use warnings; use Test::More; -require './t/common.perl'; +use PublicInbox::TestCommon; require_git(2.6); use PublicInbox::MIME; use PublicInbox::Config; diff --git a/t/purge.t b/t/purge.t index db09b731..0262f791 100644 --- a/t/purge.t +++ b/t/purge.t @@ -3,7 +3,7 @@ use strict; use warnings; use Test::More; -require './t/common.perl'; +use PublicInbox::TestCommon; require_git(2.6); my @mods = qw(DBI DBD::SQLite); foreach my $mod (@mods) { diff --git a/t/replace.t b/t/replace.t index 57290f96..2346c3a1 100644 --- a/t/replace.t +++ b/t/replace.t @@ -5,7 +5,7 @@ use warnings; use Test::More; use PublicInbox::MIME; use PublicInbox::InboxWritable; -require './t/common.perl'; +use PublicInbox::TestCommon; use Cwd qw(abs_path); require_git(2.6); # replace is v2 only, for now... foreach my $mod (qw(DBD::SQLite)) { diff --git a/t/search-thr-index.t b/t/search-thr-index.t index 4f793657..47454fe7 100644 --- a/t/search-thr-index.t +++ b/t/search-thr-index.t @@ -13,7 +13,7 @@ foreach my $mod (@mods) { } require PublicInbox::SearchIdx; require PublicInbox::Inbox; -require './t/common.perl'; +use PublicInbox::TestCommon; my ($tmpdir, $for_destroy) = tmpdir(); my $git_dir = "$tmpdir/a.git"; diff --git a/t/search.t b/t/search.t index 58684138..33a7596e 100644 --- a/t/search.t +++ b/t/search.t @@ -10,7 +10,7 @@ foreach my $mod (@mods) { }; require PublicInbox::SearchIdx; require PublicInbox::Inbox; -require './t/common.perl'; +use PublicInbox::TestCommon; use Email::MIME; my ($tmpdir, $for_destroy) = tmpdir(); my $git_dir = "$tmpdir/a.git"; diff --git a/t/solver_git.t b/t/solver_git.t index 88f83bdb..99ee9b5e 100644 --- a/t/solver_git.t +++ b/t/solver_git.t @@ -4,7 +4,7 @@ use strict; use warnings; use Test::More; use Cwd qw(abs_path); -require './t/common.perl'; +use PublicInbox::TestCommon; require_git(2.6); use PublicInbox::Spawn qw(spawn); diff --git a/t/spamcheck_spamc.t b/t/spamcheck_spamc.t index a4a01a8b..92b4fd40 100644 --- a/t/spamcheck_spamc.t +++ b/t/spamcheck_spamc.t @@ -6,7 +6,7 @@ use Test::More; use Email::Simple; use IO::File; use Fcntl qw(:DEFAULT SEEK_SET); -require './t/common.perl'; +use PublicInbox::TestCommon; my ($tmpdir, $for_destroy) = tmpdir(); use_ok 'PublicInbox::Spamcheck::Spamc'; diff --git a/t/v1-add-remove-add.t b/t/v1-add-remove-add.t index 13e9f29c..aabb2fa5 100644 --- a/t/v1-add-remove-add.t +++ b/t/v1-add-remove-add.t @@ -5,7 +5,7 @@ use warnings; use Test::More; use PublicInbox::MIME; use PublicInbox::Import; -require './t/common.perl'; +use PublicInbox::TestCommon; foreach my $mod (qw(DBD::SQLite Search::Xapian)) { eval "require $mod"; diff --git a/t/v1reindex.t b/t/v1reindex.t index c0e21a56..321b3b21 100644 --- a/t/v1reindex.t +++ b/t/v1reindex.t @@ -6,7 +6,7 @@ use Test::More; use PublicInbox::MIME; use PublicInbox::ContentId qw(content_digest); use File::Path qw(remove_tree); -require './t/common.perl'; +use PublicInbox::TestCommon; require_git(2.6); foreach my $mod (qw(DBD::SQLite Search::Xapian)) { diff --git a/t/v2-add-remove-add.t b/t/v2-add-remove-add.t index c0dec300..7cce2493 100644 --- a/t/v2-add-remove-add.t +++ b/t/v2-add-remove-add.t @@ -4,7 +4,7 @@ use strict; use warnings; use Test::More; use PublicInbox::MIME; -require './t/common.perl'; +use PublicInbox::TestCommon; require_git(2.6); foreach my $mod (qw(DBD::SQLite Search::Xapian)) { diff --git a/t/v2mda.t b/t/v2mda.t index 11a517e4..4b1249ea 100644 --- a/t/v2mda.t +++ b/t/v2mda.t @@ -6,7 +6,7 @@ use Test::More; use PublicInbox::MIME; use Fcntl qw(SEEK_SET); use Cwd; -require './t/common.perl'; +use PublicInbox::TestCommon; require_git(2.6); my $V = 2; diff --git a/t/v2mirror.t b/t/v2mirror.t index 213a5f15..e3c384fa 100644 --- a/t/v2mirror.t +++ b/t/v2mirror.t @@ -3,7 +3,7 @@ use strict; use warnings; use Test::More; -require './t/common.perl'; +use PublicInbox::TestCommon; use Cwd qw(abs_path); require_git(2.6); local $ENV{HOME} = abs_path('t'); diff --git a/t/v2reindex.t b/t/v2reindex.t index e222d0f1..a14bf798 100644 --- a/t/v2reindex.t +++ b/t/v2reindex.t @@ -6,7 +6,7 @@ use Test::More; use PublicInbox::MIME; use PublicInbox::ContentId qw(content_digest); use File::Path qw(remove_tree); -require './t/common.perl'; +use PublicInbox::TestCommon; require_git(2.6); foreach my $mod (qw(DBD::SQLite Search::Xapian)) { diff --git a/t/v2writable.t b/t/v2writable.t index 8bbcd45a..bf2064d0 100644 --- a/t/v2writable.t +++ b/t/v2writable.t @@ -5,7 +5,7 @@ use warnings; use Test::More; use PublicInbox::MIME; use PublicInbox::ContentId qw(content_digest); -require './t/common.perl'; +use PublicInbox::TestCommon; use Cwd qw(abs_path); require_git(2.6); foreach my $mod (qw(DBD::SQLite Search::Xapian)) { diff --git a/t/watch_filter_rubylang.t b/t/watch_filter_rubylang.t index c4078879..0ea680ee 100644 --- a/t/watch_filter_rubylang.t +++ b/t/watch_filter_rubylang.t @@ -2,7 +2,7 @@ # License: AGPL-3.0+ use strict; use warnings; -require './t/common.perl'; +use PublicInbox::TestCommon; use Test::More; use PublicInbox::MIME; use PublicInbox::Config; diff --git a/t/watch_maildir.t b/t/watch_maildir.t index d2e6fecd..38297043 100644 --- a/t/watch_maildir.t +++ b/t/watch_maildir.t @@ -5,7 +5,7 @@ use Test::More; use Email::MIME; use Cwd; use PublicInbox::Config; -require './t/common.perl'; +use PublicInbox::TestCommon; my @mods = qw(Filesys::Notify::Simple); foreach my $mod (@mods) { eval "require $mod"; diff --git a/t/watch_maildir_v2.t b/t/watch_maildir_v2.t index 53f1bdfc..77e4b981 100644 --- a/t/watch_maildir_v2.t +++ b/t/watch_maildir_v2.t @@ -5,7 +5,7 @@ use Test::More; use PublicInbox::MIME; use Cwd; use PublicInbox::Config; -require './t/common.perl'; +use PublicInbox::TestCommon; require_git(2.6); my @mods = qw(Search::Xapian DBD::SQLite Filesys::Notify::Simple); foreach my $mod (@mods) { diff --git a/t/www_listing.t b/t/www_listing.t index e1263360..75698ee5 100644 --- a/t/www_listing.t +++ b/t/www_listing.t @@ -5,7 +5,7 @@ use strict; use warnings; use Test::More; use PublicInbox::Spawn qw(which); -require './t/common.perl'; +use PublicInbox::TestCommon; my @mods = qw(URI::Escape Plack::Builder Digest::SHA IO::Compress::Gzip IO::Uncompress::Gunzip HTTP::Tiny); foreach my $mod (@mods) { diff --git a/t/xcpdb-reshard.t b/t/xcpdb-reshard.t index a4ab35d6..0d78d2b2 100644 --- a/t/xcpdb-reshard.t +++ b/t/xcpdb-reshard.t @@ -8,7 +8,7 @@ foreach my $mod (@mods) { eval "require $mod"; plan skip_all => "missing $mod for $0" if $@; }; -require './t/common.perl'; +use PublicInbox::TestCommon; require_git('2.6'); use PublicInbox::MIME; use PublicInbox::InboxWritable; -- cgit v1.2.3-24-ge0c7