git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / 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>,
	"Ævar Arnfjörð Bjarmason" <avarab@gmail.com>
Subject: [PATCH 6/8] test-lib tests: avoid subshell for "test_cmp" for readability
Date: Mon, 14 Jun 2021 12:48:12 +0200	[thread overview]
Message-ID: <patch-6.8-2f717e437e6-20210614T104351Z-avarab@gmail.com> (raw)
In-Reply-To: <cover-0.8-00000000000-20210614T104351Z-avarab@gmail.com>

The use of a sub-shell for running the test_cmp of stdout/stderr for
the test author was introduced in this form in 565b6fa87bb (tests:
refactor mechanics of testing in a sub test-lib, 2012-12-16), but from
looking at the history that seemed to have diligently copied my
original ad-hoc implementation in 7b905119703 (t/t0000-basic.sh: Run
the passing TODO test inside its own test-lib, 2010-08-19).

There's no reason to use a subshell here, we try to avoid it in
general. It also improves readability, if the test fails we print out
the relative path in the trash directory that needs to be looked
at.

Before that was mostly obscured, since the "write_sub_test_lib_test"
will pick the directory for you from the test name.

Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
---
 t/lib-subtest.sh | 20 +++++++-------------
 1 file changed, 7 insertions(+), 13 deletions(-)

diff --git a/t/lib-subtest.sh b/t/lib-subtest.sh
index 4834db6c4ca..8f4935faf43 100644
--- a/t/lib-subtest.sh
+++ b/t/lib-subtest.sh
@@ -89,22 +89,16 @@ run_sub_test_lib_test_err () {
 
 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
-	)
+	test_must_be_empty "$name"/err &&
+	sed -e 's/^> //' -e 's/Z$//' >"$name"/expect &&
+	test_cmp "$name/"expect "$name"/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
-	)
+	sed -e 's/^> //' -e 's/Z$//' >"$name"/expect.out &&
+	test_cmp "$name"/expect.out "$name"/out &&
+	sed -e 's/^> //' -e 's/Z$//' <&3 >"$name"/expect.err &&
+	test_cmp "$name"/expect.err "$name"/err
 }
-- 
2.32.0.rc3.434.gd8aed1f08a7


  parent reply	other threads:[~2021-06-14 11:00 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 ` Ævar Arnfjörð Bjarmason [this message]
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     ` [PATCH v3 1/9] test-lib tests: move "run_sub_test" to a new lib-subtest.sh Ævar Arnfjörð Bjarmason
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

  List information: http://vger.kernel.org/majordomo-info.html

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

  git send-email \
    --in-reply-to=patch-6.8-2f717e437e6-20210614T104351Z-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=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.
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).