From 300309cebbf802463f2d7d235f2cf33d28f0760a Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Sun, 21 Mar 2021 15:50:47 +0600 Subject: lei: fix some warnings in tests 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; }; -- cgit v1.2.3-24-ge0c7