Skip to content

Commit 62c379b

Browse files
szedergitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 8cf5800 commit 62c379b

File tree

1 file changed

+11
-11
lines changed

1 file changed

+11
-11
lines changed

t/test-lib.sh

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -160,28 +160,31 @@ then
160160
test -z "$verbose_log" && verbose=t
161161
fi
162162

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+
163167
# if --tee was passed, write the output not only to the terminal, but
164168
# additionally to the file test-results/$BASENAME.out, too.
165169
if test "$GIT_TEST_TEE_STARTED" = "done"
166170
then
167171
: # do not redirect again
168172
elif test -n "$tee"
169173
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"
172175

173176
# Make this filename available to the sub-process in case it is using
174177
# --verbose-log.
175-
GIT_TEST_TEE_OUTPUT_FILE=$BASE.out
178+
GIT_TEST_TEE_OUTPUT_FILE=$TEST_RESULTS_BASE.out
176179
export GIT_TEST_TEE_OUTPUT_FILE
177180

178181
# Truncate before calling "tee -a" to get rid of the results
179182
# from any previous runs.
180183
>"$GIT_TEST_TEE_OUTPUT_FILE"
181184

182185
(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
185188
exit
186189
fi
187190

@@ -840,12 +843,9 @@ test_done () {
840843

841844
if test -z "$HARNESS_ACTIVE"
842845
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"
847847

848-
cat >"$test_results_path" <<-EOF
848+
cat >"$TEST_RESULTS_BASE.counts" <<-EOF
849849
total $test_count
850850
success $test_success
851851
fixed $test_fixed
@@ -1051,7 +1051,7 @@ then
10511051
fi
10521052

10531053
# Test repository
1054-
TRASH_DIRECTORY="trash directory.$(basename "$0" .sh)"
1054+
TRASH_DIRECTORY="trash directory.$TEST_NAME"
10551055
test -n "$root" && TRASH_DIRECTORY="$root/$TRASH_DIRECTORY"
10561056
case "$TRASH_DIRECTORY" in
10571057
/*) ;; # absolute path is good

0 commit comments

Comments
 (0)