Merge pull request #3141 from laytan/add-all-packages-flag-for-tests

Add `odin test -all-packages` to be able to test an entire project
This commit is contained in:
gingerBill
2024-01-31 11:59:54 +00:00
committed by GitHub
3 changed files with 49 additions and 34 deletions

View File

@@ -423,6 +423,7 @@ struct BuildContext {
Array<String> extra_packages;
StringSet test_names;
bool test_all_packages;
gbAffinity affinity;
isize thread_count;

View File

@@ -2368,6 +2368,43 @@ gb_internal void force_add_dependency_entity(Checker *c, Scope *scope, String co
add_dependency_to_set(c, e);
}
gb_internal void collect_testing_procedures_of_package(Checker *c, AstPackage *pkg) {
AstPackage *testing_package = get_core_package(&c->info, str_lit("testing"));
Scope *testing_scope = testing_package->scope;
Entity *test_signature = scope_lookup_current(testing_scope, str_lit("Test_Signature"));
Scope *s = pkg->scope;
for (auto const &entry : s->elements) {
Entity *e = entry.value;
if (e->kind != Entity_Procedure) {
continue;
}
if ((e->flags & EntityFlag_Test) == 0) {
continue;
}
String name = e->token.string;
bool is_tester = true;
Type *t = base_type(e->type);
GB_ASSERT(t->kind == Type_Proc);
if (are_types_identical(t, base_type(test_signature->type))) {
// Good
} else {
gbString str = type_to_string(t);
error(e->token, "Testing procedures must have a signature type of proc(^testing.T), got %s", str);
gb_string_free(str);
is_tester = false;
}
if (is_tester) {
add_dependency_to_set(c, e);
array_add(&c->info.testing_procedures, e);
}
}
}
gb_internal void generate_minimum_dependency_set_internal(Checker *c, Entity *start) {
for_array(i, c->info.definitions) {
@@ -2471,41 +2508,13 @@ gb_internal void generate_minimum_dependency_set_internal(Checker *c, Entity *st
}
}
Entity *test_signature = scope_lookup_current(testing_scope, str_lit("Test_Signature"));
AstPackage *pkg = c->info.init_package;
Scope *s = pkg->scope;
collect_testing_procedures_of_package(c, pkg);
for (auto const &entry : s->elements) {
Entity *e = entry.value;
if (e->kind != Entity_Procedure) {
continue;
}
if ((e->flags & EntityFlag_Test) == 0) {
continue;
}
String name = e->token.string;
bool is_tester = true;
Type *t = base_type(e->type);
GB_ASSERT(t->kind == Type_Proc);
if (are_types_identical(t, base_type(test_signature->type))) {
// Good
} else {
gbString str = type_to_string(t);
error(e->token, "Testing procedures must have a signature type of proc(^testing.T), got %s", str);
gb_string_free(str);
is_tester = false;
}
if (is_tester) {
add_dependency_to_set(c, e);
array_add(&c->info.testing_procedures, e);
if (build_context.test_all_packages) {
for (auto const &entry : c->info.packages) {
AstPackage *pkg = entry.value;
collect_testing_procedures_of_package(c, pkg);
}
}
} else if (start != nullptr) {

View File

@@ -473,7 +473,7 @@ gb_internal bool parse_build_flags(Array<String> args) {
add_flag(&build_flags, BuildFlag_ObfuscateSourceCodeLocations, str_lit("obfuscate-source-code-locations"), BuildFlagParam_None, Command__does_build);
add_flag(&build_flags, BuildFlag_Short, str_lit("short"), BuildFlagParam_None, Command_doc);
add_flag(&build_flags, BuildFlag_AllPackages, str_lit("all-packages"), BuildFlagParam_None, Command_doc);
add_flag(&build_flags, BuildFlag_AllPackages, str_lit("all-packages"), BuildFlagParam_None, Command_doc | Command_test);
add_flag(&build_flags, BuildFlag_DocFormat, str_lit("doc-format"), BuildFlagParam_None, Command_doc);
add_flag(&build_flags, BuildFlag_IgnoreWarnings, str_lit("ignore-warnings"), BuildFlagParam_None, Command_all);
@@ -1149,6 +1149,7 @@ gb_internal bool parse_build_flags(Array<String> args) {
break;
case BuildFlag_AllPackages:
build_context.cmd_doc_flags |= CmdDocFlag_AllPackages;
build_context.test_all_packages = true;
break;
case BuildFlag_DocFormat:
build_context.cmd_doc_flags |= CmdDocFlag_DocFormat;
@@ -1908,6 +1909,10 @@ gb_internal void print_show_help(String const arg0, String const &command) {
print_usage_line(1, "-test-name:<string>");
print_usage_line(2, "Runs specific test only by name.");
print_usage_line(0, "");
print_usage_line(1, "-all-packages");
print_usage_line(2, "Tests all packages imported into the given initial package.");
print_usage_line(0, "");
}
if (run_or_build) {