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

[PATCH v4 0/7] test-lib tests: split off subtest code in t0000 into lib-subtest.sh

From
Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Date
Sep 22, 2021, 11:19 UTC
Message-ID
<cover-v4-0.7-00000000000-20210922T111734Z-avarab@gmail.com>
In-Reply-To
<cover-v3-0.9-0000000000-20210805T103237Z-avarab@gmail.com>

A re-roll of v3[1] of this cleanup/refactoring of t0000-basic.sh series which addresses Carlo's comments on it, thanks for the review Carlo!

I.e. the old 3/9 is squashed into a 2/7, and the assertion of non-duplicate tests is now ejected. I left a note in 7/7 that we may want it in the future, but for now let's punt on it.

1. https://lore.kernel.org/git/cover-v3-0.9-0000000000-20210805T103237Z-avarab@gmail.com/
2. https://lore.kernel.org/git/CAPUEspg3pT1F5YMwGuwvmiyMGoYLUB0neHeunXnLxwc_G9zN-A@mail.gmail.com/
Ævar Arnfjörð Bjarmason (7):
  test-lib tests: move "run_sub_test" to a new lib-subtest.sh
  test-lib tests: split up "write and run" into two functions
  test-lib tests: don't provide a description for the sub-tests
  test-lib tests: avoid subshell for "test_cmp" for readability
  test-lib tests: refactor common part of check_sub_test_lib_test*()
  test-lib tests: assert 1 exit code, not non-zero
  test-lib tests: get rid of copy/pasted mock test code
 t/lib-subtest.sh |  95 ++++++++++
 t/t0000-basic.sh | 448 +++++++++++++----------------------------------
 2 files changed, 213 insertions(+), 330 deletions(-)
 create mode 100644 t/lib-subtest.sh
Range-diff against v3:
 1:  3f34420a3e1 =  1:  f915bc2ee77 test-lib tests: move "run_sub_test" to a new lib-subtest.sh
 2:  c9c16016da6 !  2:  5b5038867df test-lib tests: split up "write and run" into two functions
    @@ Commit message
         it possible to do so. All the changes in t0000-basic.sh are a simple
         search-replacement.
     
    +    Since the _run_sub_test_lib_test_common() function doesn't handle
    +    running the test anymore we can do away with the sub-shell, which was
    +    used to scope an "unset" and "export" shell variables.
    +
         Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
     
      ## t/lib-subtest.sh ##
    @@ t/lib-subtest.sh
     +write_sub_test_lib_test () {
     +	name="$1" descr="$2" # stdin is the body of the test code
     +	mkdir "$name" &&
    -+	(
    -+		cd "$name" &&
    -+		write_script "$name.sh" "$TEST_SHELL_PATH" <<-EOF &&
    -+		test_description='$descr (run in sub test-lib)
    ++	write_script "$name/$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
    -+		'
    ++	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"
    -+	)
    ++	# Point to the t/test-lib.sh, which isn't in ../ as usual
    ++	. "\$TEST_DIRECTORY"/test-lib.sh
    ++	EOF
    ++	cat >>"$name/$name.sh"
     +}
     +
      _run_sub_test_lib_test_common () {
    @@ t/lib-subtest.sh: _run_sub_test_lib_test_common () {
     -		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
 3:  76f57eadcdd <  -:  ----------- test-lib tests: stop using a subshell in write_sub_test_lib_test()
 4:  cde015c7dd0 =  3:  78177ce1729 test-lib tests: don't provide a description for the sub-tests
 7:  48176f3e60c =  4:  a581bff6e62 test-lib tests: avoid subshell for "test_cmp" for readability
 8:  fda7c4fbe34 =  5:  5e95484fb61 test-lib tests: refactor common part of check_sub_test_lib_test*()
 9:  dd0af5bd6ce =  6:  1e0a49c1a70 test-lib tests: assert 1 exit code, not non-zero
 5:  7d1e6b9a3e4 !  7:  68f8fabaa1e test-lib tests: get rid of copy/pasted mock test code
    @@ Commit message
         run_sub_test_lib_test*() functions let's fix those tests in
         t0000-basic.sh that were verbosely copy/pasting earlier tests.
     
    -    In a subsequent commit we'll add an assertion to check whether we
    -    caught all of the copy/pasting.
    +    That we caught all of them was asserted with a follow-up change that's
    +    not part of this series[1], we might add such a duplication check at
    +    some later time, but for now let's just one-off remove the duplicate
    +    boilerplate.
    +
    +    1. https://lore.kernel.org/git/patch-v3-6.9-bc79b29f3c-20210805T103237Z-avarab@gmail.com/
     
         Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
     
 6:  bc79b29f3cd <  -:  ----------- test-lib tests: assert no copy/pasted mock test code
-- 
2.33.0.1225.g9f062250122
Previous: Carlo ArenasNext: Ævar Arnfjörð Bjarmason
Message 37 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.