Skip to content

Commit 2d207ed

Browse files
markmentovaigitster
authored andcommitted
t: run tests from a normalized working directory
Some tests make git perform actions that produce observable pathnames, and have expectations on those paths. Tests run with $HOME set to a $TRASH_DIRECTORY, and with their working directory the same $TRASH_DIRECTORY, although these paths are logically identical, they do not observe the same pathname canonicalization rules and thus might not be represented by strings that compare equal. In particular, no pathname normalization is applied to $TRASH_DIRECTORY or $HOME, while tests change their working directory with `cd -P`, which normalizes the working directory's path by fully resolving symbolic links. t7900's macOS maintenance tests (which are not limited to running on macOS) have an expectation on a path that `git maintenance` forms by using abspath.c strbuf_realpath() to resolve a canonical absolute path based on $HOME. When t7900 runs from a working directory that contains symbolic links in its pathname, $HOME will also contain symbolic links, which `git maintenance` resolves but the test's expectation does not, causing a test failure. Align $TRASH_DIRECTORY and $HOME with the normalized path as used for the working directory by resetting them to match the working directory after it's established by `cd -P`. With all paths in agreement and symbolic links resolved, pathname expectations can be set and met based on string comparison without regard to external environmental factors such as the presence of symbolic links in a path. Suggested-by: Junio C Hamano <[email protected]> Signed-off-by: Mark Mentovai <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent d50a5e8 commit 2d207ed

File tree

1 file changed

+2
-0
lines changed

1 file changed

+2
-0
lines changed

t/test-lib.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1567,6 +1567,8 @@ fi
15671567
# Use -P to resolve symlinks in our working directory so that the cwd
15681568
# in subprocesses like git equals our $PWD (for pathname comparisons).
15691569
cd -P "$TRASH_DIRECTORY" || BAIL_OUT "cannot cd -P to \"$TRASH_DIRECTORY\""
1570+
TRASH_DIRECTORY=$(pwd)
1571+
HOME="$TRASH_DIRECTORY"
15701572

15711573
start_test_output "$0"
15721574

0 commit comments

Comments
 (0)