]> Sergey Matveev's repositories - public-inbox.git/commitdiff
tests: more common JSON module loading
authorEric Wong <e@80x24.org>
Tue, 15 Dec 2020 08:21:24 +0000 (08:21 +0000)
committerEric Wong <e@80x24.org>
Sat, 19 Dec 2020 09:32:08 +0000 (09:32 +0000)
We'll probably be using JSON more in the future, so make
it easier to require in tests

lib/PublicInbox/ManifestJsGz.pm
lib/PublicInbox/TestCommon.pm
t/extsearch.t
t/lei.t
t/www_listing.t

index 6d5b57eebc2e5c31db1496e982b41097f8e415fa..33df020a853ee0f161741b8c8ece4093a30636c7 100644 (file)
@@ -11,7 +11,7 @@ use PublicInbox::Config;
 use IO::Compress::Gzip qw(gzip);
 use HTTP::Date qw(time2str);
 
-our $json = PublicInbox::Config::json();
+my $json = PublicInbox::Config::json();
 
 # called by WwwListing
 sub url_regexp {
index 299b9c6a830833966df288687270d27ae95e1b49..2116575b2946bf941b6e351e56bd2d63f07a0322 100644 (file)
@@ -75,6 +75,10 @@ sub require_mods {
        my $maybe = pop @mods if $mods[-1] =~ /\A[0-9]+\z/;
        my @need;
        while (my $mod = shift(@mods)) {
+               if ($mod eq 'json') {
+                       $mod = 'Cpanel::JSON::XS||JSON::MaybeXS||'.
+                               'JSON||JSON::PP'
+               }
                if ($mod eq 'Search::Xapian') {
                        if (eval { require PublicInbox::Search } &&
                                PublicInbox::Search::load_xapian()) {
index fb31b0abf18e6b155f372459fab93381a9aeec1d..ffbc10e2f3522b585dcab4f0d78efcae4054f423 100644 (file)
@@ -8,9 +8,8 @@ use PublicInbox::Config;
 use PublicInbox::Search;
 use PublicInbox::InboxWritable;
 use Fcntl qw(:seek);
-my $json = PublicInbox::Config::json() or plan skip_all => 'JSON missing';
 require_git(2.6);
-require_mods(qw(DBD::SQLite Search::Xapian));
+require_mods(qw(json DBD::SQLite Search::Xapian));
 use_ok 'PublicInbox::ExtSearch';
 use_ok 'PublicInbox::ExtSearchIdx';
 use_ok 'PublicInbox::OverIdx';
diff --git a/t/lei.t b/t/lei.t
index feee92700502730948bb3bcd56708a9dc1c71a48..02f213225f4aff822cfbe967b657385c62727fc9 100644 (file)
--- a/t/lei.t
+++ b/t/lei.t
@@ -6,8 +6,7 @@ use v5.10.1;
 use Test::More;
 use PublicInbox::TestCommon;
 use PublicInbox::Config;
-my $json = PublicInbox::Config::json() or plan skip_all => 'JSON missing';
-require_mods(qw(DBD::SQLite Search::Xapian));
+require_mods(qw(json DBD::SQLite Search::Xapian));
 my ($home, $for_destroy) = tmpdir();
 my $opt = { 1 => \(my $out = ''), 2 => \(my $err = '') };
 
index 636133715eb1f4cbe5c93ac56197c9d29430727e..94c1e5bbbcb0f37ac26aae03b42a802902f712dc 100644 (file)
@@ -7,14 +7,12 @@ use Test::More;
 use PublicInbox::Spawn qw(which);
 use PublicInbox::TestCommon;
 use PublicInbox::Import;
-require_mods(qw(URI::Escape Plack::Builder Digest::SHA
+require_mods(qw(json URI::Escape Plack::Builder Digest::SHA
                IO::Compress::Gzip IO::Uncompress::Gunzip HTTP::Tiny));
 require PublicInbox::WwwListing;
 require PublicInbox::ManifestJsGz;
-my $json = do {
-       no warnings 'once';
-       $PublicInbox::ManifestJsGz::json;
-} or plan skip_all => "JSON module missing";
+use PublicInbox::Config;
+my $json = PublicInbox::Config::json();
 
 use_ok 'PublicInbox::Git';