t0000: fix test if run with TEST_OUTPUT_DIRECTORY

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 and runs "make test". 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> Acked-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Patrick Steinhardt committed Jul 20, 2021 at 08:32 UTC ade15525987a2e108fe6b6dd1a2ba4d963d64f13
2 files changed +14 -2
t/t0000-basic.sh
+5 -2
@@ -106,8 +106,11 @@ _run_sub_test_lib_test_common () {
106 EOF
107 cat >>"$name.sh" &&
108 export TEST_DIRECTORY &&
109 - TEST_OUTPUT_DIRECTORY=$(pwd) &&
110 - export TEST_OUTPUT_DIRECTORY &&
109 + # The child test re-sources GIT-BUILD-OPTIONS and may thus
110 + # override the test output directory. We thus pass it as an
111 + # explicit override to the child.
112 + TEST_OUTPUT_DIRECTORY_OVERRIDE=$(pwd) &&
113 + export TEST_OUTPUT_DIRECTORY_OVERRIDE &&
114 GIT_SKIP_TESTS=$skip &&
115 export GIT_SKIP_TESTS &&
116 sane_unset GIT_TEST_FAIL_PREREQS &&
t/test-lib.sh
+9
@@ -57,6 +57,15 @@ fi
57 . "$GIT_BUILD_DIR"/GIT-BUILD-OPTIONS
58 export PERL_PATH SHELL_PATH
59
60 +# In t0000, we need to override test directories of nested testcases. In case
61 +# the developer has TEST_OUTPUT_DIRECTORY part of his build options, then we'd
62 +# reset this value to instead contain what the developer has specified. We thus
63 +# have this knob to allow overriding the directory.
64 +if test -n "${TEST_OUTPUT_DIRECTORY_OVERRIDE}"
65 +then
66 + TEST_OUTPUT_DIRECTORY="${TEST_OUTPUT_DIRECTORY_OVERRIDE}"
67 +fi
68 +
69 # Disallow the use of abbreviated options in the test suite by default
70 if test -z "${GIT_TEST_DISALLOW_ABBREVIATED_OPTIONS}"
71 then