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

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

From
Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Date
Aug 5, 2021, 10:37 UTC
Message-ID
<cover-v3-0.9-0000000000-20210805T103237Z-avarab@gmail.com>
In-Reply-To
<cover-0.8-00000000000-20210721T225504Z-avarab@gmail.com>

This series has been looking for reviewer attention for a while. It splits up the testing of test-lib.sh itself from t0000-basic.sh into a lib-subtest.sh library, a subsequent series of mine makes use of that library.

The diffstat is nicely negative since a lot of the test code is something we could delete as redundant, the tests are also made stricter as a result (e.g. now checking 1 exit code, not any non-zero).

For v2, see: https://lore.kernel.org/git/cover-0.8-00000000000-20210721T225504Z-avarab@gmail.com/

The ony tricky part of this series is the "clever" way of (ab)using the object store and tags to detect copy/pasted tests. For this v3 I've split that up into its own commit, see [56]/9 for the removal of the copy/pasting and the assertion, respectively.

This series also depended on ps/t0000-output-directory-fix and jk/t0000-subtests-fix, since both made it mo "master" it's been rebased on "master". The range-diff that's not the split-up around [56]/9 is due to that rebasing.

Ævar Arnfjörð Bjarmason (9):
  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: stop using a subshell in write_sub_test_lib_test()
  test-lib tests: don't provide a description for the sub-tests
  test-lib tests: get rid of copy/pasted mock test code
  test-lib tests: assert no copy/pasted mock test code
  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
 t/lib-subtest.sh | 127 ++++++++++++++
 t/t0000-basic.sh | 448 +++++++++++++----------------------------------
 2 files changed, 245 insertions(+), 330 deletions(-)
 create mode 100644 t/lib-subtest.sh
Range-diff against v2:
 1:  7a06ea3a7b =  1:  3f34420a3e test-lib tests: move "run_sub_test" to a new lib-subtest.sh
 2:  28117b84ab !  2:  c9c16016da test-lib tests: split up "write and run" into two functions
    @@ t/lib-subtest.sh: _run_sub_test_lib_test_common () {
      run_sub_test_lib_test () {
      	_run_sub_test_lib_test_common '' "$@"
      }
    -@@ t/lib-subtest.sh: check_sub_test_lib_test_err () {
    - 		test_cmp expect.err err
    - 	)
    - }
    -+
     
      ## t/t0000-basic.sh ##
     @@ t/t0000-basic.sh: test_expect_success 'success is reported like this' '
 3:  7d5ed335a3 =  3:  76f57eadcd test-lib tests: stop using a subshell in write_sub_test_lib_test()
 4:  2a0dd64da9 =  4:  cde015c7dd test-lib tests: don't provide a description for the sub-tests
 5:  f60190dec6 !  5:  7d1e6b9a3e 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.
     
    -    I'm (ab)using writing a tag object under a ref-name that's
    -    content-addressable from the content of the test script. If we can
    -    update-ref that it's unique, if not we've got a duplicate. The tag
    -    object stores the name of the earlier test for reporting the error.
    +    In a subsequent commit we'll add an assertion to check whether we
    +    caught all of the copy/pasting.
     
         Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
     
    - ## t/lib-subtest.sh ##
    -@@
    -+_assert_unique_sub_test () {
    -+	name=$1 &&
    -+
    -+	# Alert about the copy/paste programming
    -+	hash=$(git hash-object -w "$name") &&
    -+	cat >tag.sig <<-EOF &&
    -+	object $hash
    -+	type blob
    -+	tag $hash
    -+	tagger . <> 0 +0000
    -+
    -+	duplicate script detected!
    -+
    -+	This test script was already written as:
    -+
    -+	$name
    -+
    -+	You can just re-use its test code with your own
    -+	run_sub_test_lib_test*()
    -+	EOF
    -+
    -+	tag=$(git mktag <tag.sig) &&
    -+	if ! git update-ref refs/tags/blob-$hash $tag $(test_oid zero) 2>/dev/null
    -+	then
    -+		msg=$(git for-each-ref refs/tags/blob-$hash \
    -+			--format='%(contents)' refs/tags/blob-$hash)
    -+		error "on write of $name: $msg"
    -+		return 1
    -+	fi
    -+}
    -+
    - write_sub_test_lib_test () {
    - 	name="$1" # stdin is the body of the test code
    - 	mkdir "$name" &&
    -@@ t/lib-subtest.sh: write_sub_test_lib_test () {
    - 	# Point to the t/test-lib.sh, which isn't in ../ as usual
    - 	. "\$TEST_DIRECTORY"/test-lib.sh
    - 	EOF
    --	cat >>"$name/$name.sh"
    -+	cat >>"$name/$name.sh" &&
    -+	_assert_unique_sub_test "$name/$name.sh"
    - }
    - 
    - _run_sub_test_lib_test_common () {
    -
      ## t/t0000-basic.sh ##
     @@ t/t0000-basic.sh: test_expect_success 'subtest: --verbose option' '
      '
 -:  ---------- >  6:  bc79b29f3c test-lib tests: assert no copy/pasted mock test code
 6:  022ddbabf6 !  7:  48176f3e60 test-lib tests: avoid subshell for "test_cmp" for readability
    @@ t/lib-subtest.sh: run_sub_test_lib_test_err () {
     +	sed -e 's/^> //' -e 's/Z$//' <&3 >"$name"/expect.err &&
     +	test_cmp "$name"/expect.err "$name"/err
      }
    - 
 7:  ae0226e164 =  8:  fda7c4fbe3 test-lib tests: refactor common part of check_sub_test_lib_test*()
 8:  676547e001 =  9:  dd0af5bd6c test-lib tests: assert 1 exit code, not non-zero
-- 
2.33.0.rc0.635.g0ab9d6d3b5a
Previous: Junio C HamanoNext: Ævar Arnfjörð Bjarmason
Message 25 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.