run_script start_script key2sub xsys xsys_e xqx eml_load tick
have_xapian_compact json_utf8 setup_public_inboxes create_inbox
tcp_host_port test_lei lei lei_ok $lei_out $lei_err $lei_opt
- test_httpd xbail);
+ test_httpd xbail require_cmd);
require Test::More;
my @methods = grep(!/\W/, @Test::More::EXPORT);
eval(join('', map { "*$_=\\&Test::More::$_;" } @methods));
$s;
}
+sub require_cmd ($;$) {
+ my ($cmd, $maybe) = @_;
+ require PublicInbox::Spawn;
+ my $bin = PublicInbox::Spawn::which($cmd);
+ return $bin if $bin;
+ $maybe ? 0 : plan(skip_all => "$cmd missing from PATH for $0");
+}
+
+sub have_xapian_compact () {
+ require_cmd($ENV{XAPIAN_COMPACT} || 'xapian-compact', 1);
+}
+
sub require_git ($;$) {
my ($req, $maybe) = @_;
my ($req_maj, $req_min, $req_sub) = split(/\./, $req);
PublicInboxTestProcess->new($pid, $tail_pid);
}
-sub have_xapian_compact () {
- require PublicInbox::Spawn;
- # $ENV{XAPIAN_COMPACT} is used by PublicInbox/Xapcmd.pm, too
- PublicInbox::Spawn::which($ENV{XAPIAN_COMPACT} || 'xapian-compact');
-}
-
# favor lei() or lei_ok() over $lei for new code
sub lei (@) {
my ($cmd, $env, $xopt) = @_;
# License: GPL-1.0+ or Artistic-1.0-Perl
# <https://www.gnu.org/licenses/gpl-1.0.txt>
# <https://dev.perl.org/licenses/artistic.html>
-use strict;
-use warnings;
-use Test::More;
-use PublicInbox::TestCommon;
+use strict; use v5.10.1; use PublicInbox::TestCommon;
use_ok 'PublicInbox::DS';
if ('close-on-exec for epoll and kqueue') {
- use PublicInbox::Spawn qw(spawn which);
+ use PublicInbox::Spawn qw(spawn);
my $pid;
my $evfd_re = qr/(?:kqueue|eventpoll)/i;
is($l, undef, 'cloexec works and sleep(1) is running');
SKIP: {
- my $lsof = which('lsof') or skip 'lsof missing', 1;
+ my $lsof = require_cmd('lsof', 1) or skip 'lsof missing', 1;
my $rdr = { 2 => \(my $null) };
my @of = grep(/$evfd_re/, xqx([$lsof, '-p', $pid], {}, $rdr));
my $err = $?;
#!/usr/bin/perl -w
# Copyright (C) 2019-2021 all contributors <meta@public-inbox.org>
# License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
-use strict;
-use warnings;
-use Test::More;
-use PublicInbox::Spawn qw(which);
-use PublicInbox::TestCommon;
-use IO::Handle; # ->autoflush
+use strict; use v5.10.1; use PublicInbox::TestCommon; use IO::Handle; # ->autoflush
use Fcntl qw(:seek);
eval { require highlight } or
plan skip_all => "failed to load highlight.pm for $0";
is($$ref, $$lref, 'do_hl_lang matches do_hl');
SKIP: {
- my $w3m = which('w3m') or
+ my $w3m = require_cmd('w3m', 1) or
skip('w3m(1) missing to check output', 1);
my $cmd = [ $w3m, qw(-T text/html -dump -config /dev/null) ];
my $in = '<pre>' . $$ref . '</pre>';
# License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
# note: our HTTP server should be standalone and capable of running
# generic PSGI/Plack apps.
-use strict;
-use warnings;
-use Test::More;
+use strict; use v5.10.1; use PublicInbox::TestCommon;
use Time::HiRes qw(gettimeofday tv_interval);
-use PublicInbox::Spawn qw(which spawn popen_rd);
-use PublicInbox::TestCommon;
+use PublicInbox::Spawn qw(spawn popen_rd);
require_mods(qw(Plack::Util Plack::Builder HTTP::Date HTTP::Status));
use Digest::SHA qw(sha1_hex);
use IO::Handle ();
};
SKIP: {
- my $curl = which('curl') or skip('curl(1) missing', 4);
+ my $curl = require_cmd('curl', 1) or skip('curl(1) missing', 4);
my $base = 'http://'.tcp_host_port($sock);
my $url = "$base/sha1";
my ($r, $w);
SKIP: {
skip 'only testing lsof(8) output on Linux', 1 if $^O ne 'linux';
- my $lsof = which('lsof') or skip 'no lsof in PATH', 1;
+ my $lsof = require_cmd('lsof', 1) or skip 'no lsof in PATH', 1;
my $null_in = '';
my $rdr = { 2 => \(my $null_err), 0 => \$null_in };
my @lsof = xqx([$lsof, '-p', $td->{pid}], undef, $rdr);
use Time::HiRes ();
use PublicInbox::TestCommon;
use PublicInbox::Config;
-use PublicInbox::Spawn qw(which);
require_mods(qw(-imapd Mail::IMAPClient));
my $imap_client = 'Mail::IMAPClient';
my $can_compress = $imap_client->can('compress');
# License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
use strict; use v5.10.1; use PublicInbox::TestCommon;
use Socket qw(AF_UNIX SOCK_SEQPACKET MSG_EOR pack_sockaddr_un);
-use PublicInbox::Spawn qw(which);
test_lei({ daemon_only => 1 }, sub {
my $send_cmd = PublicInbox::Spawn->can('send_cmd4') // do {
# License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
use strict; use v5.10.1; use PublicInbox::TestCommon;
use Fcntl qw(SEEK_SET);
-use PublicInbox::Spawn qw(which);
require_git 2.6;
require_mods(qw(json DBD::SQLite Search::Xapian));
use POSIX qw(WTERMSIG WIFSIGNALED SIGPIPE);
my ($url, $k) = @_;
SKIP: {
skip "$k unset", 1 if !$url;
- state $curl = which('curl');
- $curl or skip 'no curl', 1;
- which('torsocks') or skip 'no torsocks', 1 if $url =~ m!\.onion/!;
+ require_cmd 'curl', 1 or skip 'curl missing', 1;
+ if ($url =~ m!\.onion/!) {
+ require_cmd 'torsocks', 1 or skip 'no torsocks', 1;
+ }
my $mid = '20140421094015.GA8962@dcvr.yhbt.net';
my @cmd = ('q', '--only', $url, '-q', "m:$mid");
lei_ok(@cmd, \"query $url");
# Copyright (C) 2021 all contributors <meta@public-inbox.org>
# License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
use strict; use v5.10.1; use PublicInbox::TestCommon;
-use PublicInbox::Spawn qw(which);
require_mods(qw(lei -httpd));
-which('curl') or plan skip_all => "curl required for $0";
+require_cmd('curl');
my ($ro_home, $cfg_path) = setup_public_inboxes;
my ($tmpdir, $for_destroy) = tmpdir;
my $sock = tcp_server;
use strict; use v5.10.1; use PublicInbox::TestCommon;
use PublicInbox::Inbox;
require_mods(qw(-httpd lei));
+require_cmd('curl');
my $sock = tcp_server();
my ($tmpdir, $for_destroy) = tmpdir();
my $http = 'http://'.tcp_host_port($sock);
# License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
use strict; use v5.10.1; use PublicInbox::TestCommon;
require_mods(qw(lei -httpd));
+require_cmd 'curl';
use PublicInbox::MboxReader;
my ($ro_home, $cfg_path) = setup_public_inboxes;
my $sock = tcp_server;
# License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
use strict; use v5.10.1; use PublicInbox::TestCommon;
use File::Path qw(rmtree);
-use PublicInbox::Spawn qw(which);
# this only tests the basic help/config/init/completion bits of lei;
# actual functionality is tested in other t/lei-*.t tests
-my $curl = which('curl');
my $home;
my $home_trash = [];
my $cleanup = sub { rmtree([@$home_trash, @_]) };
lei_ok('sucks', \'yes, but hopefully less every day');
like($lei_out, qr/loaded features/, 'loaded features shown');
SKIP: {
- skip 'no curl', 3 unless which('curl');
+ skip 'no curl', 3 unless require_cmd('curl', 1);
lei(qw(q --only http://127.0.0.1:99999/bogus/ t:m));
is($? >> 8, 3, 'got curl exit for bogus URL');
lei(qw(q --only http://127.0.0.1:99999/bogus/ t:m -o), "$home/junk");
#!perl -w
# Copyright (C) 2015-2021 all contributors <meta@public-inbox.org>
# License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
-use strict;
-use v5.10.1;
-use PublicInbox::TestCommon;
-use PublicInbox::Spawn qw(which);
+use strict; use v5.10.1; use PublicInbox::TestCommon;
require_mods(qw(DBD::SQLite));
use PublicInbox::Eml;
use Socket qw(IPPROTO_TCP TCP_NODELAY);
my $version = $ENV{PI_TEST_VERSION} || 1;
require_git('2.6') if $version == 2;
use_ok 'PublicInbox::Msgmap';
-my $lsof = which('lsof');
+my $lsof = require_cmd('lsof', 1);
my $fast_idle = eval { require Linux::Inotify2; 1 } //
eval { require IO::KQueue; 1 };
#!perl -w
# Copyright (C) 2020-2021 all contributors <meta@public-inbox.org>
# License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
-use strict;
-use Test::More;
+use strict; use v5.10.1; use PublicInbox::TestCommon;
use File::Temp 0.19;
-use PublicInbox::TestCommon;
-use PublicInbox::Spawn qw(which);
use_ok 'PublicInbox::NDC_PP';
SKIP: {
skip 'test is Linux-only', $nr if $^O ne 'linux';
my $dir = $ENV{BTRFS_TESTDIR};
skip 'BTRFS_TESTDIR not defined', $nr unless defined $dir;
- skip 'chattr(1) not installed', $nr unless which('chattr');
- my $lsattr = which('lsattr') or skip 'lsattr(1) not installed', $nr;
+ require_cmd('chattr', 1) or skip 'chattr(1) not installed', $nr;
+ my $lsattr = require_cmd('lsattr', 1) or
+ skip 'lsattr(1) not installed', $nr;
my $tmp = File::Temp->newdir('nodatacow-XXXX', DIR => $dir);
my $dn = $tmp->dirname;
use Cwd qw(abs_path);
require_git(2.6);
use PublicInbox::ContentHash qw(git_sha);
-use PublicInbox::Spawn qw(popen_rd which);
+use PublicInbox::Spawn qw(popen_rd);
require_mods(qw(DBD::SQLite Search::Xapian Plack::Util));
my $git_dir = xqx([qw(git rev-parse --git-dir)], undef, {2 => \(my $null)});
$? == 0 or plan skip_all => "$0 must be run from a git working tree";
my $url = "http://$h:$p";
local $ENV{PLACK_TEST_EXTERNALSERVER_URI} = $url;
Plack::Test::ExternalServer::test_psgi(client => $client);
- skip 'no curl', 1 unless which('curl');
+ require_cmd('curl', 1) or skip 'no curl', 1;
mkdir "$tmpdir/ext" // xbail "mkdir $!";
test_lei({tmpdir => "$tmpdir/ext"}, sub {
# Copyright (C) 2018-2021 all contributors <meta@public-inbox.org>
# License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
use strict;
-use warnings;
-use Test::More;
+use v5.10.1;
use PublicInbox::TestCommon;
use File::Path qw(remove_tree);
use Cwd qw(abs_path);
require_git(2.6);
+require_cmd('curl');
local $ENV{HOME} = abs_path('t');
# Integration tests for HTTP cloning + mirroring
require_mods(qw(Plack::Util Plack::Builder
HTTP::Date HTTP::Status Search::Xapian DBD::SQLite));
-use IO::Socket;
-use POSIX qw(dup2);
use_ok 'PublicInbox::V2Writable';
use PublicInbox::InboxWritable;
use PublicInbox::Eml;
# Copyright (C) 2018-2021 all contributors <meta@public-inbox.org>
# License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
-use strict;
-use warnings;
-use Test::More;
+use strict; use v5.10.1; use PublicInbox::TestCommon;
use PublicInbox::Eml;
use PublicInbox::ContentHash qw(content_digest);
use File::Path qw(remove_tree);
-use PublicInbox::TestCommon;
require_git(2.6);
require_mods(qw(DBD::SQLite Search::Xapian));
use_ok 'PublicInbox::V2Writable';
is($err, '', 'no errors from --xapian-only');
undef $for_destroy;
SKIP: {
- use PublicInbox::Spawn qw(which);
skip 'only testing lsof(8) output on Linux', 1 if $^O ne 'linux';
- my $lsof = which('lsof') or skip 'no lsof in PATH', 1;
+ my $lsof = require_cmd('lsof', 1) or skip 'no lsof in PATH', 1;
my $rdr = { 2 => \(my $null_err) };
my @d = grep(m!/xap[0-9]+/!, xqx([$lsof, '-p', $$], undef, $rdr));
is_deeply(\@d, [], 'no deleted index files') or diag explain(\@d);
#!perl -w
# Copyright (C) 2020-2021 all contributors <meta@public-inbox.org>
# License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
-use strict;
-use v5.10.1;
-use PublicInbox::TestCommon;
+use strict; use v5.10.1; use PublicInbox::TestCommon;
use PublicInbox::Config;
-use PublicInbox::Spawn qw(which spawn);
-which('sqlite3') or plan skip_all => 'sqlite3 binary missing';
+use PublicInbox::Spawn qw(spawn);
+require_cmd('sqlite3');
require_mods(qw(DBD::SQLite HTTP::Request::Common Plack::Test URI::Escape
Plack::Builder IO::Uncompress::Gunzip));
use_ok($_) for qw(Plack::Test HTTP::Request::Common);
# Copyright (C) 2019-2021 all contributors <meta@public-inbox.org>
# License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
# manifest.js.gz generation and grok-pull integration test
-use strict;
-use v5.10.1;
-use Test::More;
-use PublicInbox::Spawn qw(which);
-use PublicInbox::TestCommon;
+use strict; use v5.10.1; use PublicInbox::TestCommon;
use PublicInbox::Import;
use IO::Uncompress::Gunzip qw(gunzip);
require_mods(qw(json URI::Escape Plack::Builder Digest::SHA HTTP::Tiny));
tiny_test($json, $host, $port, 1);
undef $sock;
- my $grok_pull = which('grok-pull') or
+ my $grok_pull = require_cmd('grok-pull', 1) or
skip('grok-pull not available', 12);
my ($grok_version) = (xqx([$grok_pull, "--version"])
=~ /(\d+)\.(?:\d+)(?:\.(\d+))?/);