Skip to content

Commit 53ff3b9

Browse files
szedergitster
authored andcommitted
tests: make sure nested lazy prereqs work reliably
Some test prereqs depend on other prereqs, so in a couple of cases we have nested prereqs that look something like this: test_lazy_prereq FOO ' test_have_prereq BAR && check-foo ' This can be problematic, because lazy prereqs are evaluated in the '$TRASH_DIRECTORY/prereq-test-dir' directory, which is the same for every prereq, and which is automatically removed after the prereq has been evaluated. So if the inner prereq (BAR above) is a lazy prereq that hasn't been evaluated yet, then after its evaluation the 'prereq-test-dir' shared with the outer prereq will be removed. Consequently, 'check-foo' will find itself in a non-existing directory, and won't be able to create/access any files in its cwd, which could result in an unfulfilled outer prereq. Luckily, this doesn't affect any of our current nested prereqs, either because the inner prereq is not a lazy prereq (e.g. MINGW, CYGWIN or PERL), or because the outer prereq happens to be checked without touching any paths in its cwd (GPGSM and RFC1991 in 'lib-gpg.sh'). So to prevent nested prereqs from interfering with each other let's evaluate each prereq in its own dedicated directory by appending the prereq's name to the directory name, e.g. 'prereq-test-dir-SYMLINKS'. In the test we check not only that the prereq test dir is still there, but also that the inner prereq can't mess with the outer prereq's files. Signed-off-by: SZEDER Gábor <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 898f807 commit 53ff3b9

File tree

2 files changed

+24
-3
lines changed

2 files changed

+24
-3
lines changed

t/t0000-basic.sh

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -831,6 +831,27 @@ then
831831
exit 1
832832
fi
833833

834+
test_lazy_prereq NESTED_INNER '
835+
>inner &&
836+
rm -f outer
837+
'
838+
test_lazy_prereq NESTED_PREREQ '
839+
>outer &&
840+
test_have_prereq NESTED_INNER &&
841+
echo "can create new file in cwd" >file &&
842+
test -f outer &&
843+
test ! -f inner
844+
'
845+
test_expect_success NESTED_PREREQ 'evaluating nested lazy prereqs dont interfere with each other' '
846+
nestedworks=yes
847+
'
848+
849+
if test -z "$GIT_TEST_FAIL_PREREQS_INTERNAL" && test "$nestedworks" != yes
850+
then
851+
say 'bug in test framework: nested lazy prerequisites do not work'
852+
exit 1
853+
fi
854+
834855
test_expect_success 'lazy prereqs do not turn off tracing' "
835856
run_sub_test_lib_test lazy-prereq-and-tracing \
836857
'lazy prereqs and -x' -v -x <<-\\EOF &&

t/test-lib-functions.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -474,15 +474,15 @@ test_lazy_prereq () {
474474

475475
test_run_lazy_prereq_ () {
476476
script='
477-
mkdir -p "$TRASH_DIRECTORY/prereq-test-dir" &&
477+
mkdir -p "$TRASH_DIRECTORY/prereq-test-dir-'"$1"'" &&
478478
(
479-
cd "$TRASH_DIRECTORY/prereq-test-dir" &&'"$2"'
479+
cd "$TRASH_DIRECTORY/prereq-test-dir-'"$1"'" &&'"$2"'
480480
)'
481481
say >&3 "checking prerequisite: $1"
482482
say >&3 "$script"
483483
test_eval_ "$script"
484484
eval_ret=$?
485-
rm -rf "$TRASH_DIRECTORY/prereq-test-dir"
485+
rm -rf "$TRASH_DIRECTORY/prereq-test-dir-$1"
486486
if test "$eval_ret" = 0; then
487487
say >&3 "prerequisite $1 ok"
488488
else

0 commit comments

Comments
 (0)