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>
SZEDER Gábor committed
Jan 5, 2019 at 02:08 UTC
62c379b8d4b56df94c79ca06e5aceff45f617901
1 file changed
+11
-11
t/test-lib.sh
+11
-11
@@ -160,6 +160,10 @@ then
160
test -z "$verbose_log" && verbose=t
161
fi
162
163
+TEST_NAME="$(basename "$0" .sh)"
164
+TEST_RESULTS_DIR="$TEST_OUTPUT_DIRECTORY/test-results"
165
+TEST_RESULTS_BASE="$TEST_RESULTS_DIR/$TEST_NAME"
166
+
167
# if --tee was passed, write the output not only to the terminal, but
168
# additionally to the file test-results/$BASENAME.out, too.
169
if test "$GIT_TEST_TEE_STARTED" = "done"
@@ -167,12 +171,11 @@ then
171
: # do not redirect again
172
elif test -n "$tee"
173
then
170
- mkdir -p "$TEST_OUTPUT_DIRECTORY/test-results"
171
- BASE="$TEST_OUTPUT_DIRECTORY/test-results/$(basename "$0" .sh)"
174
+ mkdir -p "$TEST_RESULTS_DIR"
175
176
# Make this filename available to the sub-process in case it is using
177
# --verbose-log.
175
- GIT_TEST_TEE_OUTPUT_FILE=$BASE.out
178
+ GIT_TEST_TEE_OUTPUT_FILE=$TEST_RESULTS_BASE.out
179
export GIT_TEST_TEE_OUTPUT_FILE
180
181
# Truncate before calling "tee -a" to get rid of the results
@@ -180,8 +183,8 @@ then
183
>"$GIT_TEST_TEE_OUTPUT_FILE"
184
185
(GIT_TEST_TEE_STARTED=done ${TEST_SHELL_PATH} "$0" "$@" 2>&1;
183
- echo $? >"$BASE.exit") | tee -a "$GIT_TEST_TEE_OUTPUT_FILE"
184
- test "$(cat "$BASE.exit")" = 0
186
+ echo $? >"$TEST_RESULTS_BASE.exit") | tee -a "$GIT_TEST_TEE_OUTPUT_FILE"
187
+ test "$(cat "$TEST_RESULTS_BASE.exit")" = 0
188
exit
189
fi
190
@@ -840,12 +843,9 @@ test_done () {
843
844
if test -z "$HARNESS_ACTIVE"
845
then
843
- test_results_dir="$TEST_OUTPUT_DIRECTORY/test-results"
844
- mkdir -p "$test_results_dir"
845
- base=${0##*/}
846
- test_results_path="$test_results_dir/${base%.sh}.counts"
846
+ mkdir -p "$TEST_RESULTS_DIR"
847
848
- cat >"$test_results_path" <<-EOF
848
+ cat >"$TEST_RESULTS_BASE.counts" <<-EOF
849
total $test_count
850
success $test_success
851
fixed $test_fixed
@@ -1051,7 +1051,7 @@ then
1051
fi
1052
1053
# Test repository
1054
-TRASH_DIRECTORY="trash directory.$(basename "$0" .sh)"
1054
+TRASH_DIRECTORY="trash directory.$TEST_NAME"
1055
test -n "$root" && TRASH_DIRECTORY="$root/$TRASH_DIRECTORY"
1056
case "$TRASH_DIRECTORY" in
1057
/*) ;; # absolute path is good