test-lib: make $GIT_BUILD_DIR an absolute path

Change the GIT_BUILD_DIR from a path like "/path/to/build/t/.." to "/path/to/build". The "TEST_DIRECTORY" here is already made an absolute path a few lines above this. We could simply do $(cd "$TEST_DIRECTORY"/.." && pwd) here, but as noted in the preceding commit the "$TEST_DIRECTORY" can't be anything except the path containing this test-lib.sh file at this point, so we can more cheaply and equally strip the "/t" off the end. This change will be helpful to LSAN_OPTIONS which will want to strip the build directory path from filenames, which we couldn't do if we had a "/.." in there. Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Ævar Arnfjörð Bjarmason committed Feb 27, 2022 at 11:25 UTC b9638d7286fbfef46e325049cdd8cfa3fff3edc1
1 file changed +3 -2
t/test-lib.sh
+3 -2
@@ -41,8 +41,8 @@ then
41 # elsewhere
42 TEST_OUTPUT_DIRECTORY=$TEST_DIRECTORY
43 fi
44 -GIT_BUILD_DIR="$TEST_DIRECTORY"/..
45 -if test "$TEST_DIRECTORY" = "${TEST_DIRECTORY%/t}"
44 +GIT_BUILD_DIR="${TEST_DIRECTORY%/t}"
45 +if test "$TEST_DIRECTORY" = "$GIT_BUILD_DIR"
46 then
47 echo "PANIC: Running in a $TEST_DIRECTORY that doesn't end in '/t'?" >&2
48 exit 1
@@ -64,6 +64,7 @@ prepend_var () {
64 # problems. The GIT_SAN_OPTIONS variable can be used to set common
65 # defaults shared between [AL]SAN_OPTIONS.
66 prepend_var GIT_SAN_OPTIONS : abort_on_error=1
67 +prepend_var GIT_SAN_OPTIONS : strip_path_prefix=\"$GIT_BUILD_DIR/\"
68
69 # If we were built with ASAN, it may complain about leaks
70 # of program-lifetime variables. Disable it by default to lower