user/dev discussion of public-inbox itself
 help / color / mirror / code / Atom feed
From: Eric Wong <e@80x24.org>
To: meta@public-inbox.org
Subject: [PATCH 3/3] lei: fix some warnings in tests
Date: Sun, 21 Mar 2021 15:50:47 +0600	[thread overview]
Message-ID: <20210321095047.13855-4-e@80x24.org> (raw)
In-Reply-To: <20210321095047.13855-1-e@80x24.org>

And then test the contents of $lei_err to ensure it doesn't
happen again.

We'll also make MboxLock emit nicer warnings without the line
number, since the line number is irrelevant to the user fixing
an mbox lock contention problem.

Finally, we'll also allow showing loud warnings via
TEST_LEI_ERR_LOUD=1
---
 lib/PublicInbox/LEI.pm         | 8 ++++----
 lib/PublicInbox/LeiExternal.pm | 2 +-
 lib/PublicInbox/LeiP2q.pm      | 2 +-
 lib/PublicInbox/MboxLock.pm    | 8 ++++----
 lib/PublicInbox/TestCommon.pm  | 9 +++++++++
 5 files changed, 19 insertions(+), 10 deletions(-)

diff --git a/lib/PublicInbox/LEI.pm b/lib/PublicInbox/LEI.pm
index 72a0e52c..bf97a680 100644
--- a/lib/PublicInbox/LEI.pm
+++ b/lib/PublicInbox/LEI.pm
@@ -757,7 +757,7 @@ sub lei__complete {
 	my ($proto, undef, @spec) = @$info;
 	my $cur = pop @argv;
 	my $re = defined($cur) ? qr/\A\Q$cur\E/ : qr/./;
-	if (substr($cur // '-', 0, 1) eq '-') { # --switches
+	if (substr(my $_cur = $cur // '-', 0, 1) eq '-') { # --switches
 		# gross special case since the only git-config options
 		# Consider moving to a table if we need more special cases
 		# we use Getopt::Long for are the ones we reject, so these
@@ -781,7 +781,7 @@ sub lei__complete {
 			}
 			map {
 				my $x = length > 1 ? "--$_" : "-$_";
-				$x eq $cur ? () : $x;
+				$x eq $_cur ? () : $x;
 			} grep(!/_/, split(/\|/, $_, -1)) # help|h
 		} grep { $OPTDESC{"$_\t$cmd"} || $OPTDESC{$_} } @spec);
 	} elsif ($cmd eq 'config' && !@argv && !$CONFIG_KEYS{$cur}) {
@@ -796,13 +796,13 @@ sub lei__complete {
 			my @v = ref($v) ? split(/\|/, $v->[0]) : ();
 			# get rid of ALL CAPS placeholder (e.g "OUT")
 			# (TODO: completion for external paths)
-			shift(@v) if uc($v[0]) eq $v[0];
+			shift(@v) if scalar(@v) && uc($v[0]) eq $v[0];
 			@v;
 		} grep(/\A(?:[\w-]+\|)*$opt\b.*?(?:\t$cmd)?\z/, keys %OPTDESC);
 	}
 	$cmd =~ tr/-/_/;
 	if (my $sub = $self->can("_complete_$cmd")) {
-		puts $self, $sub->($self, @argv, $cur);
+		puts $self, $sub->($self, @argv, $cur ? ($cur) : ());
 	}
 	# TODO: URLs, pathnames, OIDs, MIDs, etc...  See optparse() for
 	# proto parsing.
diff --git a/lib/PublicInbox/LeiExternal.pm b/lib/PublicInbox/LeiExternal.pm
index b5dd85e1..f4e24c2a 100644
--- a/lib/PublicInbox/LeiExternal.pm
+++ b/lib/PublicInbox/LeiExternal.pm
@@ -222,7 +222,7 @@ sub _complete_url_common ($) {
 	# Maybe there's a better way to go about this in
 	# contrib/completion/lei-completion.bash
 	my $re = '';
-	my $cur = pop @$argv;
+	my $cur = pop(@$argv) // '';
 	if (@$argv) {
 		my @x = @$argv;
 		if ($cur eq ':' && @x) {
diff --git a/lib/PublicInbox/LeiP2q.pm b/lib/PublicInbox/LeiP2q.pm
index e7ddc852..c5718603 100644
--- a/lib/PublicInbox/LeiP2q.pm
+++ b/lib/PublicInbox/LeiP2q.pm
@@ -144,7 +144,7 @@ sub do_p2q { # via wq_do
 			my $end = ($pfx =~ s/([0-9\*]+)\z//) ? $1 : '';
 			my $x = delete($lei->{qterms}->{$pfx}) or next;
 			my $star = $end =~ tr/*//d ? '*' : '';
-			my $min_len = ($end // 0) + 0;
+			my $min_len = ($end || 0) + 0;
 
 			# no wildcards for bool_pfx_external
 			$star = '' if $pfx =~ /\A(dfpre|dfpost|mid)\z/;
diff --git a/lib/PublicInbox/MboxLock.pm b/lib/PublicInbox/MboxLock.pm
index 4e2a2d9a..bea0e325 100644
--- a/lib/PublicInbox/MboxLock.pm
+++ b/lib/PublicInbox/MboxLock.pm
@@ -43,13 +43,13 @@ EOF
 		}
 		select(undef, undef, undef, $self->{delay});
 	} while (now < $end);
-	croak "fcntl lock $self->{f}: $!";
+	die "fcntl lock timeout $self->{f}: $!\n";
 }
 
 sub acq_dotlock {
 	my ($self) = @_;
 	my $dot_lock = "$self->{f}.lock";
-	my ($pfx, $base) = ($self->{f} =~ m!(\A.*?/)([^/]+)\z!);
+	my ($pfx, $base) = ($self->{f} =~ m!(\A.*?/)?([^/]+)\z!);
 	$pfx //= '';
 	my $pid = $$;
 	my $end = now + $self->{timeout};
@@ -68,7 +68,7 @@ sub acq_dotlock {
 			croak "open $tmp (for $dot_lock): $!" if !$!{EXIST};
 		}
 	} while (now < $end);
-	croak "dotlock $dot_lock";
+	die "dotlock timeout $dot_lock\n";
 }
 
 sub acq_flock {
@@ -80,7 +80,7 @@ sub acq_flock {
 		return if flock($self->{fh}, $op);
 		select(undef, undef, undef, $self->{delay});
 	} while (now < $end);
-	croak "flock $self->{f}: $!";
+	die "flock timeout $self->{f}: $!\n";
 }
 
 sub acq {
diff --git a/lib/PublicInbox/TestCommon.pm b/lib/PublicInbox/TestCommon.pm
index 0d15514e..e67e94ea 100644
--- a/lib/PublicInbox/TestCommon.pm
+++ b/lib/PublicInbox/TestCommon.pm
@@ -457,6 +457,15 @@ sub lei (@) {
 	my $res = run_script(['lei', @$cmd], $env, $xopt // $lei_opt);
 	$err_skip and
 		$lei_err = join('', grep(!/$err_skip/, split(/^/m, $lei_err)));
+	if ($lei_err ne '') {
+		if ($lei_err =~ /Use of uninitialized/ ||
+			$lei_err =~ m!\bArgument .*? isn't numeric in !) {
+			fail "lei_err=$lei_err";
+		} else {
+			state $loud = $ENV{TEST_LEI_ERR_LOUD};
+			diag "lei_err=$lei_err" if $loud;
+		}
+	}
 	$res;
 };
 

      parent reply	other threads:[~2021-03-21  9:50 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-03-21  9:50 [PATCH 0/3] lei import fix, other fixes Eric Wong
2021-03-21  9:50 ` [PATCH 1/3] lei import: vivify external-only messages Eric Wong
2021-03-21  9:50 ` [PATCH 2/3] lei q: fix warning on remote imports Eric Wong
2021-03-21  9:50 ` Eric Wong [this message]

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: http://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=20210321095047.13855-4-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.
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).