]> git.ipfire.org Git - thirdparty/git.git/commitdiff
tests: make sure nested lazy prereqs work reliably
authorSZEDER Gábor <szeder.dev@gmail.com>
Wed, 18 Nov 2020 19:04:13 +0000 (20:04 +0100)
committerJunio C Hamano <gitster@pobox.com>
Wed, 18 Nov 2020 20:38:18 +0000 (12:38 -0800)
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 <szeder.dev@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
t/t0000-basic.sh
t/test-lib-functions.sh

index 923281af93981d5b6f67ace54f41849b44ecf0b1..4031a0e3fc53b0f5d2c77e959ba40bd2d3f09b7f 100755 (executable)
@@ -831,6 +831,27 @@ then
        exit 1
 fi
 
+test_lazy_prereq NESTED_INNER '
+       >inner &&
+       rm -f outer
+'
+test_lazy_prereq NESTED_PREREQ '
+       >outer &&
+       test_have_prereq NESTED_INNER &&
+       echo "can create new file in cwd" >file &&
+       test -f outer &&
+       test ! -f inner
+'
+test_expect_success NESTED_PREREQ 'evaluating nested lazy prereqs dont interfere with each other' '
+       nestedworks=yes
+'
+
+if test -z "$GIT_TEST_FAIL_PREREQS_INTERNAL" && test "$nestedworks" != yes
+then
+       say 'bug in test framework: nested lazy prerequisites do not work'
+       exit 1
+fi
+
 test_expect_success 'lazy prereqs do not turn off tracing' "
        run_sub_test_lib_test lazy-prereq-and-tracing \
                'lazy prereqs and -x' -v -x <<-\\EOF &&
index 8d59b90348ea898ca983e8bbd0742de495a8d36d..94395b9807bf0c8369aeaf433120ae4c5d3d0431 100644 (file)
@@ -474,15 +474,15 @@ test_lazy_prereq () {
 
 test_run_lazy_prereq_ () {
        script='
-mkdir -p "$TRASH_DIRECTORY/prereq-test-dir" &&
+mkdir -p "$TRASH_DIRECTORY/prereq-test-dir-'"$1"'" &&
 (
-       cd "$TRASH_DIRECTORY/prereq-test-dir" &&'"$2"'
+       cd "$TRASH_DIRECTORY/prereq-test-dir-'"$1"'" &&'"$2"'
 )'
        say >&3 "checking prerequisite: $1"
        say >&3 "$script"
        test_eval_ "$script"
        eval_ret=$?
-       rm -rf "$TRASH_DIRECTORY/prereq-test-dir"
+       rm -rf "$TRASH_DIRECTORY/prereq-test-dir-$1"
        if test "$eval_ret" = 0; then
                say >&3 "prerequisite $1 ok"
        else