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

[RFC PATCH v2 0/6] test-tool: add unit test suite runner

From
Josh Steadmon <steadmon@google.com>
Date
Feb 3, 2024, 00:50 UTC
Message-ID
<cover.1706921262.git.steadmon@google.com>
In-Reply-To
<cover.1705443632.git.steadmon@google.com>
Please note: this series has been rebased onto jk/unit-tests-buildfix.

For various reasons (see discussion at [1]) we would like an alternative to `prove` for running test suites (including the unit tests) on Windows.

This series extends the existing `test-tool run-command testsuite` to
support running unit tests. In addition, it includes some small
cleanups:
* move t-basic out of the unit-tests directory
* don't hardcode the shell for running tests in `test-tool ... testsuite`
* don't hardcode a test name filter in `test-tool ... testsuite`
* add a test wrapper script to allow unit tests and the shell test suite
  to run in a single `prove` process
Some known remaining bits of work:
* We should investigate switching the Windows CI to use `test-tool`
  instead of prove. However, Windows CI seems broken on
  jk/unit-tests-buildfix, and I haven't had time to determine why.
* We should determine whether it is confusing or otherwise harmful to
  people's workflow to have the unit tests run in parallel with shell
  tests when using prove as the default test target.
[1] https://lore.kernel.org/git/pull.1613.git.1699894837844.gitgitgadget@gmail.com/
Changes in V2:
* Patch 1: move t-basic to a test-tool subcommand rather than a new
  executable under t/t0080/
* New patch 2: get the shell path from TEST_SHELL_PATH in
  `test-tool run-command testsuite`
* New patch 3: remove the hardcoded filename filter in
  `test-tool run-command testsuite`
* Patch 4 (previously 2): simplified now that we no longer need to add
  any command-line flags to support unit tests
* Patch 5 (previously 3): avoid trying to run cmake *.pdb files by using
  the unit test list built in the makefile in jk/unit-tests-buildfix.
Jeff King (1):
  t/Makefile: run unit tests alongside shell tests
Josh Steadmon (5):
  t0080: turn t-basic unit test into a helper
  test-tool run-command testsuite: get shell from env
  test-tool run-command testsuite: remove hardcoded filter
  test-tool run-command testsuite: support unit tests
  unit tests: add rule for running with test-tool
 Makefile                                      |  6 ++--
 t/Makefile                                    | 15 +++++++---
 .../t-basic.c => helper/test-example-tap.c}   |  5 ++--
 t/helper/test-run-command.c                   | 29 +++++++++++++++----
 t/helper/test-tool.c                          |  1 +
 t/helper/test-tool.h                          |  1 +
 t/run-test.sh                                 | 13 +++++++++
 t/t0080-unit-test-output.sh                   | 24 +++++++--------
 8 files changed, 67 insertions(+), 27 deletions(-)
 rename t/{unit-tests/t-basic.c => helper/test-example-tap.c} (95%)
 create mode 100755 t/run-test.sh
Range-diff against v1:
1:  a9f67ed703 < -:  ---------- t0080: turn t-basic unit test into a helper
-:  ---------- > 1:  da756b4bfb t0080: turn t-basic unit test into a helper
-:  ---------- > 2:  c8448406d7 test-tool run-command testsuite: get shell from env
-:  ---------- > 3:  e1b89ae93e test-tool run-command testsuite: remove hardcoded filter
2:  5ecbc976e6 ! 4:  b5665386b5 test-tool run-command testsuite: support unit tests
    @@ Commit message
         test-tool run-command testsuite: support unit tests
     
         Teach the testsuite runner in `test-tool run-command testsuite` how to
    -    run unit tests, by adding two new flags:
    +    run unit tests: if TEST_SHELL_PATH is not set, assume that we're running
    +    the programs directly from CWD, rather than defaulting to "sh" as an
    +    interpreter.
     
    -    First, "--(no-)run-in-shell" allows the test-tool to exec the unit-test
    -    binaries directly, rather than trying to interpret them as shell
    -    scripts.
    -
    -    Second "--(no-)require-shell-test-pattern" bypasses the check that the
    -    test filenames match the expected t####-*.sh pattern.
    -
    -    With these changes, you can now use test-tool to run the unit tests:
    +    With this change, you can now use test-tool to run the unit tests:
         $ make
         $ cd t/unit-tests/bin
    -    $ ../../helper/test-tool run-command testsuite --no-run-in-shell \
    -        --no-require-shell-test-pattern
    +    $ ../../helper/test-tool run-command testsuite
     
         This should be helpful on Windows to allow running tests without
         requiring Perl (for `prove`), as discussed in [1] and [2].
     
    +    This again breaks backwards compatibility, as it is now required to set
    +    TEST_SHELL_PATH properly for executing shell scripts, but again, as
    +    noted in [2], there are no longer any such invocations in our codebase.
    +
         [1] https://lore.kernel.org/git/nycvar.QRO.7.76.6.2109091323150.59@tvgsbejvaqbjf.bet/
         [2] https://lore.kernel.org/git/850ea42c-f103-68d5-896b-9120e2628686@gmx.de/
     
     
      ## t/helper/test-run-command.c ##
    -@@ t/helper/test-run-command.c: static int task_finished(int result UNUSED,
    - struct testsuite {
    - 	struct string_list tests, failed;
    - 	int next;
    --	int quiet, immediate, verbose, verbose_log, trace, write_junit_xml;
    -+	int quiet, immediate, verbose, verbose_log, trace, write_junit_xml, run_in_shell;
    - };
    - #define TESTSUITE_INIT { \
    - 	.tests = STRING_LIST_INIT_DUP, \
    - 	.failed = STRING_LIST_INIT_DUP, \
    -+	.run_in_shell = 1, \
    - }
    - 
    - static int next_test(struct child_process *cp, struct strbuf *err, void *cb,
    -@@ t/helper/test-run-command.c: static int next_test(struct child_process *cp, struct strbuf *err, void *cb,
    - 		return 0;
    - 
    - 	test = suite->tests.items[suite->next++].string;
    --	strvec_pushl(&cp->args, "sh", test, NULL);
    -+	if (suite->run_in_shell)
    -+		strvec_push(&cp->args, "sh");
    -+	strvec_push(&cp->args, test);
    - 	if (suite->quiet)
    - 		strvec_push(&cp->args, "--quiet");
    - 	if (suite->immediate)
    -@@ t/helper/test-run-command.c: static const char * const testsuite_usage[] = {
    - static int testsuite(int argc, const char **argv)
    - {
    - 	struct testsuite suite = TESTSUITE_INIT;
    --	int max_jobs = 1, i, ret = 0;
    -+	int max_jobs = 1, i, ret = 0, require_shell_test_pattern = 1;
    - 	DIR *dir;
    - 	struct dirent *d;
    - 	struct option options[] = {
    -@@ t/helper/test-run-command.c: static int testsuite(int argc, const char **argv)
    - 		OPT_BOOL('x', "trace", &suite.trace, "trace shell commands"),
    - 		OPT_BOOL(0, "write-junit-xml", &suite.write_junit_xml,
    - 			 "write JUnit-style XML files"),
    -+		OPT_BOOL(0, "run-in-shell", &suite.run_in_shell,
    -+			 "run programs in the suite via `sh`"),
    -+		OPT_BOOL(0, "require-shell-test-pattern", &require_shell_test_pattern,
    -+			 "require programs to match 't####-*.sh'"),
    - 		OPT_END()
    - 	};
    - 	struct run_process_parallel_opts opts = {
     @@ t/helper/test-run-command.c: static int testsuite(int argc, const char **argv)
      		.task_finished = test_finished,
      		.data = &suite,
    @@ t/helper/test-run-command.c: static int testsuite(int argc, const char **argv)
      
      	argc = parse_options(argc, argv, NULL, options,
      			testsuite_usage, PARSE_OPT_STOP_AT_NON_OPTION);
    - 
    +@@ t/helper/test-run-command.c: static int testsuite(int argc, const char **argv)
      	if (max_jobs <= 0)
      		max_jobs = online_cpus();
    + 
     +	/*
     +	 * If we run without a shell, we have to provide the relative path to
     +	 * the executables.
     +	 */
    -+	if (!suite.run_in_shell)
    + 	suite.shell_path = getenv("TEST_SHELL_PATH");
    + 	if (!suite.shell_path)
    +-		suite.shell_path = "sh";
     +		strbuf_addstr(&progpath, "./");
     +	path_prefix_len = progpath.len;
      
      	dir = opendir(".");
      	if (!dir)
     @@ t/helper/test-run-command.c: static int testsuite(int argc, const char **argv)
    - 	while ((d = readdir(dir))) {
    - 		const char *p = d->d_name;
    - 
    --		if (*p != 't' || !isdigit(p[1]) || !isdigit(p[2]) ||
    --		    !isdigit(p[3]) || !isdigit(p[4]) || p[5] != '-' ||
    --		    !ends_with(p, ".sh"))
    -+		if (!strcmp(p, ".") || !strcmp(p, ".."))
    - 			continue;
    -+		if (require_shell_test_pattern)
    -+			if (*p != 't' || !isdigit(p[1]) || !isdigit(p[2]) ||
    -+			    !isdigit(p[3]) || !isdigit(p[4]) || p[5] != '-' ||
    -+			    !ends_with(p, ".sh"))
    -+				continue;
      
      		/* No pattern: match all */
      		if (!argc) {
3:  5b34c851cd ! 5:  f2746703d5 unit tests: add rule for running with test-tool
    @@ Commit message
         `make DEFAULT_UNIT_TEST_TARGET=unit-tests-test-tool unit-tests`, or by
         setting DEFAULT_UNIT_TEST_TARGET in config.mak.
     
    -    NEEDS WORK: we need to exclude .pdb files generated by cmake [see
    -    0df903d402 (unit-tests: do not mistake `.pdb` files for being
    -    executable, 2023-09-25)]
    -
     
      ## Makefile ##
    -@@ Makefile: $(UNIT_TEST_HELPER_PROGS): %$X: %.o $(UNIT_TEST_DIR)/test-lib.o $(GITLIBS) GIT-L
    +@@ Makefile: $(UNIT_TEST_PROGS): $(UNIT_TEST_BIN)/%$X: $(UNIT_TEST_DIR)/%.o $(UNIT_TEST_DIR)/
      
      .PHONY: build-unit-tests unit-tests
      build-unit-tests: $(UNIT_TEST_PROGS)
    @@ Makefile: $(UNIT_TEST_HELPER_PROGS): %$X: %.o $(UNIT_TEST_DIR)/test-lib.o $(GITL
      	$(MAKE) -C t/ unit-tests
     
      ## t/Makefile ##
    +@@ t/Makefile: CHAINLINTTESTS = $(sort $(patsubst chainlint/%.test,%,$(wildcard chainlint/*.tes
    + CHAINLINT = '$(PERL_PATH_SQ)' chainlint.pl
    + UNIT_TEST_SOURCES = $(wildcard unit-tests/t-*.c)
    + UNIT_TESTS = $(patsubst unit-tests/%.c,unit-tests/bin/%$(X),$(UNIT_TEST_SOURCES))
    ++UNIT_TESTS_NO_DIR = $(notdir $(UNIT_TESTS))
    + 
    + # `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
     @@ t/Makefile: $(T):
      $(UNIT_TESTS):
      	@echo "*** $@ ***"; $@
    @@ t/Makefile: unit-tests-raw: $(UNIT_TESTS)
     +	@echo "*** test-tool - unit tests **"
     +	( \
     +		cd unit-tests/bin && \
    -+		../../helper/test-tool run-command testsuite --no-run-in-shell --no-require-shell-test-pattern \
    ++		../../helper/test-tool$X run-command testsuite $(UNIT_TESTS_NO_DIR)\
     +	)
     +
      pre-clean:
4:  c823265f0d = 6:  cd7467a7bd t/Makefile: run unit tests alongside shell tests
base-commit: 799d449105dc1f6e77fa1ebaea4f6d8bdc6537cf
-- 
2.43.0.594.gd9cf4e227d-goog
Previous: Junio C HamanoNext: Josh Steadmon
Message 17 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.