mirror of
https://github.com/c3lang/c3c.git
synced 2026-02-27 12:01:16 +00:00
Allow test runners to take String[] arguments.
This commit is contained in:
@@ -286,6 +286,20 @@ static void sema_analyze_to_stage(AnalysisStage stage)
|
||||
halt_on_error();
|
||||
}
|
||||
|
||||
static bool setup_main_runner(Decl *run_function)
|
||||
{
|
||||
SemaContext context;
|
||||
sema_context_init(&context, run_function->unit);
|
||||
Decl *main = sema_create_runner_main(&context, run_function);
|
||||
if (!decl_ok(main)) return false;
|
||||
if (!sema_analyse_decl(&context, main)) return false;
|
||||
if (!sema_analyse_function_body(&context, main)) return false;
|
||||
sema_context_destroy(&context);
|
||||
compiler.context.main = main;
|
||||
main->unit->main_function = main;
|
||||
main->no_strip = true;
|
||||
return true;
|
||||
}
|
||||
static void assign_panicfn(void)
|
||||
{
|
||||
if (compiler.build.feature.panic_level == PANIC_OFF || (!compiler.build.panicfn && no_stdlib()))
|
||||
@@ -354,7 +368,7 @@ static void assign_testfn(void)
|
||||
if (!compiler.build.testing) return;
|
||||
if (!compiler.build.testfn && no_stdlib())
|
||||
{
|
||||
compiler.context.test_func = NULL;
|
||||
error_exit("No test function could be found.");
|
||||
return;
|
||||
}
|
||||
const char *testfn = compiler.build.testfn ? compiler.build.testfn : "std::core::runtime::default_test_runner";
|
||||
@@ -374,12 +388,17 @@ static void assign_testfn(void)
|
||||
{
|
||||
error_exit("'%s::%s' is not a function.", path->module, ident);
|
||||
}
|
||||
if (!type_func_match(type_get_func_ptr(decl->type->canonical), type_bool, 0))
|
||||
if (!type_func_match(type_get_func_ptr(decl->type->canonical), type_bool, 1, type_get_slice(type_string)))
|
||||
{
|
||||
error_exit("Expected test runner to have the signature fn void().");
|
||||
error_exit("Expected test runner to have the signature fn bool(String[]).");
|
||||
}
|
||||
compiler.context.test_func = decl;
|
||||
decl->no_strip = true;
|
||||
if (compiler.build.type != TARGET_TYPE_TEST) return;
|
||||
|
||||
if (!setup_main_runner(decl))
|
||||
{
|
||||
error_exit("Failed to set up test runner.");
|
||||
}
|
||||
}
|
||||
|
||||
static void assign_benchfn(void)
|
||||
@@ -387,7 +406,6 @@ static void assign_benchfn(void)
|
||||
if (!compiler.build.benchmarking) return;
|
||||
if (!compiler.build.benchfn && no_stdlib())
|
||||
{
|
||||
compiler.context.benchmark_func = NULL;
|
||||
return;
|
||||
}
|
||||
const char *testfn = compiler.build.benchfn ? compiler.build.benchfn : "std::core::runtime::default_benchmark_runner";
|
||||
@@ -407,12 +425,15 @@ static void assign_benchfn(void)
|
||||
{
|
||||
error_exit("'%s::%s' is not a function.", path->module, ident);
|
||||
}
|
||||
if (!type_func_match(type_get_func_ptr(decl->type->canonical), type_bool, 0))
|
||||
if (!type_func_match(type_get_func_ptr(decl->type->canonical), type_bool, 1, type_get_slice(type_string)))
|
||||
{
|
||||
error_exit("Expected benchmark function to have the signature fn void().");
|
||||
error_exit("Expected benchmark function to have the signature fn bool(String[] args).");
|
||||
}
|
||||
compiler.context.benchmark_func = decl;
|
||||
decl->no_strip = true;
|
||||
if (!setup_main_runner(decl))
|
||||
{
|
||||
error_exit("Failed to set up benchmark runner.");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user