{"thread":{"id":"48375","subject":"[PATCH] tests: introduce test_unset_prereq, for debugging","startedAt":"2018-04-28T22:33:51Z","lastAt":"2018-05-07T14:22:42Z","messageCount":4,"participants":["Johannes Schindelin","Junio C Hamano","SZEDER Gábor"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"346054","messageId":"b94af009c1bc9c9b96d977b1c5775ff73669138f.1524954814.git.johannes.schindelin@gmx.de","threadId":"48375","inReplyTo":null,"subject":"[PATCH] tests: introduce test_unset_prereq, for debugging","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2018-04-28T22:33:36Z","receivedAt":"2018-04-28T22:33:51Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"While working on the --convert-graft-file test, I missed that I was\nrelying on the GPG prereq, by using output of test cases that were only\nrun under that prereq.\n\nFor debugging, it was really convenient to force that prereq to be\nunmet, but there was no easy way to do that. So I came up with a way,\nand this patch reflects the cleaned-up version of that way.\n\nFor convenience, the following two methods are now supported ways to\npretend that a prereq is not met:\n\n\ttest_set_prereq !GPG\n\nand\n\n\ttest_unset_prereq GPG\n\nSigned-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>\n---\nPublished-As: https://github.com/dscho/git/releases/tag/test-unset-prereq-v1\nFetch-It-Via: git fetch https://github.com/dscho/git test-unset-prereq-v1\n t/test-lib-functions.sh | 14 +++++++++++++-\n 1 file changed, 13 insertions(+), 1 deletion(-)\n\ndiff --git a/t/test-lib-functions.sh b/t/test-lib-functions.sh\nindex 7d620bf2a9a..76cd6630f29 100644\n--- a/t/test-lib-functions.sh\n+++ b/t/test-lib-functions.sh\n@@ -278,8 +278,20 @@ write_script () {\n # The single parameter is the prerequisite tag (a simple word, in all\n # capital letters by convention).\n \n+test_unset_prereq () {\n+\t! test_have_prereq \"$1\" ||\n+\tsatisfied_prereq=\"${satisfied_prereq% $1 *} ${satisfied_prereq#* $1 }\"\n+}\n+\n test_set_prereq () {\n-\tsatisfied_prereq=\"$satisfied_prereq$1 \"\n+\tcase \"$1\" in\n+\t!*)\n+\t\ttest_unset_prereq \"${1#!}\"\n+\t\t;;\n+\t*)\n+\t\tsatisfied_prereq=\"$satisfied_prereq$1 \"\n+\t\t;;\n+\tesac\n }\n satisfied_prereq=\" \"\n lazily_testable_prereq= lazily_tested_prereq=\n\nbase-commit: 1f1cddd558b54bb0ce19c8ace353fd07b758510d\n-- \n2.17.0.windows.1.36.gdf4ca5fb72a\n"},{"id":"346118","messageId":"xmqqd0yhzfxk.fsf@gitster-ct.c.googlers.com","threadId":"48375","inReplyTo":"b94af009c1bc9c9b96d977b1c5775ff73669138f.1524954814.git.johannes.schindelin@gmx.de","subject":"Re: [PATCH] tests: introduce test_unset_prereq, for debugging","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2018-04-30T00:38:47Z","receivedAt":"2018-04-30T00:38:53Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Johannes Schindelin <johannes.schindelin@gmx.de> writes:\n\n> While working on the --convert-graft-file test, I missed that I was\n> relying on the GPG prereq, by using output of test cases that were only\n> run under that prereq.\n>\n> For debugging, it was really convenient to force that prereq to be\n> unmet, but there was no easy way to do that. So I came up with a way,\n> and this patch reflects the cleaned-up version of that way.\n>\n> For convenience, the following two methods are now supported ways to\n> pretend that a prereq is not met:\n>\n> \ttest_set_prereq !GPG\n>\n> and\n>\n> \ttest_unset_prereq GPG\n\nVery nice new feature, and a great description ;-)\n\n> Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>\n> ---\n> Published-As: https://github.com/dscho/git/releases/tag/test-unset-prereq-v1\n> Fetch-It-Via: git fetch https://github.com/dscho/git test-unset-prereq-v1\n>  t/test-lib-functions.sh | 14 +++++++++++++-\n>  1 file changed, 13 insertions(+), 1 deletion(-)\n>\n> diff --git a/t/test-lib-functions.sh b/t/test-lib-functions.sh\n> index 7d620bf2a9a..76cd6630f29 100644\n> --- a/t/test-lib-functions.sh\n> +++ b/t/test-lib-functions.sh\n> @@ -278,8 +278,20 @@ write_script () {\n>  # The single parameter is the prerequisite tag (a simple word, in all\n>  # capital letters by convention).\n>  \n> +test_unset_prereq () {\n> +\t! test_have_prereq \"$1\" ||\n> +\tsatisfied_prereq=\"${satisfied_prereq% $1 *} ${satisfied_prereq#* $1 }\"\n> +}\n> +\n>  test_set_prereq () {\n> -\tsatisfied_prereq=\"$satisfied_prereq$1 \"\n> +\tcase \"$1\" in\n> +\t!*)\n> +\t\ttest_unset_prereq \"${1#!}\"\n> +\t\t;;\n> +\t*)\n> +\t\tsatisfied_prereq=\"$satisfied_prereq$1 \"\n> +\t\t;;\n> +\tesac\n>  }\n>  satisfied_prereq=\" \"\n>  lazily_testable_prereq= lazily_tested_prereq=\n>\n> base-commit: 1f1cddd558b54bb0ce19c8ace353fd07b758510d\n"},{"id":"346863","messageId":"20180507115950.3887-1-szeder.dev@gmail.com","threadId":"48375","inReplyTo":"b94af009c1bc9c9b96d977b1c5775ff73669138f.1524954814.git.johannes.schindelin@gmx.de","subject":"Re: [PATCH] tests: introduce test_unset_prereq, for debugging","fromName":"SZEDER Gábor","fromEmail":"szeder.dev@gmail.com","sentAt":"2018-05-07T11:59:50Z","receivedAt":"2018-05-07T12:00:00Z","isPatch":true,"sender":{"key":"szeder.dev@gmail.com","avatar":"https://avatars.githubusercontent.com/u/116324?v=4"},"body":"> While working on the --convert-graft-file test, I missed that I was\n> relying on the GPG prereq, by using output of test cases that were only\n> run under that prereq.\n\nThat GPG vs --convert-graft-file thing really does have a bit of a\nfallout, doesn't it?  I'm at five patches and possibly counting...\n\n> For debugging, it was really convenient to force that prereq to be\n> unmet, but there was no easy way to do that.\n\nWell, in case of the GPG prereq there is an easy way: you could have\njust commented out that\n\n  . \"$TEST_DIRECTORY/lib-gpg.sh\"\n\nline near the beginning of the test script.  Just a single '#'\ncharacter, it can't get much easier than that :)\n\nBut yeah, this doesn't work with every prereq...\n\n> So I came up with a way,\n> and this patch reflects the cleaned-up version of that way.\n> \n> For convenience, the following two methods are now supported ways to\n> pretend that a prereq is not met:\n> \n> \ttest_set_prereq !GPG\n> \n> and\n> \n> \ttest_unset_prereq GPG\n\nI'm not sure this is the right way to do this.\n\nI wanted to run the whole test suite with all GPG tests skipped the\nother day.  With this 'test_unset_prereq' I would have to modify all\ntest scripts containing tests depending on the GPG prereq and add\n'test_unset_prereq GPG', right?  I rather modified 't/lib-gpg.sh',\ni.e. only a single file, instead of modifying the 13 test scripts that\nmatch the 'test_expect_[a-z]*[ ,]GPG[ ,]' regexp.\n\nI think we would be better served by an environment variable similar\nto $GIT_SKIP_TESTS, e.g. $GIT_SKIP_PREREQS, to list all the prereqs\nthat should be skipped even if they were met.\n\n> Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>\n> ---\n> Published-As: https://github.com/dscho/git/releases/tag/test-unset-prereq-v1\n> Fetch-It-Via: git fetch https://github.com/dscho/git test-unset-prereq-v1\n>  t/test-lib-functions.sh | 14 +++++++++++++-\n>  1 file changed, 13 insertions(+), 1 deletion(-)\n\nAnyway, please add a bit of documentation with docstrings and/or in\n't/README'.\n\n> \n> diff --git a/t/test-lib-functions.sh b/t/test-lib-functions.sh\n> index 7d620bf2a9a..76cd6630f29 100644\n> --- a/t/test-lib-functions.sh\n> +++ b/t/test-lib-functions.sh\n> @@ -278,8 +278,20 @@ write_script () {\n>  # The single parameter is the prerequisite tag (a simple word, in all\n>  # capital letters by convention).\n>  \n> +test_unset_prereq () {\n> +\t! test_have_prereq \"$1\" ||\n> +\tsatisfied_prereq=\"${satisfied_prereq% $1 *} ${satisfied_prereq#* $1 }\"\n> +}\n> +\n>  test_set_prereq () {\n> -\tsatisfied_prereq=\"$satisfied_prereq$1 \"\n> +\tcase \"$1\" in\n> +\t!*)\n> +\t\ttest_unset_prereq \"${1#!}\"\n> +\t\t;;\n> +\t*)\n> +\t\tsatisfied_prereq=\"$satisfied_prereq$1 \"\n> +\t\t;;\n> +\tesac\n>  }\n>  satisfied_prereq=\" \"\n>  lazily_testable_prereq= lazily_tested_prereq=\n> \n> base-commit: 1f1cddd558b54bb0ce19c8ace353fd07b758510d\n> -- \n> 2.17.0.windows.1.36.gdf4ca5fb72a\n> \n"},{"id":"346869","messageId":"xmqqfu33pmtv.fsf@gitster-ct.c.googlers.com","threadId":"48375","inReplyTo":"20180507115950.3887-1-szeder.dev@gmail.com","subject":"Re: [PATCH] tests: introduce test_unset_prereq, for debugging","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2018-05-07T14:22:36Z","receivedAt":"2018-05-07T14:22:42Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"SZEDER Gábor <szeder.dev@gmail.com> writes:\n\n>> For convenience, the following two methods are now supported ways to\n>> pretend that a prereq is not met:\n>> \n>> \ttest_set_prereq !GPG\n>> \n>> and\n>> \n>> \ttest_unset_prereq GPG\n>\n> I'm not sure this is the right way to do this.\n>\n> I wanted to run the whole test suite with all GPG tests skipped the\n> other day.  With this 'test_unset_prereq' I would have to modify all\n> test scripts containing tests depending on the GPG prereq and add\n> 'test_unset_prereq GPG', right?\n\nExcellent point.  This won't cover that use case well.\n\nThat does not mean this change is useless.  If you are focusing on\ndeveloping a single test script, you can afford to tentatively add\nthese set/unset, just like you tentatively debug with echo's ;-)\n\nBut I find your SKIP_PREREQS an excellent idea.\n\nIt may want to be FORCE_PREREQS that lets you pretend a prereq is\nnot satisfied on your machine even when it actually is, and also\nlets you pretend a prereq is satisfied on your machine even when it\nis not.  SKIP_PREREQS would only do the first half, which would be\nsufficient most of the time, though.\n\n> I think we would be better served by an environment variable similar\n> to $GIT_SKIP_TESTS, e.g. $GIT_SKIP_PREREQS, to list all the prereqs\n> that should be skipped even if they were met.\n"}]}