mirror of
https://github.com/c3lang/c3c.git
synced 2026-02-27 12:01:16 +00:00
Add test option --test-log-level to choose tests' log level (#2560)
* Add test option `--test-log-level` to choose tests' log level * draft: Improvements to `--test-log-level` * Some fixes. --------- Co-authored-by: Christoffer Lerno <christoffer@aegik.com>
This commit is contained in:
@@ -18,6 +18,8 @@ struct TestContext
|
||||
String test_filter;
|
||||
<* Triggers debugger breakpoint when assert or test:: checks failed *>
|
||||
bool breakpoint_on_assert;
|
||||
<* Controls level of printed logs *>
|
||||
LogPriority log_level;
|
||||
|
||||
// internal state
|
||||
bool assert_print_backtrace;
|
||||
@@ -202,6 +204,7 @@ $endif
|
||||
{
|
||||
.assert_print_backtrace = true,
|
||||
.breakpoint_on_assert = false,
|
||||
.log_level = LogPriority.ERROR,
|
||||
.test_filter = "",
|
||||
.has_ansi_codes = terminal_has_ansi_codes(),
|
||||
.stored.allocator = mem,
|
||||
@@ -234,11 +237,28 @@ $endif
|
||||
}
|
||||
context.test_filter = args[i + 1];
|
||||
i++;
|
||||
case "--test-log-level":
|
||||
if (i == args.len - 1)
|
||||
{
|
||||
io::printn("Missing log level for argument `--test-log-level`.");
|
||||
return false;
|
||||
}
|
||||
@pool()
|
||||
{
|
||||
String upper = args[i + 1].to_upper_copy(tmem);
|
||||
if (catch @try(context.log_level, enum_by_name(LogPriority, upper)))
|
||||
{
|
||||
io::printn("Log level given to `--test-log-level` is not one of verbose, debug, info, warn, error or critical.");
|
||||
return false;
|
||||
}
|
||||
};
|
||||
i++;
|
||||
default:
|
||||
io::printfn("Unknown argument: %s", args[i]);
|
||||
}
|
||||
}
|
||||
test_context = &context;
|
||||
log::set_priority_all(test_context.log_level);
|
||||
|
||||
if (sort_tests)
|
||||
{
|
||||
|
||||
@@ -142,6 +142,17 @@ typedef enum
|
||||
OPTIMIZATION_AGGRESSIVE = 3, // -O3
|
||||
} OptimizationLevel;
|
||||
|
||||
typedef enum
|
||||
{
|
||||
TESTLOGLEVEL_NOT_SET = -1,
|
||||
TESTLOGLEVEL_VERBOSE = 0,
|
||||
TESTLOGLEVEL_DEBUG = 1,
|
||||
TESTLOGLEVEL_INFO = 2,
|
||||
TESTLOGLEVEL_WARN = 3,
|
||||
TESTLOGLEVEL_ERROR = 4,
|
||||
TESTLOGLEVEL_CRITICAL = 5,
|
||||
} TestLogLevel;
|
||||
|
||||
typedef enum
|
||||
{
|
||||
PANIC_NOT_SET = -1,
|
||||
@@ -511,6 +522,7 @@ typedef struct BuildOptions_
|
||||
const char **unchecked_directories;
|
||||
LinkerType linker_type;
|
||||
ValidationLevel validation_level;
|
||||
TestLogLevel test_log_level;
|
||||
Ansi ansi;
|
||||
bool test_breakpoint;
|
||||
bool test_quiet;
|
||||
|
||||
@@ -107,6 +107,15 @@ static const char *optlevels[4] = {
|
||||
[OPTIMIZATION_AGGRESSIVE] = "max",
|
||||
};
|
||||
|
||||
static const char *test_log_levels[6] = {
|
||||
[TESTLOGLEVEL_VERBOSE] = "verbose",
|
||||
[TESTLOGLEVEL_DEBUG] = "debug",
|
||||
[TESTLOGLEVEL_INFO] = "info",
|
||||
[TESTLOGLEVEL_WARN] = "warn",
|
||||
[TESTLOGLEVEL_ERROR] = "error",
|
||||
[TESTLOGLEVEL_CRITICAL] = "critical",
|
||||
};
|
||||
|
||||
static const char *backends[3] = {
|
||||
[BACKEND_LLVM] = "llvm",
|
||||
[BACKEND_TB] = "tb",
|
||||
|
||||
@@ -153,6 +153,7 @@ static void usage(bool full)
|
||||
print_opt("--test-noleak", "Disable tracking allocator and memory leak detection for tests");
|
||||
print_opt("--test-nocapture", "Disable test stdout capturing, all tests can print as they run");
|
||||
print_opt("--test-quiet", "Run tests without printing full names, printing output only on failure");
|
||||
print_opt("--test-log-level=<verbose|debug|info|warn|error|critical>", "Set log priority when running tests.");
|
||||
}
|
||||
PRINTF("");
|
||||
print_opt("-l <library>", "Link with the static or dynamic library provided.");
|
||||
@@ -869,6 +870,11 @@ static void parse_option(BuildOptions *options)
|
||||
options->optlevel = parse_opt_select(OptimizationLevel, argopt, optlevels);
|
||||
return;
|
||||
}
|
||||
if ((argopt = match_argopt("test-log-level")))
|
||||
{
|
||||
options->test_log_level = parse_opt_select(TestLogLevel, argopt, test_log_levels);
|
||||
return;
|
||||
}
|
||||
if ((argopt = match_argopt("merge-functions")))
|
||||
{
|
||||
options->merge_functions = parse_opt_select(MergeFunctions, argopt, on_off);
|
||||
@@ -1456,6 +1462,7 @@ BuildOptions parse_arguments(int argc, const char *argv[])
|
||||
.emit_llvm = false,
|
||||
.optsetting = OPT_SETTING_NOT_SET,
|
||||
.debug_info_override = DEBUG_INFO_NOT_SET,
|
||||
.test_log_level = TESTLOGLEVEL_NOT_SET,
|
||||
.safety_level = SAFETY_NOT_SET,
|
||||
.panic_level = PANIC_NOT_SET,
|
||||
.show_backtrace = SHOW_BACKTRACE_NOT_SET,
|
||||
|
||||
@@ -322,6 +322,11 @@ static void update_build_target_from_options(BuildTarget *target, BuildOptions *
|
||||
vec_add(target->args, "--test-filter");
|
||||
vec_add(target->args, options->test_filter);
|
||||
}
|
||||
if (options->test_log_level > -1)
|
||||
{
|
||||
vec_add(target->args, "--test-log-level");
|
||||
vec_add(target->args, test_log_levels[options->test_log_level]);
|
||||
}
|
||||
if (options->test_breakpoint) vec_add(target->args, "--test-breakpoint");
|
||||
if (options->test_nosort) vec_add(target->args, "--test-nosort");
|
||||
if (options->test_quiet) vec_add(target->args, "--test-quiet");
|
||||
|
||||
Reference in New Issue
Block a user