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 +++++++++ diff --git a/lib/PublicInbox/LEI.pm b/lib/PublicInbox/LEI.pm index 72a0e52c62d148a7b61da1ce063c0ac26e81583d..bf97a6809ddb5a07fb266e531404255ac58743ad 100644 --- a/lib/PublicInbox/LEI.pm +++ b/lib/PublicInbox/LEI.pm @@ -757,7 +757,7 @@ }; 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 @@ s/([\w\-]+)/$1|no-$1/g } 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 @@ my $v = $OPTDESC{$_}; 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 b5dd85e158b18f007cf53f97e6e6c08f896430e0..f4e24c2a131ef3d6e4fa58dcc12b14183ddf4281 100644 --- a/lib/PublicInbox/LeiExternal.pm +++ b/lib/PublicInbox/LeiExternal.pm @@ -222,7 +222,7 @@ # Workaround bash word-splitting URLs to ['https', ':', '//' ...] # 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 e7ddc852e492cfe500aa8b9ce31215f2bf498acb..c5718603c672b158934fc6067c8717f6e93423ab 100644 --- a/lib/PublicInbox/LeiP2q.pm +++ b/lib/PublicInbox/LeiP2q.pm @@ -144,7 +144,7 @@ my $plusminus = ($pfx =~ s/\A([\+\-])//) ? $1 : ''; 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 4e2a2d9a4fed66bfb3d5328143345af51d697618..bea0e3253e6471b6f36637a66296f5b31835baaf 100644 --- a/lib/PublicInbox/MboxLock.pm +++ b/lib/PublicInbox/MboxLock.pm @@ -43,13 +43,13 @@ return if $fl->lock($self->{fh}, $op); } 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 @@ } else { 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 @@ do { 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 0d15514e2cb6f2859ab2296515fa82d9e05d2574..e67e94ea830bdfe8d0389529da9d1e16e2059693 100644 --- a/lib/PublicInbox/TestCommon.pm +++ b/lib/PublicInbox/TestCommon.pm @@ -457,6 +457,15 @@ } 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; };