threads / patch / 52336

patcht5150: skip request-pull test if Perl is disabled

Subject: [PATCH] t5150: skip request-pull test if Perl is disabled

## tl;dr

11 messages between Nov 26, 2019 and Dec 16, 2019. Diffs are folded; open one to read it.

replies: 10people: 4as markdown or json

Ruud van Asseldonk· Nov 26, 2019, 00:02 UTC · lore

The git-request-pull.sh script invokes Perl, so it requires Perl to be available, but the associated test t5150 does not skip itself when Perl has been disabled, which then makes subtest 4 through 10 fail. Subtest 3 still passes, but for the wrong reasons (it expects git-request-pull to fail, and it does fail when Perl is not available). The initial two subtests that do pass are only doing setup.

To prevent t5150 from failing the build when NO_PERL=1, add a check that sets skip_all when "! test_have_prereq PERL", just like how for example t3701-add-interactive skips itself when Perl has been disabled.

Signed-off-by: Ruud van Asseldonk <dev@veniogames.com>
---
I discovered this issue in the Git package in Nixpkgs. The Nix package
manager tries to make it hard to accidentally introduce undeclared
dependencies, and it has a sandbox that hides things in /usr/bin. So
when it builds with NO_PERL=1, it really makes no Perl available, so you
cannot accidentally depend on the Perl in /usr/bin/perl. For the tests
it does set PERL_PATH, but it does not point to a binary in /usr/bin.
 t/t5150-request-pull.sh | 6 ++++++
 1 file changed, 6 insertions(+)
Show changes to t/t5150-request-pull.sh +6 −0
diff --git a/t/t5150-request-pull.sh b/t/t5150-request-pull.sh
index 852dcd913f..1ad4ecc29a 100755
--- a/t/t5150-request-pull.sh
+++ b/t/t5150-request-pull.sh
@@ -4,6 +4,12 @@ test_description='Test workflows involving pull request.'
 
 . ./test-lib.sh
 
+if ! test_have_prereq PERL
+then
+	skip_all='skipping request-pull tests, perl not available'
+	test_done
+fi
+
 test_expect_success 'setup' '
 
 	git init --bare upstream.git &&
-- 
2.24.0
Jonathan Nieder· Nov 26, 2019, 00:43 UTC · re: Ruud van Asseldonk · lore

Re: [PATCH] t5150: skip request-pull test if Perl is disabled

Hi,
Ruud van Asseldonk wrote:
> The git-request-pull.sh script invokes Perl,

Do you have more details? From a quick glance, I wasn't able to find any instance of perl or $PERL_PATH in git-request-pull.sh.

Thanks, Jonathan

Jonathan Nieder· Nov 26, 2019, 00:46 UTC · re: Ruud van Asseldonk · lore

Re: [PATCH] t5150: skip request-pull test if Perl is disabled

Ruud van Asseldonk wrote:
> The git-request-pull.sh script invokes Perl,
Okay, on second glance I found it:
  set fnord $(git ls-remote "$url" | @@PERL@@ -e "$find_matching_ref" "${remote:-HEAD}" "$headrev")
This does seem pretty inherently to require perl, so makes sense.

I wonder if we can generalize this. For example, would it make sense to have a helper that looks for @@PERL@@ in a file, so we could say

	if uses_perl git-request-pull.sh && ! test_have_prereq PERL
	then
		...
	fi

That way, this would be more futureproof in case someone eliminates the perl dependency (either by improving that particular parsing step or by rewriting the whole program in C).

In any event,
Reviewed-by: Jonathan Nieder <jrnieder@gmail.com>
Do the request-pull tests in t7006-pager.sh need the same treatment?

Thanks, Jonathan

Ruud van Asseldonk· Nov 27, 2019, 22:42 UTC · re: Jonathan Nieder · lore

Re: [PATCH] t5150: skip request-pull test if Perl is disabled

Thanks for having a look Jonathan.
Jonathan Nieder wrote:
Show 21 quoted lines
> Ruud van Asseldonk wrote:
> 
>> The git-request-pull.sh script invokes Perl,
> 
> Okay, on second glance I found it:
> 
>    set fnord $(git ls-remote "$url" | @@PERL@@ -e "$find_matching_ref" "${remote:-HEAD}" "$headrev")
> 
> This does seem pretty inherently to require perl, so makes sense.
> 
> I wonder if we can generalize this.  For example, would it make sense to
> have a helper that looks for @@PERL@@ in a file,  so we could say
> 
> 	if uses_perl git-request-pull.sh && ! test_have_prereq PERL
> 	then
> 		...
> 	fi
> 
> That way, this would be more futureproof in case someone eliminates
> the perl dependency (either by improving that particular parsing step
> or by rewriting the whole program in C).

That sounds like a good idea. How about turning that into a test itself? The test would check that the script mentions @@PERL@@, as the first subtest. That way, if somebody removes the Perl dependency in the future, that will make the test fail, and that will be a reminder to remove the check from the test, so the test runs unconditionally.

> In any event,
> Reviewed-by: Jonathan Nieder <jrnieder@gmail.com>
> 
> Do the request-pull tests in t7006-pager.sh need the same treatment?

I think these tests are fine, they run "git -p request-pull", not enough arguments to make request-pull do something, so it prints its usage and exits with 1. The tests use test_must_fail to verify the exit code, and printing usage does go through the pager. request-pull does not call Perl when it only prints its usage.

Jeff King· Nov 27, 2019, 11:21 UTC · re: Ruud van Asseldonk · lore

Re: [PATCH] t5150: skip request-pull test if Perl is disabled

On Tue, Nov 26, 2019 at 01:02:46AM +0100, Ruud van Asseldonk wrote:
Show 19 quoted lines
> The git-request-pull.sh script invokes Perl, so it requires Perl to be
> available, but the associated test t5150 does not skip itself when Perl
> has been disabled, which then makes subtest 4 through 10 fail. Subtest 3
> still passes, but for the wrong reasons (it expects git-request-pull to
> fail, and it does fail when Perl is not available). The initial two
> subtests that do pass are only doing setup.
> 
> To prevent t5150 from failing the build when NO_PERL=1, add a check that
> sets skip_all when "! test_have_prereq PERL", just like how for example
> t3701-add-interactive skips itself when Perl has been disabled.
> 
> Signed-off-by: Ruud van Asseldonk <dev@veniogames.com>
> ---
> I discovered this issue in the Git package in Nixpkgs. The Nix package
> manager tries to make it hard to accidentally introduce undeclared
> dependencies, and it has a sandbox that hides things in /usr/bin. So
> when it builds with NO_PERL=1, it really makes no Perl available, so you
> cannot accidentally depend on the Perl in /usr/bin/perl. For the tests
> it does set PERL_PATH, but it does not point to a binary in /usr/bin.

Hmm. I don't think that technique gives complete coverage. There are other scripts (e.g., filter-branch) that call a bare "perl" (not PERL_PATH), which presumably pass the tests even though they'd break in a real-world system without perl. In fact, many scripts used to do this before fcb06a8d54 (use @@PERL@@ in built scripts, 2013-10-28). I don't think the effects on NO_PERL were really considered there; it was more about finding the right perl.

I think NO_PERL has historically mostly meant "do not build or install perl scripts", and not "everything ought to run fine without perl". We've generally assumed you can run vanilla perl snippets from the command line the same way you'd run awk or sed (and the tests use this extensively, which is why you have to set PERL_PATH again to run them).

That said, most of those casual uses of perl in actual built scripts have gone away because the shell scripts have gone away. It looks like filter-branch, request-pull, and instaweb are the last holdouts. So maybe we should be treating NO_PERL as disabling those scripts, too.

But then, should we be doing more to make it clear that those scripts are broken in a NO_PERL build? Who knows what happens if you run filter-branch without any perl available?

-Peff
Ruud van Asseldonk· Nov 27, 2019, 23:45 UTC · re: Jeff King · lore

Re: [PATCH] t5150: skip request-pull test if Perl is disabled

Show 7 quoted lines
> Hmm. I don't think that technique gives complete coverage. There are
> other scripts (e.g., filter-branch) that call a bare "perl" (not
> PERL_PATH), which presumably pass the tests even though they'd break in
> a real-world system without perl. In fact, many scripts used to do this
> before fcb06a8d54 (use @@PERL@@ in built scripts, 2013-10-28). I don't
> think the effects on NO_PERL were really considered there; it was more
> about finding the right perl.

Hmm, filter-branch calls bare "perl", not @@PERL@@ or Perl at an absolute path. At first I thought that made it pass when "perl" is on the PATH in tests. But even when I replace those with @@PERL@@, the test still pass. I will investigate further.

Show 13 quoted lines
> I think NO_PERL has historically mostly meant "do not build or install
> perl scripts", and not "everything ought to run fine without perl".
> We've generally assumed you can run vanilla perl snippets from the
> command line the same way you'd run awk or sed (and the tests use this
> extensively, which is why you have to set PERL_PATH again to run them)
> That said, most of those casual uses of perl in actual built scripts
> have gone away because the shell scripts have gone away. It looks like
> filter-branch, request-pull, and instaweb are the last holdouts. So
> maybe we should be treating NO_PERL as disabling those scripts, too.
> 
> But then, should we be doing more to make it clear that those scripts
> are broken in a NO_PERL build? Who knows what happens if you run
> filter-branch without any perl available?

My understanding was that NO_PERL controlled the runtime dependencies of Git, and that the tests require Perl either way. Of course, without Perl any scripts that depend on it can't be used, but like you say, there are few of them left. I think it would make sense to not install those scripts when NO_PERL=1. Should I make a patch to change that in the makefile?

Best, Ruud

Jonathan Nieder· Nov 28, 2019, 01:35 UTC · re: Ruud van Asseldonk · lore

Re: [PATCH] t5150: skip request-pull test if Perl is disabled

Hi,
Ruud van Asseldonk wrote:
> Jeff King wrote:
Show 5 quoted lines
>> I think NO_PERL has historically mostly meant "do not build or install
>> perl scripts", and not "everything ought to run fine without perl".
>> We've generally assumed you can run vanilla perl snippets from the
>> command line the same way you'd run awk or sed (and the tests use this
>> extensively, which is why you have to set PERL_PATH again to run them)

We've definitely held the stance that NO_PERL doesn't mean to disable perl in tests. For casual use of perl in installed shell scripts, on the other hand, I suspect it was more that we forgot about them than that we had decided one way or another. :)

[...]
Show 14 quoted lines
>> That said, most of those casual uses of perl in actual built scripts
>> have gone away because the shell scripts have gone away. It looks like
>> filter-branch, request-pull, and instaweb are the last holdouts. So
>> maybe we should be treating NO_PERL as disabling those scripts, too.
>>
>> But then, should we be doing more to make it clear that those scripts
>> are broken in a NO_PERL build? Who knows what happens if you run
>> filter-branch without any perl available?
>
> My understanding was that NO_PERL controlled the runtime dependencies of
> Git, and that the tests require Perl either way. Of course, without Perl any
> scripts that depend on it can't be used, but like you say, there are few of
> them left. I think it would make sense to not install those scripts when
> NO_PERL=1. Should I make a patch to change that in the makefile?

Yes, that sounds good to me. (The status quo also seems fine to me, but I like that this proposed approach would simplify things a little.)

Thanks for working on this, and sorry for the earlier noise.

Sincerely, Jonathan

Jonathan Nieder· Nov 28, 2019, 01:31 UTC · re: Jeff King · lore

Re: [PATCH] t5150: skip request-pull test if Perl is disabled

Jeff King wrote:
Show 7 quoted lines
> Hmm. I don't think that technique gives complete coverage. There are
> other scripts (e.g., filter-branch) that call a bare "perl" (not
> PERL_PATH), which presumably pass the tests even though they'd break in
> a real-world system without perl. In fact, many scripts used to do this
> before fcb06a8d54 (use @@PERL@@ in built scripts, 2013-10-28). I don't
> think the effects on NO_PERL were really considered there; it was more
> about finding the right perl.
Oh!  Thanks for looking deeper.
Show 5 quoted lines
> I think NO_PERL has historically mostly meant "do not build or install
> perl scripts", and not "everything ought to run fine without perl".
> We've generally assumed you can run vanilla perl snippets from the
> command line the same way you'd run awk or sed (and the tests use this
> extensively, which is why you have to set PERL_PATH again to run them).

Right. PERL_PATH and NO_PERL are more orthogonal than I had thought. So this is

  Not-Reviewed-by: Jonathan Nieder <jrnieder@gmail.com>
--- the patch shouldn't be applied as is.
Show 8 quoted lines
> That said, most of those casual uses of perl in actual built scripts
> have gone away because the shell scripts have gone away. It looks like
> filter-branch, request-pull, and instaweb are the last holdouts. So
> maybe we should be treating NO_PERL as disabling those scripts, too.
>
> But then, should we be doing more to make it clear that those scripts
> are broken in a NO_PERL build? Who knows what happens if you run
> filter-branch without any perl available?
Agreed: if we want to follow this approach, we should install stubs in
place of those scripts when NO_PERL=YesPlease.  Will say more about
this in a separate reply.

Thanks for catching it, Jonathan

Junio C Hamano· Dec 2, 2019, 06:19 UTC · re: Jonathan Nieder · lore

Re: [PATCH] t5150: skip request-pull test if Perl is disabled

Jonathan Nieder <jrnieder@gmail.com> writes:
Show 7 quoted lines
>   Not-Reviewed-by: Jonathan Nieder <jrnieder@gmail.com>
>
> --- the patch shouldn't be applied as is.
> ...
> Agreed: if we want to follow this approach, we should install stubs in
> place of those scripts when NO_PERL=YesPlease.  Will say more about
> this in a separate reply.

I am just leaving a note here in the thread to make sure I notice if there is any progress/conclusion, until which time I'll keep the patch on hold. Thanks.

Jeff King· Dec 13, 2019, 07:46 UTC · re: Junio C Hamano · lore

Re: [PATCH] t5150: skip request-pull test if Perl is disabled

On Sun, Dec 01, 2019 at 10:19:15PM -0800, Junio C Hamano wrote:
Show 13 quoted lines
> Jonathan Nieder <jrnieder@gmail.com> writes:
> 
> >   Not-Reviewed-by: Jonathan Nieder <jrnieder@gmail.com>
> >
> > --- the patch shouldn't be applied as is.
> > ...
> > Agreed: if we want to follow this approach, we should install stubs in
> > place of those scripts when NO_PERL=YesPlease.  Will say more about
> > this in a separate reply.
> 
> I am just leaving a note here in the thread to make sure I notice if
> there is any progress/conclusion, until which time I'll keep the
> patch on hold.  Thanks.

Thinking on this more, it might not be a bad idea to take Ruud's initial patch here. It certainly makes things better for his NO_PERL case now, and then in the future we can either:

 - stop building request-pull entirely with NO_PERL, but we'd still need
   the tests to realize that we shouldn't be testing it
 - change request-pull to not require perl, at which point we'd remove
   this restriction
-Peff
Junio C Hamano· Dec 16, 2019, 18:32 UTC · re: Jeff King · lore

Re: [PATCH] t5150: skip request-pull test if Perl is disabled

Jeff King <peff@peff.net> writes:
Show 25 quoted lines
> On Sun, Dec 01, 2019 at 10:19:15PM -0800, Junio C Hamano wrote:
>
>> Jonathan Nieder <jrnieder@gmail.com> writes:
>> 
>> >   Not-Reviewed-by: Jonathan Nieder <jrnieder@gmail.com>
>> >
>> > --- the patch shouldn't be applied as is.
>> > ...
>> > Agreed: if we want to follow this approach, we should install stubs in
>> > place of those scripts when NO_PERL=YesPlease.  Will say more about
>> > this in a separate reply.
>> 
>> I am just leaving a note here in the thread to make sure I notice if
>> there is any progress/conclusion, until which time I'll keep the
>> patch on hold.  Thanks.
>
> Thinking on this more, it might not be a bad idea to take Ruud's initial
> patch here. It certainly makes things better for his NO_PERL case now,
> and then in the future we can either:
>
>  - stop building request-pull entirely with NO_PERL, but we'd still need
>    the tests to realize that we shouldn't be testing it
>
>  - change request-pull to not require perl, at which point we'd remove
>    this restriction

Hmph, that is a reasonable stance to take, I would think. Let's move it forward.

Thanks.

← back to recent threads