git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
* [PATCH 1/2] tests: make sure nested lazy prereqs work reliably
@ 2020-11-18 19:04 SZEDER Gábor
  2020-11-18 19:04 ` [PATCH 2/2] tests: fix description of 'test_set_prereq' SZEDER Gábor
                   ` (2 more replies)
  0 siblings, 3 replies; 14+ messages in thread
From: SZEDER Gábor @ 2020-11-18 19:04 UTC (permalink / raw)
  To: git; +Cc: Junio C Hamano, Johannes Schindelin, Jeff King, SZEDER Gábor

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>
---

This came up while looking into:

  https://public-inbox.org/git/nycvar.QRO.7.76.6.2011152252520.18437@tvgsbejvaqbjf.bet/

because this did become an issue when I made the JGIT prereq depend on
SHA1.

 t/t0000-basic.sh        | 21 +++++++++++++++++++++
 t/test-lib-functions.sh |  6 +++---
 2 files changed, 24 insertions(+), 3 deletions(-)

diff --git a/t/t0000-basic.sh b/t/t0000-basic.sh
index 923281af93..4031a0e3fc 100755
--- a/t/t0000-basic.sh
+++ b/t/t0000-basic.sh
@@ -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 &&
diff --git a/t/test-lib-functions.sh b/t/test-lib-functions.sh
index 8d59b90348..94395b9807 100644
--- a/t/test-lib-functions.sh
+++ b/t/test-lib-functions.sh
@@ -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
-- 
2.29.2.612.g41c40d3f73


^ permalink raw reply related	[flat|nested] 14+ messages in thread
* [PATCH 0/4] t0000 cleanups
@ 2021-01-28  6:32 Jeff King
  2021-01-28  6:32 ` [PATCH 2/4] t0000: run prereq tests inside sub-test Jeff King
  0 siblings, 1 reply; 14+ messages in thread
From: Jeff King @ 2021-01-28  6:32 UTC (permalink / raw)
  To: git

This is a re-send of some cleanups from:

  https://lore.kernel.org/git/20201120001458.GA274082@coredump.intra.peff.net/

There were some textual conflicts back then which would have been
tedious to resolve, so we punted. Now that the requisite commits are all
in master, this can be applied there without any conflicts.

  [1/4]: t0000: keep clean-up tests together
  [2/4]: t0000: run prereq tests inside sub-test
  [3/4]: t0000: run cleaning test inside sub-test
  [4/4]: t0000: consistently use single quotes for outer tests

 t/t0000-basic.sh | 570 +++++++++++++++++++++++------------------------
 1 file changed, 284 insertions(+), 286 deletions(-)

-Peff

^ permalink raw reply	[flat|nested] 14+ messages in thread

end of thread, other threads:[~2021-01-28  6:34 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-11-18 19:04 [PATCH 1/2] tests: make sure nested lazy prereqs work reliably SZEDER Gábor
2020-11-18 19:04 ` [PATCH 2/2] tests: fix description of 'test_set_prereq' SZEDER Gábor
2020-11-18 20:00 ` [PATCH 1/2] tests: make sure nested lazy prereqs work reliably Junio C Hamano
2020-11-19 15:58 ` Jeff King
2020-11-19 17:56   ` Jeff King
2020-11-19 19:50     ` Junio C Hamano
2020-11-20  0:14       ` Jeff King
2020-11-20  0:17         ` [PATCH 1/4] t0000: keep clean-up tests together Jeff King
2020-11-20  0:20         ` [PATCH 2/4] t0000: run prereq tests inside sub-test Jeff King
2020-11-20  0:22         ` [PATCH 3/4] t0000: run cleaning test " Jeff King
2020-11-20  0:27         ` [PATCH 4/4] t0000: consistently use single quotes for outer tests Jeff King
2020-11-20  1:32         ` [PATCH 1/2] tests: make sure nested lazy prereqs work reliably Junio C Hamano
2020-11-20  0:07   ` Junio C Hamano
  -- strict thread matches above, loose matches on Subject: below --
2021-01-28  6:32 [PATCH 0/4] t0000 cleanups Jeff King
2021-01-28  6:32 ` [PATCH 2/4] t0000: run prereq tests inside sub-test Jeff King

Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).