diff --git a/doc/env.rst b/doc/env.rst index 234a496..2205bc5 100644 --- a/doc/env.rst +++ b/doc/env.rst @@ -93,3 +93,8 @@ Environment variables are alternatives to command line switches when set to 1. to its value. (\*nix only) * ``CRITERION_DISABLE_TIME_MEASUREMENTS``: Disables any time measurements on the tests. +* ``CRITERION_OUTPUTS``: Can be set to a comma-separated list of + ``PROVIDER:FILE`` entries. For instance, setting the variable to + ``tap:foo.tap,xml:bar.xml`` has the same effect as specifying ``--tap=foo.tap`` + and ``--xml=bar.xml`` at once. +* ``CRITERION_ENABLE_TAP``: (Deprecated, use CRITERION_OUTPUTS) Same as ``--tap``. diff --git a/src/entry/main.c b/src/entry/main.c index 1f64243..833f6ad 100644 --- a/src/entry/main.c +++ b/src/entry/main.c @@ -200,10 +200,42 @@ int criterion_handle_args(int argc, char *argv[], bool handle_unknown_arg) { opt->measure_time = !!strcmp("1", DEF(getenv("CRITERION_DISABLE_TIME_MEASUREMENTS"), "0")); + bool quiet = false; + + // CRITERION_ENABLE_TAP backward compatibility. + // The environment variable is otherwise deprecated. + if (!strcmp("1", DEF(getenv("CRITERION_ENABLE_TAP"), "0"))) { + quiet = true; + criterion_add_output("tap", DEF(optarg, "-")); + } + bool do_list_tests = false; bool do_print_version = false; bool do_print_usage = false; - bool quiet = false; + + const char *outputs = getenv("CRITERION_OUTPUTS"); + if (outputs) { + char *out = strdup(outputs); + char *buf = NULL; + strtok_r(out, ",", &buf); + + for (char *s = out; s; s = strtok_r(NULL, ",", &buf)) { + s = strdup(s); + char *buf2 = NULL; + char *provider = strtok_r(s, ":", &buf2); + char *path = strtok_r(NULL, ":", &buf2); + + if (provider == NULL || path == NULL) { + do_print_usage = true; + goto end; + } + + quiet = true; + criterion_add_output(provider, path); + } + free(out); + } + for (int c; (c = getopt_long(argc, argv, "hvlfj:SqO:", opts, NULL)) != -1;) { switch (c) { case 'b': criterion_options.logging_threshold = (enum criterion_logging_level) atou(DEF(optarg, "1")); break; @@ -241,6 +273,8 @@ int criterion_handle_args(int argc, char *argv[], bool handle_unknown_arg) { default : do_print_usage = handle_unknown_arg; break; } } + +end: if (quiet) criterion_options.logging_threshold = CRITERION_LOG_LEVEL_QUIET;