diff options
| author | Junio C Hamano <gitster@pobox.com> | 2024-09-18 18:02:05 -0700 |
|---|---|---|
| committer | Junio C Hamano <gitster@pobox.com> | 2024-09-18 18:02:05 -0700 |
| commit | 5d55832f5cf914d583881cdb6f7b76b1793e2b16 (patch) | |
| tree | 665698b7e6c23568a0f081469c2f990973abbed6 /t/unit-tests/unit-test.c | |
| parent | 3fb745257b30a643ee78c9a7c52ab107c82e4745 (diff) | |
| parent | c3de556a841f132832f742d1c4d3a2618ee3b355 (diff) | |
Merge branch 'ps/clar-unit-test'
Import clar unit tests framework libgit2 folks invented for our
use.
* ps/clar-unit-test:
Makefile: rename clar-related variables to avoid confusion
clar: add CMake support
t/unit-tests: convert ctype tests to use clar
t/unit-tests: convert strvec tests to use clar
t/unit-tests: implement test driver
Makefile: wire up the clar unit testing framework
Makefile: do not use sparse on third-party sources
Makefile: make hdr-check depend on generated headers
Makefile: fix sparse dependency on GENERATED_H
clar: stop including `shellapi.h` unnecessarily
clar(win32): avoid compile error due to unused `fs_copy()`
clar: avoid compile error with mingw-w64
t/clar: fix compatibility with NonStop
t: import the clar unit testing framework
t: do not pass GIT_TEST_OPTS to unit tests with prove
Diffstat (limited to 't/unit-tests/unit-test.c')
| -rw-r--r-- | t/unit-tests/unit-test.c | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/t/unit-tests/unit-test.c b/t/unit-tests/unit-test.c new file mode 100644 index 0000000000..a474cdcfd3 --- /dev/null +++ b/t/unit-tests/unit-test.c @@ -0,0 +1,47 @@ +#include "unit-test.h" +#include "parse-options.h" +#include "string-list.h" +#include "strvec.h" + +static const char * const unit_test_usage[] = { + N_("unit-test [<options>]"), + NULL, +}; + +int cmd_main(int argc, const char **argv) +{ + struct string_list run_args = STRING_LIST_INIT_NODUP; + struct string_list exclude_args = STRING_LIST_INIT_NODUP; + int immediate = 0; + struct option options[] = { + OPT_BOOL('i', "immediate", &immediate, + N_("immediately exit upon the first failed test")), + OPT_STRING_LIST('r', "run", &run_args, N_("suite[::test]"), + N_("run only test suite or individual test <suite[::test]>")), + OPT_STRING_LIST('x', "exclude", &exclude_args, N_("suite"), + N_("exclude test suite <suite>")), + OPT_END(), + }; + struct strvec args = STRVEC_INIT; + int ret; + + argc = parse_options(argc, argv, NULL, options, + unit_test_usage, PARSE_OPT_KEEP_ARGV0); + if (argc > 1) + usagef(_("extra command line parameter '%s'"), argv[0]); + + strvec_push(&args, argv[0]); + strvec_push(&args, "-t"); + if (immediate) + strvec_push(&args, "-Q"); + for (size_t i = 0; i < run_args.nr; i++) + strvec_pushf(&args, "-s%s", run_args.items[i].string); + for (size_t i = 0; i < exclude_args.nr; i++) + strvec_pushf(&args, "-x%s", exclude_args.items[i].string); + + ret = clar_test(args.nr, (char **) args.v); + + string_list_clear(&run_args, 0); + strvec_clear(&args); + return ret; +} |
