test-lib: consolidate naming of test-results paths

There are two places where we strip off any leading path components
and the '.sh' suffix from the test script's pathname, and there are
four places where we construct the name of the 't/test-results'
directory or the name of various test-specific files in there.  The
last patch in this series will add even more.

Factor these out into helper variables to avoid repeating ourselves.

Signed-off-by: SZEDER Gábor <szeder.dev@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
SZEDER Gábor
2019-01-05 02:08:56 +01:00
committed by Junio C Hamano
parent 8cf5800681
commit 62c379b8d4

View File

@ -160,6 +160,10 @@ then
test -z "$verbose_log" && verbose=t test -z "$verbose_log" && verbose=t
fi fi
TEST_NAME="$(basename "$0" .sh)"
TEST_RESULTS_DIR="$TEST_OUTPUT_DIRECTORY/test-results"
TEST_RESULTS_BASE="$TEST_RESULTS_DIR/$TEST_NAME"
# if --tee was passed, write the output not only to the terminal, but # if --tee was passed, write the output not only to the terminal, but
# additionally to the file test-results/$BASENAME.out, too. # additionally to the file test-results/$BASENAME.out, too.
if test "$GIT_TEST_TEE_STARTED" = "done" if test "$GIT_TEST_TEE_STARTED" = "done"
@ -167,12 +171,11 @@ then
: # do not redirect again : # do not redirect again
elif test -n "$tee" elif test -n "$tee"
then then
mkdir -p "$TEST_OUTPUT_DIRECTORY/test-results" mkdir -p "$TEST_RESULTS_DIR"
BASE="$TEST_OUTPUT_DIRECTORY/test-results/$(basename "$0" .sh)"
# Make this filename available to the sub-process in case it is using # Make this filename available to the sub-process in case it is using
# --verbose-log. # --verbose-log.
GIT_TEST_TEE_OUTPUT_FILE=$BASE.out GIT_TEST_TEE_OUTPUT_FILE=$TEST_RESULTS_BASE.out
export GIT_TEST_TEE_OUTPUT_FILE export GIT_TEST_TEE_OUTPUT_FILE
# Truncate before calling "tee -a" to get rid of the results # Truncate before calling "tee -a" to get rid of the results
@ -180,8 +183,8 @@ then
>"$GIT_TEST_TEE_OUTPUT_FILE" >"$GIT_TEST_TEE_OUTPUT_FILE"
(GIT_TEST_TEE_STARTED=done ${TEST_SHELL_PATH} "$0" "$@" 2>&1; (GIT_TEST_TEE_STARTED=done ${TEST_SHELL_PATH} "$0" "$@" 2>&1;
echo $? >"$BASE.exit") | tee -a "$GIT_TEST_TEE_OUTPUT_FILE" echo $? >"$TEST_RESULTS_BASE.exit") | tee -a "$GIT_TEST_TEE_OUTPUT_FILE"
test "$(cat "$BASE.exit")" = 0 test "$(cat "$TEST_RESULTS_BASE.exit")" = 0
exit exit
fi fi
@ -840,12 +843,9 @@ test_done () {
if test -z "$HARNESS_ACTIVE" if test -z "$HARNESS_ACTIVE"
then then
test_results_dir="$TEST_OUTPUT_DIRECTORY/test-results" mkdir -p "$TEST_RESULTS_DIR"
mkdir -p "$test_results_dir"
base=${0##*/}
test_results_path="$test_results_dir/${base%.sh}.counts"
cat >"$test_results_path" <<-EOF cat >"$TEST_RESULTS_BASE.counts" <<-EOF
total $test_count total $test_count
success $test_success success $test_success
fixed $test_fixed fixed $test_fixed
@ -1051,7 +1051,7 @@ then
fi fi
# Test repository # Test repository
TRASH_DIRECTORY="trash directory.$(basename "$0" .sh)" TRASH_DIRECTORY="trash directory.$TEST_NAME"
test -n "$root" && TRASH_DIRECTORY="$root/$TRASH_DIRECTORY" test -n "$root" && TRASH_DIRECTORY="$root/$TRASH_DIRECTORY"
case "$TRASH_DIRECTORY" in case "$TRASH_DIRECTORY" in
/*) ;; # absolute path is good /*) ;; # absolute path is good