git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH v2 7/8] test-lib tests: refactor common part of check_sub_test_lib_test*()

From
Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Date
Jul 21, 2021, 22:57 UTC
Message-ID
<patch-7.8-ae0226e164c-20210721T225504Z-avarab@gmail.com>
In-Reply-To
<cover-0.8-00000000000-20210721T225504Z-avarab@gmail.com>

Refactor the two check_sub_test_lib_test*() functions to avoid duplicating the same comparison they did of stdout. This duplication was initially added when check_sub_test_lib_test_err() was added in 0445e6f0a12 (test-lib: '--run' to run only specific tests, 2014-04-30).

Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
---
 t/lib-subtest.sh | 14 +++++++++-----
 1 file changed, 9 insertions(+), 5 deletions(-)
diff --git a/t/lib-subtest.sh b/t/lib-subtest.sh
index 96a4e6e259a..2fde75e8863 100644
--- a/t/lib-subtest.sh
+++ b/t/lib-subtest.sh
@@ -109,18 +109,22 @@ run_sub_test_lib_test_err () {
 	_run_sub_test_lib_test_common '!' "$@"
 }
 
+_check_sub_test_lib_test_common () {
+	name="$1" &&
+	sed -e 's/^> //' -e 's/Z$//' >"$name"/expect.out &&
+	test_cmp "$name"/expect.out "$name"/out
+}
+
 check_sub_test_lib_test () {
 	name="$1" # stdin is the expected output from the test
-	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_common "$name" &&
+	test_must_be_empty "$name"/err
 }
 
 check_sub_test_lib_test_err () {
 	name="$1" # stdin is the expected output from the test
+	_check_sub_test_lib_test_common "$name" &&
 	# expected error output is in descriptor 3
-	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.955.ge7c5360f7e7
Previous: Ævar Arnfjörð BjarmasonNext: Ævar Arnfjörð Bjarmason
Message 22 of 44 in “test-lib tests: split off subtest code in t0000 into lib-subtest.sh”
  1. 0/8 test-lib tests: split off subtest code in t0000 into lib-subtest.shÆvar Arnfjörð Bjarmason, Jun 14, 2021
  2. 5/8 test-lib tests: get rid of copy/pasted mock test codeÆvar Arnfjörð Bjarmason, Jun 14, 2021
  3. 8/8 test-lib tests: assert 1 exit code, not non-zeroÆvar Arnfjörð Bjarmason, Jun 14, 2021
  4. 4/8 test-lib tests: don't provide a description for the sub-testsÆvar Arnfjörð Bjarmason, Jun 14, 2021
  5. 1/8 test-lib tests: move "run_sub_test" to a new lib-subtest.shÆvar Arnfjörð Bjarmason, Jun 14, 2021
  6. 3/8 test-lib tests: stop using a subshell in write_sub_test_lib_test()Ævar Arnfjörð Bjarmason, Jun 14, 2021
  7. 6/8 test-lib tests: avoid subshell for "test_cmp" for readabilityÆvar Arnfjörð Bjarmason, Jun 14, 2021
  8. 7/8 test-lib tests: refactor common part of check_sub_test_lib_test*()Ævar Arnfjörð Bjarmason, Jun 14, 2021
  9. 2/8 test-lib tests: split up "write and run" into two functionsÆvar Arnfjörð Bjarmason, Jun 14, 2021
  10. Junio C HamanoJun 15, 2021
  11. Ævar Arnfjörð BjarmasonJun 24, 2021
  12. Ævar Arnfjörð BjarmasonJun 30, 2021
  13. Junio C HamanoJul 1, 2021
  14. Felipe ContrerasJun 15, 2021
  15. 0/8 test-lib tests: split off subtest code in t0000 into lib-subtest.shÆvar Arnfjörð Bjarmason, Jul 21, 2021
  16. 1/8 test-lib tests: move "run_sub_test" to a new lib-subtest.shÆvar Arnfjörð Bjarmason, Jul 21, 2021
  17. 2/8 test-lib tests: split up "write and run" into two functionsÆvar Arnfjörð Bjarmason, Jul 21, 2021
  18. 5/8 test-lib tests: get rid of copy/pasted mock test codeÆvar Arnfjörð Bjarmason, Jul 21, 2021
  19. 4/8 test-lib tests: don't provide a description for the sub-testsÆvar Arnfjörð Bjarmason, Jul 21, 2021
  20. 3/8 test-lib tests: stop using a subshell in write_sub_test_lib_test()Ævar Arnfjörð Bjarmason, Jul 21, 2021
  21. 6/8 test-lib tests: avoid subshell for "test_cmp" for readabilityÆvar Arnfjörð Bjarmason, Jul 21, 2021
  22. 7/8 test-lib tests: refactor common part of check_sub_test_lib_test*()Ævar Arnfjörð Bjarmason, Jul 21, 2021
  23. 8/8 test-lib tests: assert 1 exit code, not non-zeroÆvar Arnfjörð Bjarmason, Jul 21, 2021
  24. Junio C HamanoJul 21, 2021
  25. 0/9 test-lib tests: split off subtest code in t0000 into lib-subtest.shÆvar Arnfjörð Bjarmason, Aug 5, 2021
  26. 1/9 test-lib tests: move "run_sub_test" to a new lib-subtest.shÆvar Arnfjörð Bjarmason, Aug 5, 2021
  27. 2/9 test-lib tests: split up "write and run" into two functionsÆvar Arnfjörð Bjarmason, Aug 5, 2021
  28. 3/9 test-lib tests: stop using a subshell in write_sub_test_lib_test()Ævar Arnfjörð Bjarmason, Aug 5, 2021
  29. Carlo ArenasSep 22, 2021
  30. 5/9 test-lib tests: get rid of copy/pasted mock test codeÆvar Arnfjörð Bjarmason, Aug 5, 2021
  31. 4/9 test-lib tests: don't provide a description for the sub-testsÆvar Arnfjörð Bjarmason, Aug 5, 2021
  32. 6/9 test-lib tests: assert no copy/pasted mock test codeÆvar Arnfjörð Bjarmason, Aug 5, 2021
  33. 7/9 test-lib tests: avoid subshell for "test_cmp" for readabilityÆvar Arnfjörð Bjarmason, Aug 5, 2021
  34. 8/9 test-lib tests: refactor common part of check_sub_test_lib_test*()Ævar Arnfjörð Bjarmason, Aug 5, 2021
  35. 9/9 test-lib tests: assert 1 exit code, not non-zeroÆvar Arnfjörð Bjarmason, Aug 5, 2021
  36. Carlo ArenasSep 22, 2021
  37. 0/7 test-lib tests: split off subtest code in t0000 into lib-subtest.shÆvar Arnfjörð Bjarmason, Sep 22, 2021
  38. 1/7 test-lib tests: move "run_sub_test" to a new lib-subtest.shÆvar Arnfjörð Bjarmason, Sep 22, 2021
  39. 2/7 test-lib tests: split up "write and run" into two functionsÆvar Arnfjörð Bjarmason, Sep 22, 2021
  40. 3/7 test-lib tests: don't provide a description for the sub-testsÆvar Arnfjörð Bjarmason, Sep 22, 2021
  41. 4/7 test-lib tests: avoid subshell for "test_cmp" for readabilityÆvar Arnfjörð Bjarmason, Sep 22, 2021
  42. 5/7 test-lib tests: refactor common part of check_sub_test_lib_test*()Ævar Arnfjörð Bjarmason, Sep 22, 2021
  43. 6/7 test-lib tests: assert 1 exit code, not non-zeroÆvar Arnfjörð Bjarmason, Sep 22, 2021
  44. 7/7 test-lib tests: get rid of copy/pasted mock test codeÆvar Arnfjörð Bjarmason, Sep 22, 2021

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.