Git fork
1#include "unit-test.h"
2#include "hex.h"
3#include "parse-options.h"
4#include "strbuf.h"
5#include "string-list.h"
6#include "strvec.h"
7
8static const char * const unit_test_usage[] = {
9 N_("unit-test [<options>]"),
10 NULL,
11};
12
13int cmd_main(int argc, const char **argv)
14{
15 struct string_list run_args = STRING_LIST_INIT_NODUP;
16 struct string_list exclude_args = STRING_LIST_INIT_NODUP;
17 int immediate = 0;
18 struct option options[] = {
19 OPT_BOOL('i', "immediate", &immediate,
20 N_("immediately exit upon the first failed test")),
21 OPT_STRING_LIST('r', "run", &run_args, N_("suite[::test]"),
22 N_("run only test suite or individual test <suite[::test]>")),
23 OPT_STRING_LIST(0, "exclude", &exclude_args, N_("suite"),
24 N_("exclude test suite <suite>")),
25 /*
26 * Compatibility wrappers so that we don't have to filter
27 * options understood by integration tests.
28 */
29 OPT_NOOP_NOARG('d', "debug"),
30 OPT_NOOP_NOARG(0, "github-workflow-markup"),
31 OPT_NOOP_NOARG(0, "no-bin-wrappers"),
32 OPT_NOOP_ARG(0, "root"),
33 OPT_NOOP_ARG(0, "stress"),
34 OPT_NOOP_NOARG(0, "tee"),
35 OPT_NOOP_NOARG(0, "with-dashes"),
36 OPT_NOOP_ARG(0, "valgrind"),
37 OPT_NOOP_ARG(0, "valgrind-only"),
38 OPT_NOOP_NOARG('v', "verbose"),
39 OPT_NOOP_NOARG('V', "verbose-log"),
40 OPT_NOOP_ARG(0, "verbose-only"),
41 OPT_NOOP_NOARG('x', NULL),
42 OPT_END(),
43 };
44 struct strvec args = STRVEC_INIT;
45 int ret;
46
47 argc = parse_options(argc, argv, NULL, options,
48 unit_test_usage, PARSE_OPT_KEEP_ARGV0);
49 if (argc > 1)
50 usagef(_("extra command line parameter '%s'"), argv[0]);
51
52 strvec_push(&args, argv[0]);
53 strvec_push(&args, "-t");
54 if (immediate)
55 strvec_push(&args, "-Q");
56 for (size_t i = 0; i < run_args.nr; i++)
57 strvec_pushf(&args, "-s%s", run_args.items[i].string);
58 for (size_t i = 0; i < exclude_args.nr; i++)
59 strvec_pushf(&args, "-x%s", exclude_args.items[i].string);
60
61 ret = clar_test(args.nr, (char **) args.v);
62
63 string_list_clear(&run_args, 0);
64 strvec_clear(&args);
65 return ret;
66}