user/dev discussion of public-inbox itself
 help / color / mirror / code / Atom feed
From: Eric Wong <e@yhbt.net>
To: meta@public-inbox.org
Subject: [PATCH 1/3] testcommon: allow OR-ing module dependencies
Date: Sun, 14 Jun 2020 00:25:03 +0000	[thread overview]
Message-ID: <20200614002505.15384-2-e@yhbt.net> (raw)
In-Reply-To: <20200614002505.15384-1-e@yhbt.net>

IMAP requires either the Email::Address::XS or Mail::Address
package (part of perl-MailTools RPM or libmailtools-perl deb);
and Email::Address::XS is not officially packaged for some older
distros, most notably CentOS 7.x.
---
 lib/PublicInbox/TestCommon.pm | 11 ++++++++++-
 t/imap.t                      |  6 +++---
 t/imapd-tls.t                 |  3 ++-
 t/imapd.t                     |  3 ++-
 xt/imapd-mbsync-oimap.t       |  1 +
 xt/imapd-validate.t           |  2 +-
 xt/mem-imapd-tls.t            |  2 +-
 7 files changed, 20 insertions(+), 8 deletions(-)

diff --git a/lib/PublicInbox/TestCommon.pm b/lib/PublicInbox/TestCommon.pm
index 5e7dc8b0..a97125e5 100644
--- a/lib/PublicInbox/TestCommon.pm
+++ b/lib/PublicInbox/TestCommon.pm
@@ -72,7 +72,7 @@ sub require_mods {
 	my @mods = @_;
 	my $maybe = pop @mods if $mods[-1] =~ /\A[0-9]+\z/;
 	my @need;
-	for my $mod (@mods) {
+	while (my $mod = shift(@mods)) {
 		if ($mod eq 'Search::Xapian') {
 			if (eval { require PublicInbox::Search } &&
 				PublicInbox::Search::load_xapian()) {
@@ -83,6 +83,15 @@ sub require_mods {
 				PublicInbox::SearchIdx::load_xapian_writable()){
 					next;
 			}
+		} elsif (index($mod, '||') >= 0) { # "Foo||Bar"
+			my $ok;
+			for my $m (split(/\Q||\E/, $mod)) {
+				eval "require $m";
+				next if $@;
+				$ok = $m;
+				last;
+			}
+			next if $ok;
 		} else {
 			eval "require $mod";
 		}
diff --git a/t/imap.t b/t/imap.t
index 0700f578..83adf553 100644
--- a/t/imap.t
+++ b/t/imap.t
@@ -4,10 +4,10 @@
 # unit tests (no network) for IMAP, see t/imapd.t for end-to-end tests
 use strict;
 use Test::More;
-use PublicInbox::IMAP;
-use PublicInbox::IMAPD;
 use PublicInbox::TestCommon;
-require_mods(qw(DBD::SQLite));
+require_mods(qw(DBD::SQLite Email::Address::XS||Mail::Address));
+require_ok 'PublicInbox::IMAP';
+require_ok 'PublicInbox::IMAPD';
 require_git 2.6;
 use POSIX qw(strftime);
 
diff --git a/t/imapd-tls.t b/t/imapd-tls.t
index 5352d100..f81959a5 100644
--- a/t/imapd-tls.t
+++ b/t/imapd-tls.t
@@ -6,7 +6,8 @@ use Test::More;
 use Socket qw(IPPROTO_TCP SOL_SOCKET);
 use PublicInbox::TestCommon;
 # IO::Poll is part of the standard library, but distros may split it off...
-require_mods(qw(DBD::SQLite IO::Socket::SSL Mail::IMAPClient IO::Poll));
+require_mods(qw(DBD::SQLite IO::Socket::SSL Mail::IMAPClient IO::Poll
+	Email::Address::XS||Mail::Address));
 my $imap_client = 'Mail::IMAPClient';
 $imap_client->can('starttls') or
 	plan skip_all => 'Mail::IMAPClient does not support TLS';
diff --git a/t/imapd.t b/t/imapd.t
index f5ca8b7e..0f48e905 100644
--- a/t/imapd.t
+++ b/t/imapd.t
@@ -8,7 +8,8 @@ use Time::HiRes ();
 use PublicInbox::TestCommon;
 use PublicInbox::Config;
 use PublicInbox::Spawn qw(which);
-require_mods(qw(DBD::SQLite Mail::IMAPClient Mail::IMAPClient::BodyStructure));
+require_mods(qw(DBD::SQLite Mail::IMAPClient Mail::IMAPClient::BodyStructure
+	Email::Address::XS||Mail::Address));
 my $imap_client = 'Mail::IMAPClient';
 my $can_compress = $imap_client->can('compress');
 if ($can_compress) { # hope this gets fixed upstream, soon
diff --git a/xt/imapd-mbsync-oimap.t b/xt/imapd-mbsync-oimap.t
index c097a026..edf111fd 100644
--- a/xt/imapd-mbsync-oimap.t
+++ b/xt/imapd-mbsync-oimap.t
@@ -7,6 +7,7 @@ use Test::More;
 use File::Path qw(mkpath);
 use PublicInbox::TestCommon;
 use PublicInbox::Spawn qw(which spawn);
+require_mods(qw(DBD::SQLite Email::Address::XS||Mail::Address));
 my $inboxdir = $ENV{GIANT_INBOX_DIR};
 (defined($inboxdir) && -d $inboxdir) or
 	plan skip_all => "GIANT_INBOX_DIR not defined for $0";
diff --git a/xt/imapd-validate.t b/xt/imapd-validate.t
index 9a56c2d0..3e445156 100644
--- a/xt/imapd-validate.t
+++ b/xt/imapd-validate.t
@@ -15,7 +15,7 @@ my $BATCH = $ENV{TEST_BATCH} // 100;
 my $REPEAT = $ENV{TEST_REPEAT} // 1;
 diag "TEST_BATCH=$BATCH TEST_REPEAT=$REPEAT";
 
-require_mods(qw(Mail::IMAPClient));
+require_mods(qw(Mail::IMAPClient Email::Address::XS||Mail::Address));
 my $imap_client = 'Mail::IMAPClient';
 my $can_compress = $imap_client->can('compress');
 if ($can_compress) { # hope this gets fixed upstream, soon
diff --git a/xt/mem-imapd-tls.t b/xt/mem-imapd-tls.t
index accf7564..648a0ad3 100644
--- a/xt/mem-imapd-tls.t
+++ b/xt/mem-imapd-tls.t
@@ -9,7 +9,7 @@ use Socket qw(SOCK_STREAM IPPROTO_TCP SOL_SOCKET);
 use PublicInbox::TestCommon;
 use PublicInbox::Syscall qw(:epoll);
 use PublicInbox::DS;
-require_mods(qw(DBD::SQLite));
+require_mods(qw(DBD::SQLite Email::Address::XS||Mail::Address));
 my $inboxdir = $ENV{GIANT_INBOX_DIR};
 my $TEST_TLS;
 SKIP: {

  reply	other threads:[~2020-06-14  0:25 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-06-14  0:25 [PATCH 0/3] IMAP fixes for older systems Eric Wong
2020-06-14  0:25 ` Eric Wong [this message]
2020-06-14  0:25 ` [PATCH 2/3] inboxidle: support Linux::Inotify2 1.x Eric Wong
2020-06-14  0:25 ` [PATCH 3/3] t/imapd*.t: support older Mail::IMAPClient Eric Wong

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://public-inbox.org/README

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200614002505.15384-2-e@yhbt.net \
    --to=e@yhbt.net \
    --cc=meta@public-inbox.org \
    --subject='Re: [PATCH 1/3] testcommon: allow OR-ing module dependencies' \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

Code repositories for project(s) associated with this inbox:

	https://80x24.org/public-inbox.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).