user/dev discussion of public-inbox itself
 help / color / mirror / code / Atom feed
Search results ordered by [date|relevance]  view[summary|nested|Atom feed]
thread overview below | download mbox.gz: |
* [PATCH 09/17] t/tests: split out setup_public_inboxes sub
  2021-02-06 12:18  7% [PATCH 00/17] lei: more random updates Eric Wong
@ 2021-02-06 12:18  4% ` Eric Wong
  0 siblings, 0 replies; 2+ results
From: Eric Wong @ 2021-02-06 12:18 UTC (permalink / raw)
  To: meta

We'll probably use this in many more existing places
and likely change non-lei tests to use it.
---
 MANIFEST                      |  3 +++
 Makefile.PL                   |  3 +++
 lib/PublicInbox/TestCommon.pm | 50 +++++++++++++++++++++++++++++++++--
 t/home1/.gitignore            |  5 ++++
 t/home1/Makefile              |  7 +++++
 t/home1/README                |  8 ++++++
 t/lei-externals.t             | 35 ++----------------------
 7 files changed, 76 insertions(+), 35 deletions(-)
 create mode 100644 t/home1/.gitignore
 create mode 100644 t/home1/Makefile
 create mode 100644 t/home1/README

diff --git a/MANIFEST b/MANIFEST
index c7fe4fb5..000834cc 100644
--- a/MANIFEST
+++ b/MANIFEST
@@ -328,6 +328,9 @@ t/git.fast-import-data
 t/git.t
 t/gzip_filter.t
 t/hl_mod.t
+t/home1/.gitignore
+t/home1/Makefile
+t/home1/README
 t/html_index.t
 t/httpd-corner.psgi
 t/httpd-corner.t
diff --git a/Makefile.PL b/Makefile.PL
index b9e0a8cd..68545573 100644
--- a/Makefile.PL
+++ b/Makefile.PL
@@ -172,6 +172,9 @@ WriteMakefile(
 		# ExtUtils::MakeMaker # this file won't run w/o it...
 	},
 	MAN3PODS => \%man3,
+	clean => {
+		FILES => 't/home1/setup* t/home1/t* t/home1/.public-inbox'
+	},
 );
 
 sub MY::postamble {
diff --git a/lib/PublicInbox/TestCommon.pm b/lib/PublicInbox/TestCommon.pm
index 2b78731b..bb2cd7e6 100644
--- a/lib/PublicInbox/TestCommon.pm
+++ b/lib/PublicInbox/TestCommon.pm
@@ -13,7 +13,7 @@ our @EXPORT;
 BEGIN {
 	@EXPORT = qw(tmpdir tcp_server tcp_connect require_git require_mods
 		run_script start_script key2sub xsys xsys_e xqx eml_load tick
-		have_xapian_compact json_utf8
+		have_xapian_compact json_utf8 setup_public_inboxes
 		test_lei $lei $lei_out $lei_err $lei_opt);
 	require Test::More;
 	my @methods = grep(!/\W/, @Test::More::EXPORT);
@@ -498,7 +498,53 @@ EOM
 		ok(!kill(0, $daemon_pid), "$t daemon stopped after oneshot");
 	}
 }; # SKIP if missing git 2.6+ || Xapian || SQLite || json
-}
+} # /test_lei
+
+# returns the pathname to a ~/.public-inbox/config in scalar context,
+# ($test_home, $pi_config_pathname) in list context
+sub setup_public_inboxes () {
+	my $test_home = "t/home1";
+	my $pi_config = "$test_home/.public-inbox/config";
+	my $stamp = "$test_home/setup-stamp";
+	my @ret = ($test_home, $pi_config);
+	return @ret if -f $stamp;
+
+	require PublicInbox::Lock;
+	my $lk = bless { lock_path => "$test_home/setup.lock" },
+			'PublicInbox::Lock';
+	my $end = $lk->lock_for_scope;
+	return @ret if -f $stamp;
+
+	require PublicInbox::InboxWritable;
+	local $ENV{PI_CONFIG} = $pi_config;
+	for my $V (1, 2) {
+		run_script([qw(-init), "-V$V", "t$V",
+				'--newsgroup', "t.$V",
+				"$test_home/t$V", "http://example.com/t$V",
+				"t$V\@example.com" ]) or BAIL_OUT "init v$V";
+	}
+	my $cfg = PublicInbox::Config->new;
+	my $seen = 0;
+	$cfg->each_inbox(sub {
+		my ($ibx) = @_;
+		my $im = PublicInbox::InboxWritable->new($ibx)->importer(0);
+		my $V = $ibx->version;
+		my @eml = (glob('t/*.eml'), 't/data/0001.patch');
+		for (@eml) {
+			next if $_ eq 't/psgi_v2-old.eml'; # dup mid
+			$im->add(eml_load($_)) or BAIL_OUT "v$V add $_";
+			$seen++;
+		}
+		$im->done;
+		if ($V == 1) {
+			run_script(['-index', $ibx->{inboxdir}]) or
+				BAIL_OUT 'index v1';
+		}
+	});
+	$seen or BAIL_OUT 'no imports';
+	open my $fh, '>', $stamp or BAIL_OUT "open $stamp: $!";
+	@ret;
+};
 
 package PublicInboxTestProcess;
 use strict;
diff --git a/t/home1/.gitignore b/t/home1/.gitignore
new file mode 100644
index 00000000..b97d81e6
--- /dev/null
+++ b/t/home1/.gitignore
@@ -0,0 +1,5 @@
+/.public-inbox
+/t1
+/t2
+/setup.lock
+/setup-stamp
diff --git a/t/home1/Makefile b/t/home1/Makefile
new file mode 100644
index 00000000..9d4895dc
--- /dev/null
+++ b/t/home1/Makefile
@@ -0,0 +1,7 @@
+all ::
+
+help ::
+	@cat README
+
+clean ::
+	$(RM) -rf t1 t2 .public-inbox setup-stamp setup-lock
diff --git a/t/home1/README b/t/home1/README
new file mode 100644
index 00000000..1ba87891
--- /dev/null
+++ b/t/home1/README
@@ -0,0 +1,8 @@
+This directory is for read-only test inboxes and will be shared
+between various tests.
+
+See setup_publicinboxes() in lib/PublicInbox/TestCommon.pm.
+
+It is versioned (currently "1" in "home1") and will be renamed
+"home2" and so forth if the data created by setup_publicinboxes()
+changes.
diff --git a/t/lei-externals.t b/t/lei-externals.t
index 739f779d..f2cb09b4 100644
--- a/t/lei-externals.t
+++ b/t/lei-externals.t
@@ -9,37 +9,6 @@ my @onions = qw(http://hjrcffqmbrq6wope.onion/meta/
 	http://czquwvybam4bgbro.onion/meta/
 	http://ou63pmih66umazou.onion/meta/);
 
-# TODO share this across tests, it takes ~300ms
-my $setup_publicinboxes = sub {
-	my ($home) = @_;
-	use PublicInbox::InboxWritable;
-	for my $V (1, 2) {
-		run_script([qw(-init), "-V$V", "t$V",
-				'--newsgroup', "t.$V",
-				"$home/t$V", "http://example.com/t$V",
-				"t$V\@example.com" ]) or BAIL_OUT "init v$V";
-	}
-	my $cfg = PublicInbox::Config->new;
-	my $seen = 0;
-	$cfg->each_inbox(sub {
-		my ($ibx) = @_;
-		my $im = PublicInbox::InboxWritable->new($ibx)->importer(0);
-		my $V = $ibx->version;
-		my @eml = (glob('t/*.eml'), 't/data/0001.patch');
-		for (@eml) {
-			next if $_ eq 't/psgi_v2-old.eml'; # dup mid
-			$im->add(eml_load($_)) or BAIL_OUT "v$V add $_";
-			$seen++;
-		}
-		$im->done;
-		if ($V == 1) {
-			run_script(['-index', $ibx->{inboxdir}]) or
-				BAIL_OUT 'index v1';
-		}
-	});
-	$seen || BAIL_OUT 'no imports';
-};
-
 my $test_external_remote = sub {
 	my ($url, $k) = @_;
 SKIP: {
@@ -59,9 +28,9 @@ SKIP: {
 } # /SKIP
 }; # /sub
 
+my ($ro_home, $cfg_path) = setup_public_inboxes;
 test_lei(sub {
 	my $home = $ENV{HOME};
-	$setup_publicinboxes->($home);
 	my $config_file = "$home/.config/lei/config";
 	my $store_dir = "$home/.local/share/lei";
 	ok($lei->('ls-external'), 'ls-external works');
@@ -73,7 +42,7 @@ test_lei(sub {
 		"fails on non-existent dir");
 	ok($lei->('ls-external'), 'ls-external works after add failure');
 	is($lei_out.$lei_err, '', 'ls-external still has no output');
-	my $cfg = PublicInbox::Config->new;
+	my $cfg = PublicInbox::Config->new($cfg_path);
 	$cfg->each_inbox(sub {
 		my ($ibx) = @_;
 		ok($lei->(qw(add-external -q), $ibx->{inboxdir}),

^ permalink raw reply related	[relevance 4%]

* [PATCH 00/17] lei: more random updates
@ 2021-02-06 12:18  7% Eric Wong
  2021-02-06 12:18  4% ` [PATCH 09/17] t/tests: split out setup_public_inboxes sub Eric Wong
  0 siblings, 1 reply; 2+ results
From: Eric Wong @ 2021-02-06 12:18 UTC (permalink / raw)
  To: meta

"lei add-external --mirror $URL $DESTDIR" works.
Tests are more split out and hopefully easier-to-manage
going forward (they are slowing down, though, but
more use of common setup_public_inboxes() may help).

The curl(1) short options are gone to avoid conflicts.
--help looks a bit nicer, now.

Eric Wong (17):
  lei_overview: drop unnecessary autoflush call
  lei: favor "keywords" over "flags", test --no-kw
  lei: fix completion of --no-kw / --no-keywords
  lei: abort lei_import worker on client abort
  init: lowercase -j for --jobs
  lei_query: trim curl options
  tests: add test_lei wrapper, split out t/lei-import.t
  t/lei-externals: split out into separate test
  t/tests: split out setup_public_inboxes sub
  tests: split out lei-daemon.t from lei.t
  treewide: replace confess with croak
  script/lei: avoid waitpid(-1, ...) to keep tests fast
  lei: add-external --mirror support
  lei help: split out into separate file
  lei add-external: reject index and remote opts w/o mirror
  lei_curl: replace -K/--config with --curl-config
  lei: remove short switch support for curl(1) options

 MANIFEST                               |  11 +-
 Makefile.PL                            |   3 +
 contrib/completion/lei-completion.bash |   2 +-
 lib/PublicInbox/Admin.pm               |   7 +-
 lib/PublicInbox/DS.pm                  |  10 +-
 lib/PublicInbox/Eml.pm                 |   4 +-
 lib/PublicInbox/IPC.pm                 |   2 +-
 lib/PublicInbox/LEI.pm                 | 200 +++++-------
 lib/PublicInbox/LeiCurl.pm             |  72 +++++
 lib/PublicInbox/LeiExternal.pm         |  46 ++-
 lib/PublicInbox/LeiHelp.pm             | 100 ++++++
 lib/PublicInbox/LeiImport.pm           |   4 +-
 lib/PublicInbox/LeiMirror.pm           | 288 +++++++++++++++++
 lib/PublicInbox/LeiOverview.pm         |   1 -
 lib/PublicInbox/LeiQuery.pm            |  24 +-
 lib/PublicInbox/LeiXSearch.pm          |  33 +-
 lib/PublicInbox/OverIdx.pm             |   2 +-
 lib/PublicInbox/TestCommon.pm          | 142 ++++++++-
 script/lei                             |  28 +-
 script/public-inbox-init               |   2 +-
 t/home1/.gitignore                     |   5 +
 t/home1/Makefile                       |   7 +
 t/home1/README                         |   8 +
 t/lei-daemon.t                         |  63 ++++
 t/lei-externals.t                      | 200 ++++++++++++
 t/lei-import.t                         |  39 +++
 t/lei-mirror.t                         |  30 ++
 t/lei-oneshot.t                        |   8 -
 t/lei.t                                | 424 +++----------------------
 29 files changed, 1180 insertions(+), 585 deletions(-)
 create mode 100644 lib/PublicInbox/LeiCurl.pm
 create mode 100644 lib/PublicInbox/LeiHelp.pm
 create mode 100644 lib/PublicInbox/LeiMirror.pm
 create mode 100644 t/home1/.gitignore
 create mode 100644 t/home1/Makefile
 create mode 100644 t/home1/README
 create mode 100644 t/lei-daemon.t
 create mode 100644 t/lei-externals.t
 create mode 100644 t/lei-import.t
 create mode 100644 t/lei-mirror.t
 delete mode 100644 t/lei-oneshot.t

^ permalink raw reply	[relevance 7%]

Results 1-2 of 2 | reverse | options above
-- pct% links below jump to the message on this page, permalinks otherwise --
2021-02-06 12:18  7% [PATCH 00/17] lei: more random updates Eric Wong
2021-02-06 12:18  4% ` [PATCH 09/17] t/tests: split out setup_public_inboxes sub Eric Wong

Code repositories for project(s) associated with this public 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).