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

[PATCH v6 1/7] t0080: turn t-basic unit test into a helper

From
Josh Steadmon <steadmon@google.com>
Date
May 6, 2024, 19:57 UTC
Message-ID
<677745110078501e611faf3d1facd1518e0453a2.1715024899.git.steadmon@google.com>
In-Reply-To
<cover.1715024899.git.steadmon@google.com>

While t/unit-tests/t-basic.c uses the unit-test framework added in e137fe3b29 (unit tests: add TAP unit test framework, 2023-11-09), it is not a true unit test in that it intentionally fails in order to exercise various codepaths in the unit-test framework. Thus, we intentionally exclude it when running unit tests through the various t/Makefile targets. Instead, it is executed by t0080-unit-test-output.sh, which verifies its output follows the TAP format expected for the various pass, skip, or fail cases.

As such, it makes more sense for t-basic to be a helper item for t0080-unit-test-output.sh, so let's move it to t/helper/test-example-tap.c and adjust Makefiles as necessary.

Signed-off-by: Josh Steadmon <steadmon@google.com>
---
 Makefile                                      |  4 ++--
 t/Makefile                                    |  2 +-
 .../t-basic.c => helper/test-example-tap.c}   |  5 ++--
 t/helper/test-tool.c                          |  1 +
 t/helper/test-tool.h                          |  1 +
 t/t0080-unit-test-output.sh                   | 24 +++++++++----------
 6 files changed, 20 insertions(+), 17 deletions(-)
 rename t/{unit-tests/t-basic.c => helper/test-example-tap.c} (95%)
diff --git a/Makefile b/Makefile
index 23723367b8..ba55d817ee 100644
--- a/Makefile
+++ b/Makefile
@@ -802,6 +802,7 @@ TEST_BUILTINS_OBJS += test-dump-split-index.o
 TEST_BUILTINS_OBJS += test-dump-untracked-cache.o
 TEST_BUILTINS_OBJS += test-env-helper.o
 TEST_BUILTINS_OBJS += test-example-decorate.o
+TEST_BUILTINS_OBJS += test-example-tap.o
 TEST_BUILTINS_OBJS += test-find-pack.o
 TEST_BUILTINS_OBJS += test-fsmonitor-client.o
 TEST_BUILTINS_OBJS += test-genrandom.o
@@ -1338,7 +1339,6 @@ THIRD_PARTY_SOURCES += compat/regex/%
 THIRD_PARTY_SOURCES += sha1collisiondetection/%
 THIRD_PARTY_SOURCES += sha1dc/%
 
-UNIT_TEST_PROGRAMS += t-basic
 UNIT_TEST_PROGRAMS += t-mem-pool
 UNIT_TEST_PROGRAMS += t-strbuf
 UNIT_TEST_PROGRAMS += t-ctype
@@ -3218,7 +3218,7 @@ perf: all
 
 .PRECIOUS: $(TEST_OBJS)
 
-t/helper/test-tool$X: $(patsubst %,t/helper/%,$(TEST_BUILTINS_OBJS))
+t/helper/test-tool$X: $(patsubst %,t/helper/%,$(TEST_BUILTINS_OBJS)) $(UNIT_TEST_DIR)/test-lib.o
 
 t/helper/test-%$X: t/helper/test-%.o GIT-LDFLAGS $(GITLIBS) $(REFTABLE_TEST_LIB)
 	$(QUIET_LINK)$(CC) $(ALL_CFLAGS) -o $@ $(ALL_LDFLAGS) $(filter %.o,$^) $(filter %.a,$^) $(LIBS)
diff --git a/t/Makefile b/t/Makefile
index 2d95046f26..4861edafe6 100644
--- a/t/Makefile
+++ b/t/Makefile
@@ -48,7 +48,7 @@ CHAINLINTTESTS = $(sort $(patsubst chainlint/%.test,%,$(wildcard chainlint/*.tes
 CHAINLINT = '$(PERL_PATH_SQ)' chainlint.pl
 UNIT_TEST_SOURCES = $(wildcard unit-tests/t-*.c)
 UNIT_TEST_PROGRAMS = $(patsubst unit-tests/%.c,unit-tests/bin/%$(X),$(UNIT_TEST_SOURCES))
-UNIT_TESTS = $(sort $(filter-out unit-tests/bin/t-basic%,$(UNIT_TEST_PROGRAMS)))
+UNIT_TESTS = $(sort $(UNIT_TEST_PROGRAMS))
 
 # `test-chainlint` (which is a dependency of `test-lint`, `test` and `prove`)
 # checks all tests in all scripts via a single invocation, so tell individual
diff --git a/t/unit-tests/t-basic.c b/t/helper/test-example-tap.c
similarity index 95%
rename from t/unit-tests/t-basic.c
rename to t/helper/test-example-tap.c
index fda1ae59a6..d072ad559f 100644
--- a/t/unit-tests/t-basic.c
+++ b/t/helper/test-example-tap.c
@@ -1,4 +1,5 @@
-#include "test-lib.h"
+#include "test-tool.h"
+#include "t/unit-tests/test-lib.h"
 
 /*
  * The purpose of this "unit test" is to verify a few invariants of the unit
@@ -69,7 +70,7 @@ static void t_empty(void)
 	; /* empty */
 }
 
-int cmd_main(int argc, const char **argv)
+int cmd__example_tap(int argc, const char **argv)
 {
 	test_res = TEST(check_res = check_int(1, ==, 1), "passing test");
 	TEST(t_res(1), "passing test and assertion return 1");
diff --git a/t/helper/test-tool.c b/t/helper/test-tool.c
index 33b9501c21..bb5c04c9c0 100644
--- a/t/helper/test-tool.c
+++ b/t/helper/test-tool.c
@@ -29,6 +29,7 @@ static struct test_cmd cmds[] = {
 	{ "dump-untracked-cache", cmd__dump_untracked_cache },
 	{ "env-helper", cmd__env_helper },
 	{ "example-decorate", cmd__example_decorate },
+	{ "example-tap", cmd__example_tap },
 	{ "find-pack", cmd__find_pack },
 	{ "fsmonitor-client", cmd__fsmonitor_client },
 	{ "genrandom", cmd__genrandom },
diff --git a/t/helper/test-tool.h b/t/helper/test-tool.h
index b72f07ded9..38001bd1c6 100644
--- a/t/helper/test-tool.h
+++ b/t/helper/test-tool.h
@@ -23,6 +23,7 @@ int cmd__dump_untracked_cache(int argc, const char **argv);
 int cmd__dump_reftable(int argc, const char **argv);
 int cmd__env_helper(int argc, const char **argv);
 int cmd__example_decorate(int argc, const char **argv);
+int cmd__example_tap(int argc, const char **argv);
 int cmd__find_pack(int argc, const char **argv);
 int cmd__fsmonitor_client(int argc, const char **argv);
 int cmd__genrandom(int argc, const char **argv);
diff --git a/t/t0080-unit-test-output.sh b/t/t0080-unit-test-output.sh
index 961b54b06c..83b1e3b7f5 100755
--- a/t/t0080-unit-test-output.sh
+++ b/t/t0080-unit-test-output.sh
@@ -8,50 +8,50 @@ test_expect_success 'TAP output from unit tests' '
 	cat >expect <<-EOF &&
 	ok 1 - passing test
 	ok 2 - passing test and assertion return 1
-	# check "1 == 2" failed at t/unit-tests/t-basic.c:76
+	# check "1 == 2" failed at t/helper/test-example-tap.c:77
 	#    left: 1
 	#   right: 2
 	not ok 3 - failing test
 	ok 4 - failing test and assertion return 0
 	not ok 5 - passing TEST_TODO() # TODO
 	ok 6 - passing TEST_TODO() returns 1
-	# todo check ${SQ}check(x)${SQ} succeeded at t/unit-tests/t-basic.c:25
+	# todo check ${SQ}check(x)${SQ} succeeded at t/helper/test-example-tap.c:26
 	not ok 7 - failing TEST_TODO()
 	ok 8 - failing TEST_TODO() returns 0
-	# check "0" failed at t/unit-tests/t-basic.c:30
+	# check "0" failed at t/helper/test-example-tap.c:31
 	# skipping test - missing prerequisite
-	# skipping check ${SQ}1${SQ} at t/unit-tests/t-basic.c:32
+	# skipping check ${SQ}1${SQ} at t/helper/test-example-tap.c:33
 	ok 9 - test_skip() # SKIP
 	ok 10 - skipped test returns 1
 	# skipping test - missing prerequisite
 	ok 11 - test_skip() inside TEST_TODO() # SKIP
 	ok 12 - test_skip() inside TEST_TODO() returns 1
-	# check "0" failed at t/unit-tests/t-basic.c:48
+	# check "0" failed at t/helper/test-example-tap.c:49
 	not ok 13 - TEST_TODO() after failing check
 	ok 14 - TEST_TODO() after failing check returns 0
-	# check "0" failed at t/unit-tests/t-basic.c:56
+	# check "0" failed at t/helper/test-example-tap.c:57
 	not ok 15 - failing check after TEST_TODO()
 	ok 16 - failing check after TEST_TODO() returns 0
-	# check "!strcmp("\thello\\\\", "there\"\n")" failed at t/unit-tests/t-basic.c:61
+	# check "!strcmp("\thello\\\\", "there\"\n")" failed at t/helper/test-example-tap.c:62
 	#    left: "\011hello\\\\"
 	#   right: "there\"\012"
-	# check "!strcmp("NULL", NULL)" failed at t/unit-tests/t-basic.c:62
+	# check "!strcmp("NULL", NULL)" failed at t/helper/test-example-tap.c:63
 	#    left: "NULL"
 	#   right: NULL
-	# check "${SQ}a${SQ} == ${SQ}\n${SQ}" failed at t/unit-tests/t-basic.c:63
+	# check "${SQ}a${SQ} == ${SQ}\n${SQ}" failed at t/helper/test-example-tap.c:64
 	#    left: ${SQ}a${SQ}
 	#   right: ${SQ}\012${SQ}
-	# check "${SQ}\\\\${SQ} == ${SQ}\\${SQ}${SQ}" failed at t/unit-tests/t-basic.c:64
+	# check "${SQ}\\\\${SQ} == ${SQ}\\${SQ}${SQ}" failed at t/helper/test-example-tap.c:65
 	#    left: ${SQ}\\\\${SQ}
 	#   right: ${SQ}\\${SQ}${SQ}
 	not ok 17 - messages from failing string and char comparison
-	# BUG: test has no checks at t/unit-tests/t-basic.c:91
+	# BUG: test has no checks at t/helper/test-example-tap.c:92
 	not ok 18 - test with no checks
 	ok 19 - test with no checks returns 0
 	1..19
 	EOF
 
-	! "$GIT_BUILD_DIR"/t/unit-tests/bin/t-basic >actual &&
+	! test-tool example-tap >actual &&
 	test_cmp expect actual
 '
 
-- 
2.45.0.rc1.225.g2a3ae87e7f-goog
Previous: Josh SteadmonNext: Josh Steadmon
Message 92 of 99 in “test-tool: add unit test suite runner”
  1. 0/4 test-tool: add unit test suite runnerJosh Steadmon, Jan 16, 2024
  2. 1/4 t0080: turn t-basic unit test into a helperJosh Steadmon, Jan 16, 2024
  3. Junio C HamanoJan 16, 2024
  4. Jeff KingJan 23, 2024
  5. Josh SteadmonFeb 1, 2024
  6. 2/4 test-tool run-command testsuite: support unit testsJosh Steadmon, Jan 16, 2024
  7. Junio C HamanoJan 16, 2024
  8. Junio C HamanoJan 16, 2024
  9. Jeff KingJan 23, 2024
  10. Josh SteadmonFeb 1, 2024
  11. Junio C HamanoFeb 1, 2024
  12. Josh SteadmonFeb 1, 2024
  13. Josh SteadmonFeb 1, 2024
  14. 3/4 unit tests: add rule for running with test-toolJosh Steadmon, Jan 16, 2024
  15. 4/4 t/Makefile: run unit tests alongside shell testsJosh Steadmon, Jan 16, 2024
  16. Junio C HamanoJan 16, 2024
  17. 0/6 test-tool: add unit test suite runnerJosh Steadmon, Feb 3, 2024
  18. 1/6 t0080: turn t-basic unit test into a helperJosh Steadmon, Feb 3, 2024
  19. Junio C HamanoFeb 7, 2024
  20. Josh SteadmonFeb 12, 2024
  21. Jeff KingFeb 7, 2024
  22. Junio C HamanoFeb 8, 2024
  23. Josh SteadmonFeb 12, 2024
  24. Junio C HamanoFeb 12, 2024
  25. Jeff KingFeb 13, 2024
  26. rsbecker@nexbridge.comFeb 13, 2024
  27. Josh SteadmonFeb 22, 2024
  28. rsbecker@nexbridge.comFeb 23, 2024
  29. Junio C HamanoFeb 13, 2024
  30. Josh SteadmonFeb 22, 2024
  31. 2/6 test-tool run-command testsuite: get shell from envJosh Steadmon, Feb 3, 2024
  32. Junio C HamanoFeb 7, 2024
  33. Josh SteadmonFeb 12, 2024
  34. 3/6 test-tool run-command testsuite: remove hardcoded filterJosh Steadmon, Feb 3, 2024
  35. Junio C HamanoFeb 7, 2024
  36. Josh SteadmonFeb 12, 2024
  37. Junio C HamanoFeb 12, 2024
  38. 4/6 test-tool run-command testsuite: support unit testsJosh Steadmon, Feb 3, 2024
  39. phillip.wood123@gmail.comFeb 5, 2024
  40. Josh SteadmonFeb 12, 2024
  41. Junio C HamanoFeb 7, 2024
  42. Josh SteadmonFeb 23, 2024
  43. 5/6 unit tests: add rule for running with test-toolJosh Steadmon, Feb 3, 2024
  44. Junio C HamanoFeb 7, 2024
  45. 6/6 t/Makefile: run unit tests alongside shell testsJosh Steadmon, Feb 3, 2024
  46. Junio C HamanoFeb 7, 2024
  47. Jeff KingFeb 7, 2024
  48. Junio C HamanoFeb 7, 2024
  49. Junio C HamanoFeb 3, 2024
  50. Josh SteadmonFeb 12, 2024
  51. Junio C HamanoFeb 7, 2024
  52. 0/7 test-tool: add unit test suite runnerJosh Steadmon, Feb 23, 2024
  53. 1/7 t0080: turn t-basic unit test into a helperJosh Steadmon, Feb 23, 2024
  54. 2/7 test-tool run-command testsuite: get shell from envJosh Steadmon, Feb 23, 2024
  55. 3/7 test-tool run-command testsuite: remove hardcoded filterJosh Steadmon, Feb 23, 2024
  56. 4/7 test-tool run-command testsuite: support unit testsJosh Steadmon, Feb 23, 2024
  57. 5/7 unit tests: add rule for running with test-toolJosh Steadmon, Feb 23, 2024
  58. 6/7 t/Makefile: run unit tests alongside shell testsJosh Steadmon, Feb 23, 2024
  59. Jeff KingMar 27, 2024
  60. Josh SteadmonApr 11, 2024
  61. Jeff KingApr 12, 2024
  62. Josh SteadmonApr 24, 2024
  63. 7/7 ci: use test-tool as unit test runner on WindowsJosh Steadmon, Feb 23, 2024
  64. Junio C HamanoMar 26, 2024
  65. Jeff KingMar 27, 2024
  66. 0/7 test-tool: add unit test suite runnerJosh Steadmon, Apr 24, 2024
  67. 1/7 t0080: turn t-basic unit test into a helperJosh Steadmon, Apr 24, 2024
  68. 2/7 test-tool run-command testsuite: get shell from envJosh Steadmon, Apr 24, 2024
  69. 3/7 test-tool run-command testsuite: remove hardcoded filterJosh Steadmon, Apr 24, 2024
  70. 4/7 test-tool run-command testsuite: support unit testsJosh Steadmon, Apr 24, 2024
  71. 5/7 unit tests: add rule for running with test-toolJosh Steadmon, Apr 24, 2024
  72. 6/7 t/Makefile: run unit tests alongside shell testsJosh Steadmon, Apr 24, 2024
  73. Junio C HamanoApr 24, 2024
  74. Josh SteadmonApr 30, 2024
  75. Jeff KingMay 3, 2024
  76. Junio C HamanoMay 3, 2024
  77. Josh SteadmonMay 6, 2024
  78. 7/7 ci: use test-tool as unit test runner on WindowsJosh Steadmon, Apr 24, 2024
  79. 0/7 test-tool: add unit test suite runnerJosh Steadmon, Apr 30, 2024
  80. 1/7 t0080: turn t-basic unit test into a helperJosh Steadmon, Apr 30, 2024
  81. 2/7 test-tool run-command testsuite: get shell from envJosh Steadmon, Apr 30, 2024
  82. 3/7 test-tool run-command testsuite: remove hardcoded filterJosh Steadmon, Apr 30, 2024
  83. 4/7 test-tool run-command testsuite: support unit testsJosh Steadmon, Apr 30, 2024
  84. 5/7 unit tests: add rule for running with test-toolJosh Steadmon, Apr 30, 2024
  85. 6/7 t/Makefile: run unit tests alongside shell testsJosh Steadmon, Apr 30, 2024
  86. Junio C HamanoApr 30, 2024
  87. Josh SteadmonMay 6, 2024
  88. 7/7 ci: use test-tool as unit test runner on WindowsJosh Steadmon, Apr 30, 2024
  89. Junio C HamanoApr 30, 2024
  90. Josh SteadmonMay 6, 2024
  91. 0/7 test-tool: add unit test suite runnerJosh Steadmon, May 6, 2024
  92. 1/7 t0080: turn t-basic unit test into a helperJosh Steadmon, May 6, 2024
  93. 2/7 test-tool run-command testsuite: get shell from envJosh Steadmon, May 6, 2024
  94. 3/7 test-tool run-command testsuite: remove hardcoded filterJosh Steadmon, May 6, 2024
  95. 4/7 test-tool run-command testsuite: support unit testsJosh Steadmon, May 6, 2024
  96. 5/7 unit tests: add rule for running with test-toolJosh Steadmon, May 6, 2024
  97. 6/7 t/Makefile: run unit tests alongside shell testsJosh Steadmon, May 6, 2024
  98. 7/7 ci: use test-tool as unit test runner on WindowsJosh Steadmon, May 6, 2024
  99. Junio C HamanoMay 6, 2024

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.