All of lore.kernel.org
 help / color / mirror / Atom feed
From: Patrick Steinhardt <ps@pks.im>
To: git@vger.kernel.org
Cc: Jeff King <peff@peff.net>, Junio C Hamano <gitster@pobox.com>,
	Felipe Contreras <felipe.contreras@gmail.com>
Subject: [PATCH] t0000: fix test if run with TEST_OUTPUT_DIRECTORY
Date: Tue, 20 Jul 2021 08:32:26 +0200	[thread overview]
Message-ID: <44006e7b0bdda50dc51153cc2efb6ae954d4eecb.1626762728.git.ps@pks.im> (raw)
In-Reply-To: <60f5d923848d3_145c71208cc@natae.notmuch>

[-- Attachment #1: Type: text/plain, Size: 3219 bytes --]

Testcases in t0000 are quite special given that they many of them run
nested testcases to verify that testing functionality itself works as
expected. These nested testcases are realized by writing a new ad-hoc
test script which again sources test-lib.sh, where the new script is
created in a nested subdirectory located beneath the current trash
directory. We then execute the new test script with the nested
subdirectory as current working directory and explicitly re-export
TEST_OUTPUT_DIRECTORY to point to that directory.

While this works as expected in the general case, it falls apart when
the developer has TEST_OUTPUT_DIRECTORY explicitly defined either via
the environment or via config.mak. In that case, test-lib.sh will
clobber the value that we've just carefully set up to instead contain
what the developer has defined. As a result, the TEST_OUTPUT_DIRECTORY
continues to point at the root output directory, not at the nested one.

This issue causes breakage in the 'test_atexit is run' test case: the
nested test case writes files into "../../", which is assumed to be the
parent's trash directory. But because TEST_OUTPUT_DIRECTORY already
points to to the root output directory, we instead end up writing those
files outside of the output directory. The parent test case will then
try to check whether those files still exist in its own trash directory,
which thus must fail now.

Fix the issue by adding a new TEST_OUTPUT_DIRECTORY_OVERRIDE variable.
If set, then we'll always override the TEST_OUTPUT_DIRECTORY with its
value after sourcing GIT-BUILD-OPTIONS.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
---
 t/t0000-basic.sh | 7 +++++--
 t/test-lib.sh    | 9 +++++++++
 2 files changed, 14 insertions(+), 2 deletions(-)

diff --git a/t/t0000-basic.sh b/t/t0000-basic.sh
index 2c6e34b947..09d2202748 100755
--- a/t/t0000-basic.sh
+++ b/t/t0000-basic.sh
@@ -89,8 +89,11 @@ _run_sub_test_lib_test_common () {
 		EOF
 		cat >>"$name.sh" &&
 		export TEST_DIRECTORY &&
-		TEST_OUTPUT_DIRECTORY=$(pwd) &&
-		export TEST_OUTPUT_DIRECTORY &&
+		# The child test re-sources GIT-BUILD-OPTIONS and may thus
+		# override the test output directory. We thus pass it as an
+		# explicit override to the child.
+		TEST_OUTPUT_DIRECTORY_OVERRIDE=$(pwd) &&
+		export TEST_OUTPUT_DIRECTORY_OVERRIDE &&
 		sane_unset GIT_TEST_FAIL_PREREQS &&
 		if test -z "$neg"
 		then
diff --git a/t/test-lib.sh b/t/test-lib.sh
index 9e26860544..da13190970 100644
--- a/t/test-lib.sh
+++ b/t/test-lib.sh
@@ -57,6 +57,15 @@ fi
 . "$GIT_BUILD_DIR"/GIT-BUILD-OPTIONS
 export PERL_PATH SHELL_PATH
 
+# In t0000, we need to override test directories of nested testcases. In case
+# the developer has TEST_OUTPUT_DIRECTORY part of his build options, then we'd
+# reset this value to instead contain what the developer has specified. We thus
+# have this knob to allow overriding the directory.
+if test -n "${TEST_OUTPUT_DIRECTORY_OVERRIDE}"
+then
+	TEST_OUTPUT_DIRECTORY="${TEST_OUTPUT_DIRECTORY_OVERRIDE}"
+fi
+
 # Disallow the use of abbreviated options in the test suite by default
 if test -z "${GIT_TEST_DISALLOW_ABBREVIATED_OPTIONS}"
 then
-- 
2.32.0


[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

  parent reply	other threads:[~2021-07-20  6:32 UTC|newest]

Thread overview: 43+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-07-14  1:07 What's cooking in git.git (Jul 2021, #03; Tue, 13) Junio C Hamano
2021-07-14  2:16 ` Eric Sunshine
2021-07-14 16:30   ` Junio C Hamano
2021-07-14 22:39     ` Eric Sunshine
2021-07-14 22:44       ` Junio C Hamano
2021-07-14  8:42 ` Han-Wen Nienhuys
2021-07-14 11:53   ` Ævar Arnfjörð Bjarmason
2021-07-14 11:54   ` Ævar Arnfjörð Bjarmason
2021-07-14 17:28   ` Junio C Hamano
2021-07-14 13:11 ` Derrick Stolee
2021-07-14 14:32   ` Ævar Arnfjörð Bjarmason
2021-07-15 16:25     ` [PATCH] CodingGuidelines: recommend gender-neutral description Junio C Hamano
2021-07-15 16:35       ` Eric Sunshine
2021-07-15 16:47         ` Taylor Blau
2021-07-15 18:02           ` Junio C Hamano
2021-07-16 21:25           ` Felipe Contreras
2021-07-15 17:27         ` Derrick Stolee
2021-07-16 15:11           ` Johannes Schindelin
2021-07-16 21:22           ` Felipe Contreras
2021-07-16 18:41       ` [PATCH v2] " Junio C Hamano
2021-07-16 19:05         ` Derrick Stolee
2021-07-16 19:11         ` Ævar Arnfjörð Bjarmason
2021-07-16 19:50           ` Junio C Hamano
2021-07-16 21:14             ` Felipe Contreras
2021-08-12  8:35       ` [PATCH] " Bagas Sanjaya
2021-07-14 20:11 ` What's cooking in git.git (Jul 2021, #03; Tue, 13) Taylor Blau
2021-07-19  7:35 ` Patrick Steinhardt
2021-07-19  7:53   ` Felipe Contreras
2021-07-19  8:35     ` Jeff King
2021-07-19 10:42       ` Felipe Contreras
2021-07-19 10:56         ` Patrick Steinhardt
2021-07-19 11:25           ` Felipe Contreras
2021-07-19  8:33   ` Jeff King
2021-07-19 10:41     ` Patrick Steinhardt
2021-07-19 10:52       ` Jeff King
2021-07-19 18:40       ` Junio C Hamano
2021-07-19 19:57         ` Felipe Contreras
2021-07-20  6:31           ` Patrick Steinhardt
2021-07-20  7:21             ` Felipe Contreras
2021-07-20  6:32           ` Patrick Steinhardt [this message]
2021-07-20  7:11             ` [PATCH] t0000: fix test if run with TEST_OUTPUT_DIRECTORY Jeff King
2021-07-20 16:21               ` Junio C Hamano
2021-07-20  7:24             ` Felipe Contreras

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=44006e7b0bdda50dc51153cc2efb6ae954d4eecb.1626762728.git.ps@pks.im \
    --to=ps@pks.im \
    --cc=felipe.contreras@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=peff@peff.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.