From: Eric Wong <e@80x24.org>
To: meta@public-inbox.org
Subject: [PATCH 1/3] t/lei*: check error messages on failures
Date: Fri, 23 Jul 2021 10:56:10 +0000 [thread overview]
Message-ID: <20210723105612.3883-2-e@80x24.org> (raw)
In-Reply-To: <20210723105612.3883-1-e@80x24.org>
I just hit an unreproducible failure in t/lei-p2q.t and
lacked $lei_err information to diagnose it. Hopefully
this helps track down odd failures in the future.
---
t/lei-externals.t | 4 ++++
t/lei-import-http.t | 2 ++
t/lei-import-imap.t | 1 +
t/lei-mirror.t | 7 ++++++-
t/lei-p2q.t | 1 +
t/lei-q-kw.t | 1 +
t/lei-q-remote-import.t | 1 +
t/lei-q-save.t | 4 ++++
t/lei-tag.t | 8 +++++++-
t/solver_git.t | 7 +++++++
10 files changed, 34 insertions(+), 2 deletions(-)
diff --git a/t/lei-externals.t b/t/lei-externals.t
index f148fa3c..5e3c67bc 100644
--- a/t/lei-externals.t
+++ b/t/lei-externals.t
@@ -211,6 +211,8 @@ test_lei(sub {
like($lei_out, qr/use boolean prefix/, '--stdin on pipe');
}
ok(!lei(qw(q -q --stdin s:use)), "--stdin and argv don't mix");
+ like($lei_err, qr/no query allowed.*--stdin/,
+ '--stdin conflict error message');
for my $fmt (qw(ldjson ndjson jsonl)) {
lei_ok('q', '-f', $fmt, 's:use boolean prefix');
@@ -250,6 +252,8 @@ test_lei(sub {
}
ok(!lei('q', '-o', "$home/mbox", 's:nope'),
'fails if mbox format unspecified');
+ like($lei_err, qr/unable to determine mbox/, 'mbox-related message');
+
ok(!lei(qw(q --no-local s:see)), '--no-local');
is($? >> 8, 1, 'proper exit code');
like($lei_err, qr/no local or remote.+? to search/, 'no inbox');
diff --git a/t/lei-import-http.t b/t/lei-import-http.t
index 2104c778..e9eec1f7 100644
--- a/t/lei-import-http.t
+++ b/t/lei-import-http.t
@@ -17,6 +17,7 @@ test_lei({ tmpdir => $tmpdir }, sub {
my $url = "http://$host_port/t2";
for my $p (qw(bogus@x/t.mbox.gz bogus@x/raw ?q=noresultever)) {
ok(!lei('import', "$url/$p"), "/$p fails properly");
+ like($lei_err, qr/curl.*404/, 'got curl 404');
}
for my $p (qw(/ /T/ /t/ /t.atom)) {
ok(!lei('import', "$url/m\@example$p"), "/$p fails");
@@ -42,5 +43,6 @@ test_lei({ tmpdir => $tmpdir }, sub {
ok(!lei(qw(import --mail-sync), "$url/x\@example.com/raw"),
'--mail-sync fails on HTTP');
+ like($lei_err, qr/--mail-sync/, 'error message notes --mail-sync');
});
done_testing;
diff --git a/t/lei-import-imap.t b/t/lei-import-imap.t
index 12f6fad0..315567b3 100644
--- a/t/lei-import-imap.t
+++ b/t/lei-import-imap.t
@@ -43,6 +43,7 @@ test_lei({ tmpdir => $tmpdir }, sub {
$url = $u;
$u =~ s/;UIDVALIDITY=(\d+)\s*/;UIDVALIDITY=9$1/s;
ok(!lei('import', $u), 'UIDVALIDITY mismatch in URL rejected');
+ like($lei_err, qr/UIDVALIDITY mismatch/, 'mismatch noted');
lei_ok('inspect', $url);
my $inspect = json_utf8->decode($lei_out);
diff --git a/t/lei-mirror.t b/t/lei-mirror.t
index dfd35e1a..80bc6ed5 100644
--- a/t/lei-mirror.t
+++ b/t/lei-mirror.t
@@ -27,6 +27,7 @@ test_lei({ tmpdir => $tmpdir }, sub {
ok(!lei('add-external', $t2, '--mirror', "$http/t2/"),
'--mirror fails if reused') or diag "$lei_err.$lei_out = $?";
+ like($lei_err, qr/\Q$t2\E' already exists/, 'destination in error');
ok(!lei('add-external', "$home/t2\nnewline", '--mirror', "$http/t2/"),
'--mirror fails on newline');
@@ -37,13 +38,16 @@ test_lei({ tmpdir => $tmpdir }, sub {
unlike($lei_out, qr!\Qnewline\E!, 'newline entry not added');
ok(!lei('add-external', "$t2-fail", '-Lmedium'), '--mirror v2');
+ like($lei_err, qr/not a directory/, 'non-directory noted');
ok(!-d "$t2-fail", 'destination not created on failure');
lei_ok('ls-external');
unlike($lei_out, qr!\Q$t2-fail\E!, 'not added to ls-external');
my %phail = (
HTTPS => 'https://public-inbox.org/' . 'phail',
- ONION => 'http://7fh6tueqddpjyxjmgtdiueylzoqt6pt7hec3pukyptlmohoowvhde4yd.onion/' . 'phail,'
+ ONION =>
+'http://7fh6tueqddpjyxjmgtdiueylzoqt6pt7hec3pukyptlmohoowvhde4yd.onion/' .
+'phail,'
);
for my $t (qw(HTTPS ONION)) {
SKIP: {
@@ -56,6 +60,7 @@ test_lei({ tmpdir => $tmpdir }, sub {
is($? >> 8, 22, 'curl 404');
ok(!-d $dir, 'directory not created');
unlike($lei_err, qr/# mirrored/, 'no success message');
+ like($lei_err, qr/curl.*404/, "curl 404 shown for $k");
} # SKIP
} # for
});
diff --git a/t/lei-p2q.t b/t/lei-p2q.t
index 58506f94..495d81de 100644
--- a/t/lei-p2q.t
+++ b/t/lei-p2q.t
@@ -8,6 +8,7 @@ require_mods(qw(json DBD::SQLite Search::Xapian));
test_lei(sub {
ok(!lei(qw(p2q this-better-cause-format-patch-to-fail)),
'p2q fails on bogus arg');
+ like($lei_err, qr/format-patch.*failed/, 'notes format-patch failure');
lei_ok(qw(p2q -w dfpost t/data/0001.patch));
is($lei_out, "dfpost:6e006fd73b1d\n", 'pathname') or diag $lei_err;
open my $fh, '+<', 't/data/0001.patch' or xbail "open: $!";
diff --git a/t/lei-q-kw.t b/t/lei-q-kw.t
index 528751b4..2e6be1f0 100644
--- a/t/lei-q-kw.t
+++ b/t/lei-q-kw.t
@@ -48,6 +48,7 @@ SKIP: {
my $cat = popen_rd(['cat', $o]);
ok(!lei(qw(q --import-before bogus -o), "mboxrd:$o"),
'--import-before fails on non-seekable output');
+ like($lei_err, qr/not seekable/, 'unseekable noted in error');
is(do { local $/; <$cat> }, '', 'no output on FIFO');
close $cat;
$cat = popen_rd(['cat', $o]);
diff --git a/t/lei-q-remote-import.t b/t/lei-q-remote-import.t
index 7db684d9..aaf56e27 100644
--- a/t/lei-q-remote-import.t
+++ b/t/lei-q-remote-import.t
@@ -54,6 +54,7 @@ test_lei({ tmpdir => $tmpdir }, sub {
ok(-f $o && -s _, '--lock=none respected') or diag $lei_err;
unlink $o or xbail("unlink $o $! cwd=".Cwd::getcwd());
ok(!lei(@cmd, '--lock=dotlock,timeout=0.000001'), 'dotlock fails');
+ like($lei_err, qr/dotlock timeout/, 'timeout noted');
ok(-f $o && !-s _, 'nothing output on lock failure');
unlink "$o.lock" or BAIL_OUT $!;
lei_ok(@cmd, '--lock=dotlock,timeout=0.000001',
diff --git a/t/lei-q-save.t b/t/lei-q-save.t
index 6c592088..b1ca4e92 100644
--- a/t/lei-q-save.t
+++ b/t/lei-q-save.t
@@ -69,6 +69,7 @@ test_lei(sub {
ok(-s "$home/mbcl2" > $size, 'size increased after up');
ok(!lei(qw(up -q), $home), 'up fails w/o --save');
+ like($lei_err, qr/--save was not used/, 'error noted --save');
lei_ok qw(ls-search); my @d = split(/\n/, $lei_out);
lei_ok qw(ls-search -z); my @z = split(/\0/, $lei_out);
@@ -115,6 +116,8 @@ test_lei(sub {
lei_ok(qw(up --all=local));
ok(!lei(qw(forget-search), "$home/bogus"), 'bogus forget');
+ like($lei_err, qr/--save was not used/, 'error noted --save');
+
lei_ok qw(_complete lei forget-search);
like($lei_out, qr/mbrd-aug/, 'forget-search completion');
lei_ok(qw(forget-search -v), "$home/mbrd-aug");
@@ -124,6 +127,7 @@ test_lei(sub {
unlike($lei_out, qr/mbrd-aug/,
'forget-search completion cleared after forget');
ok(!lei('up', "$home/mbrd-aug"), 'lei up fails after forget');
+ like($lei_err, qr/--save was not used/, 'error noted --save');
# dedupe=mid
my $o = "$home/dd-mid";
diff --git a/t/lei-tag.t b/t/lei-tag.t
index 5cb6d9ce..44e4659f 100644
--- a/t/lei-tag.t
+++ b/t/lei-tag.t
@@ -32,8 +32,14 @@ test_lei(sub {
lei_ok(qw(ls-label)); is($lei_out, "urgent\n", 'label found');
ok(!lei(qw(tag -F eml t/utf8.eml +kw:seeen)), 'bad kw rejected');
like($lei_err, qr/`seeen' is not one of/, 'got helpful error');
+
ok(!lei(qw(tag -F eml t/utf8.eml +k:seen)), 'bad prefix rejected');
+ like($lei_err, qr/Unable to handle.*\Q+k:seen\E/, 'bad prefix noted');
+
ok(!lei(qw(tag -F eml t/utf8.eml)), 'no keywords');
+ like($lei_err, qr/no keywords or labels specified/,
+ 'lack of kw/L noted');
+
my $mb = "$ENV{HOME}/mb";
my $md = "$ENV{HOME}/md";
lei_ok(qw(q m:testmessage@example.com -o), "mboxrd:$mb");
@@ -78,7 +84,7 @@ test_lei(sub {
lei_ok(qw(ls-label));
is($lei_out, "nope\nqp\nurgent\n", 'ls-label shows qp');
- lei_ok qw(tag -F eml t/utf8.eml +L:INBOX +L:x); diag $lei_err;
+ lei_ok qw(tag -F eml t/utf8.eml +L:INBOX +L:x);
lei_ok qw(q m:testmessage@example.com);
$check_kw->([qw(answered seen)], L => [qw(INBOX nope urgent x)]);
lei_ok(qw(ls-label));
diff --git a/t/solver_git.t b/t/solver_git.t
index fe1aff0b..f5cc592c 100644
--- a/t/solver_git.t
+++ b/t/solver_git.t
@@ -43,6 +43,7 @@ test_lei({tmpdir => "$tmpdir/blob"}, sub {
is($lei_out, $patch2->as_string, 'blob matches');
ok(!lei('blob', '--mail', '69df7d5', '-I', $ibx->{inboxdir}),
"--mail won't run solver");
+ like($lei_err, qr/\b69df7d5\b/, 'OID in error by git(1)');
lei_ok('blob', '69df7d5', '-I', $ibx->{inboxdir});
is(git_sha(1, \$lei_out)->hexdigest, $expect, 'blob contents output');
@@ -51,6 +52,8 @@ test_lei({tmpdir => "$tmpdir/blob"}, sub {
is($lei_out, $prev, '--no-mail works');
ok(!lei(qw(blob -I), $ibx->{inboxdir}, $non_existent),
'non-existent blob fails');
+ my $abbrev = substr($non_existent, 0, 7);
+ like($lei_err, qr/could not find $abbrev/, 'failed abbreviation noted');
SKIP: {
skip '/.git exists', 1 if -e '/.git';
lei_ok(qw(-C / blob 69df7d5 -I), $ibx->{inboxdir},
@@ -59,9 +62,13 @@ test_lei({tmpdir => "$tmpdir/blob"}, sub {
ok(!lei(qw(-C / blob --no-cwd 69df7d5 -I), $ibx->{inboxdir}),
'--no-cwd works');
+ like($lei_err, qr/no --git-dir to try/,
+ 'lack of --git-dir noted');
ok(!lei(qw(-C / blob -I), $ibx->{inboxdir}, $non_existent),
'non-existent blob fails');
+ like($lei_err, qr/no --git-dir to try/,
+ 'lack of --git-dir noted');
}
# fallbacks
next prev parent reply other threads:[~2021-07-23 10:56 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-07-23 10:56 [PATCH 0/3] lei rm-watch, some error handling stuff Eric Wong
2021-07-23 10:56 ` Eric Wong [this message]
2021-07-23 10:56 ` [PATCH 2/3] lei: avoid SQLite COUNT() for dedupe Eric Wong
2021-07-23 10:56 ` [PATCH 3/3] lei rm-watch: new command to support removing watches 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=20210723105612.3883-2-e@80x24.org \
--to=e@80x24.org \
--cc=meta@public-inbox.org \
/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
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).