]> Sergey Matveev's repositories - public-inbox.git/commitdiff
lei: fix some warnings in tests
authorEric Wong <e@80x24.org>
Sun, 21 Mar 2021 09:50:47 +0000 (15:50 +0600)
committerEric Wong <e@80x24.org>
Sun, 21 Mar 2021 10:35:11 +0000 (10:35 +0000)
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
lib/PublicInbox/LeiExternal.pm
lib/PublicInbox/LeiP2q.pm
lib/PublicInbox/MboxLock.pm
lib/PublicInbox/TestCommon.pm

index 72a0e52c62d148a7b61da1ce063c0ac26e81583d..bf97a6809ddb5a07fb266e531404255ac58743ad 100644 (file)
@@ -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.
index b5dd85e158b18f007cf53f97e6e6c08f896430e0..f4e24c2a131ef3d6e4fa58dcc12b14183ddf4281 100644 (file)
@@ -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) {
index e7ddc852e492cfe500aa8b9ce31215f2bf498acb..c5718603c672b158934fc6067c8717f6e93423ab 100644 (file)
@@ -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/;
index 4e2a2d9a4fed66bfb3d5328143345af51d697618..bea0e3253e6471b6f36637a66296f5b31835baaf 100644 (file)
@@ -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 {
index 0d15514e2cb6f2859ab2296515fa82d9e05d2574..e67e94ea830bdfe8d0389529da9d1e16e2059693 100644 (file)
@@ -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;
 };