All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Ævar Arnfjörð Bjarmason" <avarab@gmail.com>
To: git@vger.kernel.org
Cc: "Junio C Hamano" <gitster@pobox.com>, "Jeff King" <peff@peff.net>,
	"Felipe Contreras" <felipe.contreras@gmail.com>,
	"Adam Spiers" <git@adamspiers.org>,
	"Thomas Rast" <tr@thomasrast.ch>,
	"Ilya Bobyr" <ilya.bobyr@gmail.com>,
	"Patrick Steinhardt" <ps@pks.im>,
	"Ævar Arnfjörð Bjarmason" <avarab@gmail.com>
Subject: [PATCH v3 1/9] test-lib tests: move "run_sub_test" to a new lib-subtest.sh
Date: Thu,  5 Aug 2021 12:37:20 +0200	[thread overview]
Message-ID: <patch-v3-1.9-3f34420a3e-20210805T103237Z-avarab@gmail.com> (raw)
In-Reply-To: <cover-v3-0.9-0000000000-20210805T103237Z-avarab@gmail.com>

Move the "check_sub_test_lib_test()" and its sister functions to a new
lib-subtest.sh.

In the future (not in this series) I'd like to test test-lib's output
in a more targeted and smaller test, and I'll need these functions to
do that.

Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
---
 t/lib-subtest.sh | 86 ++++++++++++++++++++++++++++++++++++++++++++++
 t/t0000-basic.sh | 88 +-----------------------------------------------
 2 files changed, 87 insertions(+), 87 deletions(-)
 create mode 100644 t/lib-subtest.sh

diff --git a/t/lib-subtest.sh b/t/lib-subtest.sh
new file mode 100644
index 0000000000..3cfe09911a
--- /dev/null
+++ b/t/lib-subtest.sh
@@ -0,0 +1,86 @@
+_run_sub_test_lib_test_common () {
+	neg="$1" name="$2" descr="$3" # stdin is the body of the test code
+	shift 3
+
+	# intercept pseudo-options at the front of the argument list that we
+	# will not pass to child script
+	skip=
+	while test $# -gt 0
+	do
+		case "$1" in
+		--skip=*)
+			skip=${1#--*=}
+			shift
+			;;
+		*)
+			break
+			;;
+		esac
+	done
+
+	mkdir "$name" &&
+	(
+		# Pretend we're not running under a test harness, whether we
+		# are or not. The test-lib output depends on the setting of
+		# this variable, so we need a stable setting under which to run
+		# the sub-test.
+		sane_unset HARNESS_ACTIVE &&
+		cd "$name" &&
+		write_script "$name.sh" "$TEST_SHELL_PATH" <<-EOF &&
+		test_description='$descr (run in sub test-lib)
+
+		This is run in a sub test-lib so that we do not get incorrect
+		passing metrics
+		'
+
+		# Point to the t/test-lib.sh, which isn't in ../ as usual
+		. "\$TEST_DIRECTORY"/test-lib.sh
+		EOF
+		cat >>"$name.sh" &&
+		export TEST_DIRECTORY &&
+		# The child test re-sources GIT-BUILD-OPTIONS and may thus
+		# override the test output directory. We thus pass it as an
+		# explicit override to the child.
+		TEST_OUTPUT_DIRECTORY_OVERRIDE=$(pwd) &&
+		export TEST_OUTPUT_DIRECTORY_OVERRIDE &&
+		GIT_SKIP_TESTS=$skip &&
+		export GIT_SKIP_TESTS &&
+		sane_unset GIT_TEST_FAIL_PREREQS &&
+		if test -z "$neg"
+		then
+			./"$name.sh" "$@" >out 2>err
+		else
+			! ./"$name.sh" "$@" >out 2>err
+		fi
+	)
+}
+
+run_sub_test_lib_test () {
+	_run_sub_test_lib_test_common '' "$@"
+}
+
+run_sub_test_lib_test_err () {
+	_run_sub_test_lib_test_common '!' "$@"
+}
+
+check_sub_test_lib_test () {
+	name="$1" # stdin is the expected output from the test
+	(
+		cd "$name" &&
+		test_must_be_empty err &&
+		sed -e 's/^> //' -e 's/Z$//' >expect &&
+		test_cmp expect out
+	)
+}
+
+check_sub_test_lib_test_err () {
+	name="$1" # stdin is the expected output from the test
+	# expected error output is in descriptor 3
+	(
+		cd "$name" &&
+		sed -e 's/^> //' -e 's/Z$//' >expect.out &&
+		test_cmp expect.out out &&
+		sed -e 's/^> //' -e 's/Z$//' <&3 >expect.err &&
+		test_cmp expect.err err
+	)
+}
diff --git a/t/t0000-basic.sh b/t/t0000-basic.sh
index cb87768513..a3865dd77b 100755
--- a/t/t0000-basic.sh
+++ b/t/t0000-basic.sh
@@ -19,6 +19,7 @@ modification *should* take notice and update the test vectors here.
 '
 
 . ./test-lib.sh
+. "$TEST_DIRECTORY"/lib-subtest.sh
 
 try_local_xy () {
 	local x="local" y="alsolocal" &&
@@ -66,93 +67,6 @@ test_expect_success 'success is reported like this' '
 	:
 '
 
-_run_sub_test_lib_test_common () {
-	neg="$1" name="$2" descr="$3" # stdin is the body of the test code
-	shift 3
-
-	# intercept pseudo-options at the front of the argument list that we
-	# will not pass to child script
-	skip=
-	while test $# -gt 0
-	do
-		case "$1" in
-		--skip=*)
-			skip=${1#--*=}
-			shift
-			;;
-		*)
-			break
-			;;
-		esac
-	done
-
-	mkdir "$name" &&
-	(
-		# Pretend we're not running under a test harness, whether we
-		# are or not. The test-lib output depends on the setting of
-		# this variable, so we need a stable setting under which to run
-		# the sub-test.
-		sane_unset HARNESS_ACTIVE &&
-		cd "$name" &&
-		write_script "$name.sh" "$TEST_SHELL_PATH" <<-EOF &&
-		test_description='$descr (run in sub test-lib)
-
-		This is run in a sub test-lib so that we do not get incorrect
-		passing metrics
-		'
-
-		# Point to the t/test-lib.sh, which isn't in ../ as usual
-		. "\$TEST_DIRECTORY"/test-lib.sh
-		EOF
-		cat >>"$name.sh" &&
-		export TEST_DIRECTORY &&
-		# The child test re-sources GIT-BUILD-OPTIONS and may thus
-		# override the test output directory. We thus pass it as an
-		# explicit override to the child.
-		TEST_OUTPUT_DIRECTORY_OVERRIDE=$(pwd) &&
-		export TEST_OUTPUT_DIRECTORY_OVERRIDE &&
-		GIT_SKIP_TESTS=$skip &&
-		export GIT_SKIP_TESTS &&
-		sane_unset GIT_TEST_FAIL_PREREQS &&
-		if test -z "$neg"
-		then
-			./"$name.sh" "$@" >out 2>err
-		else
-			! ./"$name.sh" "$@" >out 2>err
-		fi
-	)
-}
-
-run_sub_test_lib_test () {
-	_run_sub_test_lib_test_common '' "$@"
-}
-
-run_sub_test_lib_test_err () {
-	_run_sub_test_lib_test_common '!' "$@"
-}
-
-check_sub_test_lib_test () {
-	name="$1" # stdin is the expected output from the test
-	(
-		cd "$name" &&
-		test_must_be_empty err &&
-		sed -e 's/^> //' -e 's/Z$//' >expect &&
-		test_cmp expect out
-	)
-}
-
-check_sub_test_lib_test_err () {
-	name="$1" # stdin is the expected output from the test
-	# expected error output is in descriptor 3
-	(
-		cd "$name" &&
-		sed -e 's/^> //' -e 's/Z$//' >expect.out &&
-		test_cmp expect.out out &&
-		sed -e 's/^> //' -e 's/Z$//' <&3 >expect.err &&
-		test_cmp expect.err err
-	)
-}
-
 test_expect_success 'pretend we have a fully passing test suite' '
 	run_sub_test_lib_test full-pass "3 passing tests" <<-\EOF &&
 	for i in 1 2 3
-- 
2.33.0.rc0.635.g0ab9d6d3b5a


  reply	other threads:[~2021-08-05 10:37 UTC|newest]

Thread overview: 44+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-06-14 10:48 [PATCH 0/8] test-lib tests: split off subtest code in t0000 into lib-subtest.sh Ævar Arnfjörð Bjarmason
2021-06-14 10:48 ` [PATCH 1/8] test-lib tests: move "run_sub_test" to a new lib-subtest.sh Ævar Arnfjörð Bjarmason
2021-06-14 10:48 ` [PATCH 2/8] test-lib tests: split up "write and run" into two functions Ævar Arnfjörð Bjarmason
2021-06-14 10:48 ` [PATCH 3/8] test-lib tests: stop using a subshell in write_sub_test_lib_test() Ævar Arnfjörð Bjarmason
2021-06-14 10:48 ` [PATCH 4/8] test-lib tests: don't provide a description for the sub-tests Ævar Arnfjörð Bjarmason
2021-06-14 10:48 ` [PATCH 5/8] test-lib tests: get rid of copy/pasted mock test code Ævar Arnfjörð Bjarmason
2021-06-14 10:48 ` [PATCH 6/8] test-lib tests: avoid subshell for "test_cmp" for readability Ævar Arnfjörð Bjarmason
2021-06-14 10:48 ` [PATCH 7/8] test-lib tests: refactor common part of check_sub_test_lib_test*() Ævar Arnfjörð Bjarmason
2021-06-14 10:48 ` [PATCH 8/8] test-lib tests: assert 1 exit code, not non-zero Ævar Arnfjörð Bjarmason
2021-06-15  2:24 ` [PATCH 0/8] test-lib tests: split off subtest code in t0000 into lib-subtest.sh Junio C Hamano
2021-06-24 10:38   ` Ævar Arnfjörð Bjarmason
2021-06-30  7:04     ` Ævar Arnfjörð Bjarmason
2021-07-01 14:30       ` Junio C Hamano
2021-06-15 18:05 ` Felipe Contreras
2021-07-21 22:57 ` [PATCH v2 " Ævar Arnfjörð Bjarmason
2021-07-21 22:57   ` [PATCH v2 1/8] test-lib tests: move "run_sub_test" to a new lib-subtest.sh Ævar Arnfjörð Bjarmason
2021-07-21 22:57   ` [PATCH v2 2/8] test-lib tests: split up "write and run" into two functions Ævar Arnfjörð Bjarmason
2021-07-21 22:57   ` [PATCH v2 3/8] test-lib tests: stop using a subshell in write_sub_test_lib_test() Ævar Arnfjörð Bjarmason
2021-07-21 22:57   ` [PATCH v2 4/8] test-lib tests: don't provide a description for the sub-tests Ævar Arnfjörð Bjarmason
2021-07-21 22:57   ` [PATCH v2 5/8] test-lib tests: get rid of copy/pasted mock test code Ævar Arnfjörð Bjarmason
2021-07-21 22:57   ` [PATCH v2 6/8] test-lib tests: avoid subshell for "test_cmp" for readability Ævar Arnfjörð Bjarmason
2021-07-21 22:57   ` [PATCH v2 7/8] test-lib tests: refactor common part of check_sub_test_lib_test*() Ævar Arnfjörð Bjarmason
2021-07-21 22:57   ` [PATCH v2 8/8] test-lib tests: assert 1 exit code, not non-zero Ævar Arnfjörð Bjarmason
2021-07-21 23:23   ` [PATCH v2 0/8] test-lib tests: split off subtest code in t0000 into lib-subtest.sh Junio C Hamano
2021-08-05 10:37   ` [PATCH v3 0/9] " Ævar Arnfjörð Bjarmason
2021-08-05 10:37     ` Ævar Arnfjörð Bjarmason [this message]
2021-08-05 10:37     ` [PATCH v3 2/9] test-lib tests: split up "write and run" into two functions Ævar Arnfjörð Bjarmason
2021-08-05 10:37     ` [PATCH v3 3/9] test-lib tests: stop using a subshell in write_sub_test_lib_test() Ævar Arnfjörð Bjarmason
2021-09-22  7:54       ` Carlo Arenas
2021-08-05 10:37     ` [PATCH v3 4/9] test-lib tests: don't provide a description for the sub-tests Ævar Arnfjörð Bjarmason
2021-08-05 10:37     ` [PATCH v3 5/9] test-lib tests: get rid of copy/pasted mock test code Ævar Arnfjörð Bjarmason
2021-08-05 10:37     ` [PATCH v3 6/9] test-lib tests: assert no " Ævar Arnfjörð Bjarmason
2021-08-05 10:37     ` [PATCH v3 7/9] test-lib tests: avoid subshell for "test_cmp" for readability Ævar Arnfjörð Bjarmason
2021-08-05 10:37     ` [PATCH v3 8/9] test-lib tests: refactor common part of check_sub_test_lib_test*() Ævar Arnfjörð Bjarmason
2021-08-05 10:37     ` [PATCH v3 9/9] test-lib tests: assert 1 exit code, not non-zero Ævar Arnfjörð Bjarmason
2021-09-22  8:33     ` [PATCH v3 0/9] test-lib tests: split off subtest code in t0000 into lib-subtest.sh Carlo Arenas
2021-09-22 11:19     ` [PATCH v4 0/7] " Ævar Arnfjörð Bjarmason
2021-09-22 11:19       ` [PATCH v4 1/7] test-lib tests: move "run_sub_test" to a new lib-subtest.sh Ævar Arnfjörð Bjarmason
2021-09-22 11:19       ` [PATCH v4 2/7] test-lib tests: split up "write and run" into two functions Ævar Arnfjörð Bjarmason
2021-09-22 11:19       ` [PATCH v4 3/7] test-lib tests: don't provide a description for the sub-tests Ævar Arnfjörð Bjarmason
2021-09-22 11:19       ` [PATCH v4 4/7] test-lib tests: avoid subshell for "test_cmp" for readability Ævar Arnfjörð Bjarmason
2021-09-22 11:19       ` [PATCH v4 5/7] test-lib tests: refactor common part of check_sub_test_lib_test*() Ævar Arnfjörð Bjarmason
2021-09-22 11:19       ` [PATCH v4 6/7] test-lib tests: assert 1 exit code, not non-zero Ævar Arnfjörð Bjarmason
2021-09-22 11:19       ` [PATCH v4 7/7] test-lib tests: get rid of copy/pasted mock test code Ævar Arnfjörð Bjarmason

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=patch-v3-1.9-3f34420a3e-20210805T103237Z-avarab@gmail.com \
    --to=avarab@gmail.com \
    --cc=felipe.contreras@gmail.com \
    --cc=git@adamspiers.org \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=ilya.bobyr@gmail.com \
    --cc=peff@peff.net \
    --cc=ps@pks.im \
    --cc=tr@thomasrast.ch \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.