From 5dbb060037ce3e3a3ba0812baa90c80eeee762af Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Mon, 30 Jan 2023 22:50:07 +0000 Subject: tests: make require_git and require_cmd easier-to-use We'll rely on defined(wantarray) to implicitly skip subtests, and memoize these to reduce syscalls, since tests should be short-lived enough to not be affected by new installations or removals of git/xapian-compact/curl/etc... --- xt/git-http-backend.t | 8 +++----- xt/httpd-async-stream.t | 8 ++++---- xt/imapd-mbsync-oimap.t | 9 +++++---- xt/pop3d-mpop.t | 8 ++++---- 4 files changed, 16 insertions(+), 17 deletions(-) (limited to 'xt') diff --git a/xt/git-http-backend.t b/xt/git-http-backend.t index 1f3ba063..d78fe79f 100644 --- a/xt/git-http-backend.t +++ b/xt/git-http-backend.t @@ -1,14 +1,13 @@ +#!perl -w # Copyright (C) all contributors # License: AGPL-3.0+ # # Ensure buffering behavior in -httpd doesn't cause runaway memory use # or data corruption use strict; -use warnings; -use Test::More; +use v5.10.1; use POSIX qw(setsid); use PublicInbox::TestCommon; -use PublicInbox::Spawn qw(which); my $git_dir = $ENV{GIANT_GIT_DIR}; plan 'skip_all' => 'GIANT_GIT_DIR not defined' unless $git_dir; @@ -77,8 +76,7 @@ SKIP: { # make sure Last-Modified + If-Modified-Since works with curl my $nr = 6; skip 'no description', $nr unless -f "$git_dir/description"; my $mtime = (stat(_))[9]; - my $curl = which('curl'); - skip 'curl(1) not found', $nr unless $curl; + my $curl = require_cmd('curl', 1) or skip 'curl(1) not found', $nr; my $url = "http://$host:$port/description"; my $dst = "$tmpdir/desc"; is(xsys($curl, qw(-RsSf), '-o', $dst, $url), 0, 'curl -R'); diff --git a/xt/httpd-async-stream.t b/xt/httpd-async-stream.t index c7039f3e..0658c691 100644 --- a/xt/httpd-async-stream.t +++ b/xt/httpd-async-stream.t @@ -1,17 +1,17 @@ #!perl -w -# Copyright (C) 2020-2021 all contributors +# Copyright (C) all contributors # License: AGPL-3.0+ # Expensive test to validate compression and TLS. use strict; -use Test::More; +use v5.10.1; use PublicInbox::TestCommon; use PublicInbox::DS qw(now); -use PublicInbox::Spawn qw(which popen_rd); +use PublicInbox::Spawn qw(popen_rd); use Digest::MD5; use POSIX qw(_exit); my $inboxdir = $ENV{GIANT_INBOX_DIR}; plan skip_all => "GIANT_INBOX_DIR not defined for $0" unless $inboxdir; -my $curl = which('curl') or plan skip_all => "curl(1) missing for $0"; +my $curl = require_cmd('curl'); my ($tmpdir, $for_destroy) = tmpdir(); require_mods(qw(DBD::SQLite)); my $JOBS = $ENV{TEST_JOBS} // 4; diff --git a/xt/imapd-mbsync-oimap.t b/xt/imapd-mbsync-oimap.t index 0baf5b4c..b0281105 100644 --- a/xt/imapd-mbsync-oimap.t +++ b/xt/imapd-mbsync-oimap.t @@ -1,12 +1,12 @@ #!perl -w -# Copyright (C) 2020-2021 all contributors +# Copyright (C) all contributors # License: AGPL-3.0+ # ensure mbsync and offlineimap compatibility use strict; use v5.10.1; use File::Path qw(mkpath); use PublicInbox::TestCommon; -use PublicInbox::Spawn qw(which spawn); +use PublicInbox::Spawn qw(spawn); require_mods(qw(-imapd)); my $inboxdir = $ENV{GIANT_INBOX_DIR}; (defined($inboxdir) && -d $inboxdir) or @@ -42,7 +42,8 @@ my %pids; SKIP: { mkpath([map { "$tmpdir/oimapdir/$_" } qw(cur new tmp)]); - my $oimap = which('offlineimap') or skip 'no offlineimap(1)', 1; + my $oimap = require_cmd('offlineimap', 1) or + skip 'no offlineimap(1)', 1; open my $fh, '>', "$tmpdir/.offlineimaprc" or BAIL_OUT "open: $!"; print $fh <', "$tmpdir/.mbsyncrc" or BAIL_OUT "open: $!"; print $fh < "GIANT_INBOX_DIR not defined for $0"; plan skip_all => "bad characters in $inboxdir" if $inboxdir =~ m![^\w\.\-/]!; -my $uuidgen = which('uuidgen') or plan skip_all => 'uuidgen(1) missing'; +my $uuidgen = require_cmd('uuidgen'); +my $mpop = require_cmd('mpop'); require_mods(qw(DBD::SQLite)); require_git('2.6'); # for v2 require_mods(qw(File::FcntlLock)) if $^O !~ /\A(?:linux|freebsd)\z/; @@ -41,8 +42,7 @@ chomp(my $uuid = xqx([$uuidgen])); make_path("$tmpdir/home/.config/mpop", map { "$tmpdir/md/$_" } qw(new cur tmp)); -SKIP: { - my $mpop = which('mpop') or skip('mpop(1) missing', 1); +{ open my $fh, '>', "$tmpdir/home/.config/mpop/config" or xbail "open $!"; chmod 0600, $fh; -- cgit v1.2.3-24-ge0c7