threads / patch / 51087

patchtest-lib: try harder to ensure a working jgit

Subject: [PATCH] test-lib: try harder to ensure a working jgit

## tl;dr

11 messages between May 14, 2019 and May 15, 2019. Diffs are folded; open one to read it.

replies: 10people: 6as markdown or json

Todd Zullinger· May 14, 2019, 02:05 UTC · lore

The JGIT prereq uses 'type jgit' to determine whether jgit is present. While this should be sufficient, if the jgit found is broken we'll waste time running tests which fail due to no fault of our own.

Use 'jgit --version' instead, to catch some badly broken jgit installations.

Signed-off-by: Todd Zullinger <tmz@pobox.com>
---
I ran into such a broken jgit on Fedora >= 30¹.  This is clearly a
problem in the Fedora jgit package which will hopefully be resolved
soon.  But it may be good to avoid wasting time debugging tests which
fail due to a broken tool outside of our control.
¹ https://bugzilla.redhat.com/1709624
 t/test-lib.sh | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
Show changes to t/test-lib.sh +1 −1
diff --git a/t/test-lib.sh b/t/test-lib.sh
index 908ddb9c46..599fd70e14 100644
--- a/t/test-lib.sh
+++ b/t/test-lib.sh
@@ -1522,7 +1522,7 @@ test_lazy_prereq NOT_ROOT '
 '
 
 test_lazy_prereq JGIT '
-	type jgit
+	jgit --version
 '
 
 # SANITY is about "can you correctly predict what the filesystem would
-- 
Todd
brian m. carlson· May 14, 2019, 02:14 UTC · re: Todd Zullinger · lore

Re: [PATCH] test-lib: try harder to ensure a working jgit

On Mon, May 13, 2019 at 10:05:20PM -0400, Todd Zullinger wrote:
Show 11 quoted lines
> diff --git a/t/test-lib.sh b/t/test-lib.sh
> index 908ddb9c46..599fd70e14 100644
> --- a/t/test-lib.sh
> +++ b/t/test-lib.sh
> @@ -1522,7 +1522,7 @@ test_lazy_prereq NOT_ROOT '
>  '
>  
>  test_lazy_prereq JGIT '
> -	type jgit
> +	jgit --version
>  '

I think this is an improvement, not only because of the reasons you mentioned, but because we remove the use of "type", which is not guaranteed to be present in a POSIX shell.

-- 
brian m. carlson: Houston, Texas, US
OpenPGP: https://keybase.io/bk2204
Jeff King· May 14, 2019, 08:45 UTC · re: brian m. carlson · lore

Re: [PATCH] test-lib: try harder to ensure a working jgit

On Tue, May 14, 2019 at 02:14:19AM +0000, brian m. carlson wrote:
Show 16 quoted lines
> On Mon, May 13, 2019 at 10:05:20PM -0400, Todd Zullinger wrote:
> > diff --git a/t/test-lib.sh b/t/test-lib.sh
> > index 908ddb9c46..599fd70e14 100644
> > --- a/t/test-lib.sh
> > +++ b/t/test-lib.sh
> > @@ -1522,7 +1522,7 @@ test_lazy_prereq NOT_ROOT '
> >  '
> >  
> >  test_lazy_prereq JGIT '
> > -	type jgit
> > +	jgit --version
> >  '
> 
> I think this is an improvement, not only because of the reasons you
> mentioned, but because we remove the use of "type", which is not
> guaranteed to be present in a POSIX shell.

Isn't it? I have always treated it as the most-portable option for this (compared to, say, `which`). It is in POSIX as a utility (albeit marked with XSI), which even says (in APPLICATION USAGE):

  Since type must be aware of the contents of the current shell
  execution environment (such as the lists of commands, functions, and
  built-ins processed by hash), it is always provided as a shell regular
  built-in.

All that said, I think Todd's patch makes perfect sense even without wanting to avoid "type".

-Peff
Junio C Hamano· May 15, 2019, 00:52 UTC · re: Jeff King · lore

Re: [PATCH] test-lib: try harder to ensure a working jgit

Jeff King <peff@peff.net> writes:
> All that said, I think Todd's patch makes perfect sense even without
> wanting to avoid "type".

Same here. t/lib-bash.sh seems to use "if type bash" to see if one is available on $PATH; I've never felt the need to avoid "type".

Todd Zullinger· May 15, 2019, 01:12 UTC · re: Jeff King · lore

Re: [PATCH] test-lib: try harder to ensure a working jgit

Hi,
Jeff King wrote:
Show 20 quoted lines
> On Tue, May 14, 2019 at 02:14:19AM +0000, brian m. carlson wrote:
> 
>> On Mon, May 13, 2019 at 10:05:20PM -0400, Todd Zullinger wrote:
>>> diff --git a/t/test-lib.sh b/t/test-lib.sh
>>> index 908ddb9c46..599fd70e14 100644
>>> --- a/t/test-lib.sh
>>> +++ b/t/test-lib.sh
>>> @@ -1522,7 +1522,7 @@ test_lazy_prereq NOT_ROOT '
>>>  '
>>>  
>>>  test_lazy_prereq JGIT '
>>> -	type jgit
>>> +	jgit --version
>>>  '
>> 
>> I think this is an improvement, not only because of the reasons you
>> mentioned, but because we remove the use of "type", which is not
>> guaranteed to be present in a POSIX shell.
>
> Isn't it?

I wondered the same thing, but I know I am not nearly as familiar with the POSIX rules as any of you.

Show 11 quoted lines
> I have always treated it as the most-portable option for this
> (compared to, say, `which`).  It is in POSIX as a utility (albeit marked
> with XSI), which even says (in APPLICATION USAGE):
> 
>   Since type must be aware of the contents of the current shell
>   execution environment (such as the lists of commands, functions, and
>   built-ins processed by hash), it is always provided as a shell regular
>   built-in.
> 
> All that said, I think Todd's patch makes perfect sense even without
> wanting to avoid "type".

Yeah, `which` surely isn't a portable option. I presumed `type` must be fairly widely available since it was in the test suite since you added it way back in 212f2ffbf0 ("t: add basic bitmap functionality tests", 2013-12-21).

I usually make use of `command -p -v $foo` in scripts that need to be portable across systems. But I don't have access to many esoteric systems.

Based on Junio's follow-up, I think we can avoid adding anything to the commit message about the use of `type` here. That way no one will take it as a sign that we should remove other uses of it just for conformance. (I will send a follow-up with an update based on Jonathan and Ævar's comments.)

Thanks to all of you.
-- 
Todd
brian m. carlson· May 15, 2019, 23:20 UTC · re: Jeff King · lore

Re: [PATCH] test-lib: try harder to ensure a working jgit

On Tue, May 14, 2019 at 04:45:34AM -0400, Jeff King wrote:
Show 13 quoted lines
> On Tue, May 14, 2019 at 02:14:19AM +0000, brian m. carlson wrote:
> > I think this is an improvement, not only because of the reasons you
> > mentioned, but because we remove the use of "type", which is not
> > guaranteed to be present in a POSIX shell.
> 
> Isn't it? I have always treated it as the most-portable option for this
> (compared to, say, `which`).  It is in POSIX as a utility (albeit marked
> with XSI), which even says (in APPLICATION USAGE):
> 
>   Since type must be aware of the contents of the current shell
>   execution environment (such as the lists of commands, functions, and
>   built-ins processed by hash), it is always provided as a shell regular
>   built-in.

It's an XSI extension, while "command -v" is not. "type" may be more common for historical reasons, but if you have systems that don't implement XSI, "command -v" is the way to go.

I suppose this doesn't matter unless we have people try to build with Debian's posh package, which only implements the minimum requirements for a Debian /bin/sh (which don't include XSI extensions, but do include local).

> All that said, I think Todd's patch makes perfect sense even without
> wanting to avoid "type".
I agree this is an improvement either way.
-- 
brian m. carlson: Houston, Texas, US
OpenPGP: https://keybase.io/bk2204
Jonathan Nieder· May 14, 2019, 02:32 UTC · re: Todd Zullinger · lore

Re: [PATCH] test-lib: try harder to ensure a working jgit

Todd Zullinger wrote:
Show 15 quoted lines
> The JGIT prereq uses 'type jgit' to determine whether jgit is present.
> While this should be sufficient, if the jgit found is broken we'll waste
> time running tests which fail due to no fault of our own.
>
> Use 'jgit --version' instead, to catch some badly broken jgit
> installations.
>
> Signed-off-by: Todd Zullinger <tmz@pobox.com>
> ---
> I ran into such a broken jgit on Fedora >= 30¹.  This is clearly a
> problem in the Fedora jgit package which will hopefully be resolved
> soon.  But it may be good to avoid wasting time debugging tests which
> fail due to a broken tool outside of our control.
>
> ¹ https://bugzilla.redhat.com/1709624
Reviewed-by: Jonathan Nieder <jrnieder@gmail.com>

It would be nice to describe that bug in the commit message, to save readers some head scratching.

Thanks, Jonathan

Ævar Arnfjörð Bjarmason· May 14, 2019, 08:09 UTC · re: Jonathan Nieder · lore

Re: [PATCH] test-lib: try harder to ensure a working jgit

On Tue, May 14 2019, Jonathan Nieder wrote:
Show 22 quoted lines
> Todd Zullinger wrote:
>
>> The JGIT prereq uses 'type jgit' to determine whether jgit is present.
>> While this should be sufficient, if the jgit found is broken we'll waste
>> time running tests which fail due to no fault of our own.
>>
>> Use 'jgit --version' instead, to catch some badly broken jgit
>> installations.
>>
>> Signed-off-by: Todd Zullinger <tmz@pobox.com>
>> ---
>> I ran into such a broken jgit on Fedora >= 30¹.  This is clearly a
>> problem in the Fedora jgit package which will hopefully be resolved
>> soon.  But it may be good to avoid wasting time debugging tests which
>> fail due to a broken tool outside of our control.
>>
>> ¹ https://bugzilla.redhat.com/1709624
>
> Reviewed-by: Jonathan Nieder <jrnieder@gmail.com>
>
> It would be nice to describe that bug in the commit message, to save
> readers some head scratching.
FWIW the jgit in Debian testing/unstable is similarly broken right now:
    $ apt policy jgit-cli
    jgit-cli:
      Installed: 3.7.1-6
      Candidate: 3.7.1-6
      Version table:
     *** 3.7.1-6 900
            900 http://ftp.nl.debian.org/debian testing/main amd64 Packages
            800 http://ftp.nl.debian.org/debian unstable/main amd64 Packages
            100 /var/lib/dpkg/status
         3.7.1-4 700
            700 http://ftp.nl.debian.org/debian stable/main amd64 Packages
    $ jgit --version; echo $?
    Error: A JNI error has occurred, please check your installation and try again
    Exception in thread "main" java.lang.NoClassDefFoundError: org/kohsuke/args4j/CmdLineException
            at java.lang.Class.getDeclaredMethods0(Native Method)
            at java.lang.Class.privateGetDeclaredMethods(Class.java:2701)
            at java.lang.Class.privateGetMethodRecursive(Class.java:3048)
            at java.lang.Class.getMethod0(Class.java:3018)
            at java.lang.Class.getMethod(Class.java:1784)
            at sun.launcher.LauncherHelper.validateMainClass(LauncherHelper.java:544)
            at sun.launcher.LauncherHelper.checkAndLoadMain(LauncherHelper.java:526)
    Caused by: java.lang.ClassNotFoundException: org.kohsuke.args4j.CmdLineException
            at java.net.URLClassLoader.findClass(URLClassLoader.java:382)
            at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
            at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:349)
            at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
            ... 7 more
    1
So rather than describe specific bugs on RedHat/Debian maybe just say:
    This guards against cases where jgit is present on the system, but
    will fail to run, e.g. because of some JRE issue, or missing Java
    dependencies. Seeing if it gets far enough to process the
    "--version" argument isn't perfect, but seems to be good enough in
    practice. It's also consistent with how we detect some other
    dependencies, see e.g. the CURL and UNZIP prerequisites.
Todd Zullinger· May 15, 2019, 01:18 UTC · re: Ævar Arnfjörð Bjarmason · lore

Re: [PATCH] test-lib: try harder to ensure a working jgit

Hi,
Ævar Arnfjörð Bjarmason wrote:
Show 27 quoted lines
> 
> On Tue, May 14 2019, Jonathan Nieder wrote:
> 
>> Todd Zullinger wrote:
>>
>>> The JGIT prereq uses 'type jgit' to determine whether jgit is present.
>>> While this should be sufficient, if the jgit found is broken we'll waste
>>> time running tests which fail due to no fault of our own.
>>>
>>> Use 'jgit --version' instead, to catch some badly broken jgit
>>> installations.
>>>
>>> Signed-off-by: Todd Zullinger <tmz@pobox.com>
>>> ---
>>> I ran into such a broken jgit on Fedora >= 30¹.  This is clearly a
>>> problem in the Fedora jgit package which will hopefully be resolved
>>> soon.  But it may be good to avoid wasting time debugging tests which
>>> fail due to a broken tool outside of our control.
>>>
>>> ¹ https://bugzilla.redhat.com/1709624
>>
>> Reviewed-by: Jonathan Nieder <jrnieder@gmail.com>
>>
>> It would be nice to describe that bug in the commit message, to save
>> readers some head scratching.
> 
> FWIW the jgit in Debian testing/unstable is similarly broken right now:
[...]
Hah, small world. :)
Show 8 quoted lines
> So rather than describe specific bugs on RedHat/Debian maybe just say:
> 
>     This guards against cases where jgit is present on the system, but
>     will fail to run, e.g. because of some JRE issue, or missing Java
>     dependencies. Seeing if it gets far enough to process the
>     "--version" argument isn't perfect, but seems to be good enough in
>     practice. It's also consistent with how we detect some other
>     dependencies, see e.g. the CURL and UNZIP prerequisites.

Well said. I indeed avoided putting the detail into the commit message because it was such a Fedora-specific bug. I'll update the commit message to add more details though, borrowing liberally from^W^W^Wperhaps stealing your suggested wording.

Thanks!
-- 
Todd
Junio C Hamano· May 15, 2019, 02:13 UTC · re: Todd Zullinger · lore

Re: [PATCH] test-lib: try harder to ensure a working jgit

Todd Zullinger <tmz@pobox.com> writes:
Show 14 quoted lines
>>     This guards against cases where jgit is present on the system, but
>>     will fail to run, e.g. because of some JRE issue, or missing Java
>>     dependencies. Seeing if it gets far enough to process the
>>     "--version" argument isn't perfect, but seems to be good enough in
>>     practice. It's also consistent with how we detect some other
>>     dependencies, see e.g. the CURL and UNZIP prerequisites.
>
> Well said.  I indeed avoided putting the detail into the
> commit message because it was such a Fedora-specific bug.
> I'll update the commit message to add more details though,
> borrowing liberally from^W^W^Wperhaps stealing your
> suggested wording.
>
> Thanks!
Thanks, all.
Todd Zullinger· May 15, 2019, 01:36 UTC · re: Todd Zullinger · lore

[PATCH v2] test-lib: try harder to ensure a working jgit

The JGIT prereq uses `type jgit` to determine whether jgit is present. While this is usually sufficient, it won't help if the jgit found is badly broken. This wastes time running tests which fail due to no fault of our own.

Use `jgit --version` instead, to guard against cases where jgit is present on the system, but will fail to run, e.g. because of some JRE issue, or missing Java dependencies. Checking that it gets far enough to process the '--version' argument isn't perfect, but seems to be good enough in practice. It's also consistent with how we detect some other dependencies, see e.g. the CURL and UNZIP prerequisites.

Signed-off-by: Todd Zullinger <tmz@pobox.com>
---
As promised, I stole the second paragraph from Ævar nearly verbatim. :)
 t/test-lib.sh | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
Show changes to t/test-lib.sh +1 −1
diff --git a/t/test-lib.sh b/t/test-lib.sh
index 908ddb9c46..599fd70e14 100644
--- a/t/test-lib.sh
+++ b/t/test-lib.sh
@@ -1522,7 +1522,7 @@ test_lazy_prereq NOT_ROOT '
 '
 
 test_lazy_prereq JGIT '
-	type jgit
+	jgit --version
 '
 
 # SANITY is about "can you correctly predict what the filesystem would
-- 
Todd

← back to recent threads