|
1 | 1 | #include "unit-test.h"
|
| 2 | +#include "parse-options.h" |
| 3 | +#include "string-list.h" |
| 4 | +#include "strvec.h" |
2 | 5 |
|
3 |
| -int cmd_main(int argc UNUSED, const char **argv UNUSED) |
| 6 | +static const char * const unit_test_usage[] = { |
| 7 | + N_("unit-test [<options>]"), |
| 8 | + NULL, |
| 9 | +}; |
| 10 | + |
| 11 | +int cmd_main(int argc, const char **argv) |
4 | 12 | {
|
5 |
| - return 0; |
| 13 | + struct string_list run_args = STRING_LIST_INIT_NODUP; |
| 14 | + struct string_list exclude_args = STRING_LIST_INIT_NODUP; |
| 15 | + int immediate = 0; |
| 16 | + struct option options[] = { |
| 17 | + OPT_BOOL('i', "immediate", &immediate, |
| 18 | + N_("immediately exit upon the first failed test")), |
| 19 | + OPT_STRING_LIST('r', "run", &run_args, N_("suite[::test]"), |
| 20 | + N_("run only test suite or individual test <suite[::test]>")), |
| 21 | + OPT_STRING_LIST('x', "exclude", &exclude_args, N_("suite"), |
| 22 | + N_("exclude test suite <suite>")), |
| 23 | + OPT_END(), |
| 24 | + }; |
| 25 | + struct strvec args = STRVEC_INIT; |
| 26 | + int ret; |
| 27 | + |
| 28 | + argc = parse_options(argc, argv, NULL, options, |
| 29 | + unit_test_usage, PARSE_OPT_KEEP_ARGV0); |
| 30 | + if (argc > 1) |
| 31 | + usagef(_("extra command line parameter '%s'"), argv[0]); |
| 32 | + |
| 33 | + strvec_push(&args, argv[0]); |
| 34 | + strvec_push(&args, "-t"); |
| 35 | + if (immediate) |
| 36 | + strvec_push(&args, "-Q"); |
| 37 | + for (size_t i = 0; i < run_args.nr; i++) |
| 38 | + strvec_pushf(&args, "-s%s", run_args.items[i].string); |
| 39 | + for (size_t i = 0; i < exclude_args.nr; i++) |
| 40 | + strvec_pushf(&args, "-x%s", exclude_args.items[i].string); |
| 41 | + |
| 42 | + ret = clar_test(args.nr, (char **) args.v); |
| 43 | + |
| 44 | + string_list_clear(&run_args, 0); |
| 45 | + strvec_clear(&args); |
| 46 | + return ret; |
6 | 47 | }
|
0 commit comments