git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
* [PATCH] tests: introduce test_unset_prereq, for debugging
@ 2018-04-28 22:33 Johannes Schindelin
  2018-04-30  0:38 ` Junio C Hamano
  2018-05-07 11:59 ` SZEDER Gábor
  0 siblings, 2 replies; 4+ messages in thread
From: Johannes Schindelin @ 2018-04-28 22:33 UTC (permalink / raw)
  To: git; +Cc: Johannes Schindelin, Junio C Hamano

While working on the --convert-graft-file test, I missed that I was
relying on the GPG prereq, by using output of test cases that were only
run under that prereq.

For debugging, it was really convenient to force that prereq to be
unmet, but there was no easy way to do that. So I came up with a way,
and this patch reflects the cleaned-up version of that way.

For convenience, the following two methods are now supported ways to
pretend that a prereq is not met:

	test_set_prereq !GPG

and

	test_unset_prereq GPG

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
---
Published-As: https://github.com/dscho/git/releases/tag/test-unset-prereq-v1
Fetch-It-Via: git fetch https://github.com/dscho/git test-unset-prereq-v1
 t/test-lib-functions.sh | 14 +++++++++++++-
 1 file changed, 13 insertions(+), 1 deletion(-)

diff --git a/t/test-lib-functions.sh b/t/test-lib-functions.sh
index 7d620bf2a9a..76cd6630f29 100644
--- a/t/test-lib-functions.sh
+++ b/t/test-lib-functions.sh
@@ -278,8 +278,20 @@ write_script () {
 # The single parameter is the prerequisite tag (a simple word, in all
 # capital letters by convention).
 
+test_unset_prereq () {
+	! test_have_prereq "$1" ||
+	satisfied_prereq="${satisfied_prereq% $1 *} ${satisfied_prereq#* $1 }"
+}
+
 test_set_prereq () {
-	satisfied_prereq="$satisfied_prereq$1 "
+	case "$1" in
+	!*)
+		test_unset_prereq "${1#!}"
+		;;
+	*)
+		satisfied_prereq="$satisfied_prereq$1 "
+		;;
+	esac
 }
 satisfied_prereq=" "
 lazily_testable_prereq= lazily_tested_prereq=

base-commit: 1f1cddd558b54bb0ce19c8ace353fd07b758510d
-- 
2.17.0.windows.1.36.gdf4ca5fb72a

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] tests: introduce test_unset_prereq, for debugging
  2018-04-28 22:33 [PATCH] tests: introduce test_unset_prereq, for debugging Johannes Schindelin
@ 2018-04-30  0:38 ` Junio C Hamano
  2018-05-07 11:59 ` SZEDER Gábor
  1 sibling, 0 replies; 4+ messages in thread
From: Junio C Hamano @ 2018-04-30  0:38 UTC (permalink / raw)
  To: Johannes Schindelin; +Cc: git

Johannes Schindelin <johannes.schindelin@gmx.de> writes:

> While working on the --convert-graft-file test, I missed that I was
> relying on the GPG prereq, by using output of test cases that were only
> run under that prereq.
>
> For debugging, it was really convenient to force that prereq to be
> unmet, but there was no easy way to do that. So I came up with a way,
> and this patch reflects the cleaned-up version of that way.
>
> For convenience, the following two methods are now supported ways to
> pretend that a prereq is not met:
>
> 	test_set_prereq !GPG
>
> and
>
> 	test_unset_prereq GPG

Very nice new feature, and a great description ;-)

> Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
> ---
> Published-As: https://github.com/dscho/git/releases/tag/test-unset-prereq-v1
> Fetch-It-Via: git fetch https://github.com/dscho/git test-unset-prereq-v1
>  t/test-lib-functions.sh | 14 +++++++++++++-
>  1 file changed, 13 insertions(+), 1 deletion(-)
>
> diff --git a/t/test-lib-functions.sh b/t/test-lib-functions.sh
> index 7d620bf2a9a..76cd6630f29 100644
> --- a/t/test-lib-functions.sh
> +++ b/t/test-lib-functions.sh
> @@ -278,8 +278,20 @@ write_script () {
>  # The single parameter is the prerequisite tag (a simple word, in all
>  # capital letters by convention).
>  
> +test_unset_prereq () {
> +	! test_have_prereq "$1" ||
> +	satisfied_prereq="${satisfied_prereq% $1 *} ${satisfied_prereq#* $1 }"
> +}
> +
>  test_set_prereq () {
> -	satisfied_prereq="$satisfied_prereq$1 "
> +	case "$1" in
> +	!*)
> +		test_unset_prereq "${1#!}"
> +		;;
> +	*)
> +		satisfied_prereq="$satisfied_prereq$1 "
> +		;;
> +	esac
>  }
>  satisfied_prereq=" "
>  lazily_testable_prereq= lazily_tested_prereq=
>
> base-commit: 1f1cddd558b54bb0ce19c8ace353fd07b758510d

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] tests: introduce test_unset_prereq, for debugging
  2018-04-28 22:33 [PATCH] tests: introduce test_unset_prereq, for debugging Johannes Schindelin
  2018-04-30  0:38 ` Junio C Hamano
@ 2018-05-07 11:59 ` SZEDER Gábor
  2018-05-07 14:22   ` Junio C Hamano
  1 sibling, 1 reply; 4+ messages in thread
From: SZEDER Gábor @ 2018-05-07 11:59 UTC (permalink / raw)
  To: Johannes Schindelin; +Cc: SZEDER Gábor, git, Junio C Hamano

> While working on the --convert-graft-file test, I missed that I was
> relying on the GPG prereq, by using output of test cases that were only
> run under that prereq.

That GPG vs --convert-graft-file thing really does have a bit of a
fallout, doesn't it?  I'm at five patches and possibly counting...

> For debugging, it was really convenient to force that prereq to be
> unmet, but there was no easy way to do that.

Well, in case of the GPG prereq there is an easy way: you could have
just commented out that

  . "$TEST_DIRECTORY/lib-gpg.sh"

line near the beginning of the test script.  Just a single '#'
character, it can't get much easier than that :)

But yeah, this doesn't work with every prereq...

> So I came up with a way,
> and this patch reflects the cleaned-up version of that way.
> 
> For convenience, the following two methods are now supported ways to
> pretend that a prereq is not met:
> 
> 	test_set_prereq !GPG
> 
> and
> 
> 	test_unset_prereq GPG

I'm not sure this is the right way to do this.

I wanted to run the whole test suite with all GPG tests skipped the
other day.  With this 'test_unset_prereq' I would have to modify all
test scripts containing tests depending on the GPG prereq and add
'test_unset_prereq GPG', right?  I rather modified 't/lib-gpg.sh',
i.e. only a single file, instead of modifying the 13 test scripts that
match the 'test_expect_[a-z]*[ ,]GPG[ ,]' regexp.

I think we would be better served by an environment variable similar
to $GIT_SKIP_TESTS, e.g. $GIT_SKIP_PREREQS, to list all the prereqs
that should be skipped even if they were met.

> Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
> ---
> Published-As: https://github.com/dscho/git/releases/tag/test-unset-prereq-v1
> Fetch-It-Via: git fetch https://github.com/dscho/git test-unset-prereq-v1
>  t/test-lib-functions.sh | 14 +++++++++++++-
>  1 file changed, 13 insertions(+), 1 deletion(-)

Anyway, please add a bit of documentation with docstrings and/or in
't/README'.

> 
> diff --git a/t/test-lib-functions.sh b/t/test-lib-functions.sh
> index 7d620bf2a9a..76cd6630f29 100644
> --- a/t/test-lib-functions.sh
> +++ b/t/test-lib-functions.sh
> @@ -278,8 +278,20 @@ write_script () {
>  # The single parameter is the prerequisite tag (a simple word, in all
>  # capital letters by convention).
>  
> +test_unset_prereq () {
> +	! test_have_prereq "$1" ||
> +	satisfied_prereq="${satisfied_prereq% $1 *} ${satisfied_prereq#* $1 }"
> +}
> +
>  test_set_prereq () {
> -	satisfied_prereq="$satisfied_prereq$1 "
> +	case "$1" in
> +	!*)
> +		test_unset_prereq "${1#!}"
> +		;;
> +	*)
> +		satisfied_prereq="$satisfied_prereq$1 "
> +		;;
> +	esac
>  }
>  satisfied_prereq=" "
>  lazily_testable_prereq= lazily_tested_prereq=
> 
> base-commit: 1f1cddd558b54bb0ce19c8ace353fd07b758510d
> -- 
> 2.17.0.windows.1.36.gdf4ca5fb72a
> 

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] tests: introduce test_unset_prereq, for debugging
  2018-05-07 11:59 ` SZEDER Gábor
@ 2018-05-07 14:22   ` Junio C Hamano
  0 siblings, 0 replies; 4+ messages in thread
From: Junio C Hamano @ 2018-05-07 14:22 UTC (permalink / raw)
  To: SZEDER Gábor; +Cc: Johannes Schindelin, git

SZEDER Gábor <szeder.dev@gmail.com> writes:

>> For convenience, the following two methods are now supported ways to
>> pretend that a prereq is not met:
>> 
>> 	test_set_prereq !GPG
>> 
>> and
>> 
>> 	test_unset_prereq GPG
>
> I'm not sure this is the right way to do this.
>
> I wanted to run the whole test suite with all GPG tests skipped the
> other day.  With this 'test_unset_prereq' I would have to modify all
> test scripts containing tests depending on the GPG prereq and add
> 'test_unset_prereq GPG', right?

Excellent point.  This won't cover that use case well.

That does not mean this change is useless.  If you are focusing on
developing a single test script, you can afford to tentatively add
these set/unset, just like you tentatively debug with echo's ;-)

But I find your SKIP_PREREQS an excellent idea.

It may want to be FORCE_PREREQS that lets you pretend a prereq is
not satisfied on your machine even when it actually is, and also
lets you pretend a prereq is satisfied on your machine even when it
is not.  SKIP_PREREQS would only do the first half, which would be
sufficient most of the time, though.

> I think we would be better served by an environment variable similar
> to $GIT_SKIP_TESTS, e.g. $GIT_SKIP_PREREQS, to list all the prereqs
> that should be skipped even if they were met.

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2018-05-07 14:22 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-04-28 22:33 [PATCH] tests: introduce test_unset_prereq, for debugging Johannes Schindelin
2018-04-30  0:38 ` Junio C Hamano
2018-05-07 11:59 ` SZEDER Gábor
2018-05-07 14:22   ` Junio C Hamano

Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).