@@ -11496,6 +11496,13 @@ lbValue lb_find_runtime_value(lbModule *m, String const &name) {
1149611496 lbValue value = *found;
1149711497 return value;
1149811498}
11499+ lbValue lb_find_package_value (lbModule *m, String const &pkg, String const &name) {
11500+ Entity *e = find_entity_in_pkg (m->info , pkg, name);
11501+ lbValue *found = map_get (&m->values , hash_entity (e));
11502+ GB_ASSERT_MSG (found != nullptr , " Unable to find value '%.*s.%.*s'" , LIT (pkg), LIT (name));
11503+ lbValue value = *found;
11504+ return value;
11505+ }
1149911506
1150011507lbValue lb_get_type_info_ptr (lbModule *m, Type *type) {
1150111508 i32 index = cast (i32 )lb_type_info_index (m->info , type);
@@ -12885,12 +12892,51 @@ void lb_generate_code(lbGenerator *gen) {
1288512892 LLVMBuildCall2 (p->builder , LLVMGetElementType (lb_type (m, startup_runtime->type )), startup_runtime->value , nullptr , 0 , " " );
1288612893
1288712894 if (build_context.command_kind == Command_test) {
12895+ Type *t_Internal_Test = find_type_in_pkg (m->info , str_lit (" testing" ), str_lit (" Internal_Test" ));
12896+ Type *array_type = alloc_type_array (t_Internal_Test, m->info ->testing_procedures .count );
12897+ Type *slice_type = alloc_type_slice (t_Internal_Test);
12898+ lbAddr all_tests_array_addr = lb_add_global_generated (p->module , array_type, {});
12899+ lbValue all_tests_array = lb_addr_get_ptr (p, all_tests_array_addr);
12900+
12901+ LLVMTypeRef lbt_Internal_Test = lb_type (m, t_Internal_Test);
12902+
12903+ LLVMValueRef indices[2 ] = {};
12904+ indices[0 ] = LLVMConstInt (lb_type (m, t_i32), 0 , false );
12905+
1288812906 for_array (i, m->info ->testing_procedures ) {
12889- Entity *e = m->info ->testing_procedures [i];
12890- lbValue *found = map_get (&m->values , hash_entity (e));
12907+ Entity *testing_proc = m->info ->testing_procedures [i];
12908+ String name = testing_proc->token .string ;
12909+ lbValue *found = map_get (&m->values , hash_entity (testing_proc));
1289112910 GB_ASSERT (found != nullptr );
12892- lb_emit_call (p, *found, {});
12911+
12912+ lbValue v_name = lb_find_or_add_entity_string (m, name);
12913+ lbValue v_proc = *found;
12914+
12915+ indices[1 ] = LLVMConstInt (lb_type (m, t_int), i, false );
12916+
12917+ LLVMValueRef vals[2 ] = {};
12918+ vals[0 ] = v_name.value ;
12919+ vals[1 ] = v_proc.value ;
12920+ GB_ASSERT (LLVMIsConstant (vals[0 ]));
12921+ GB_ASSERT (LLVMIsConstant (vals[1 ]));
12922+
12923+ LLVMValueRef dst = LLVMConstInBoundsGEP (all_tests_array.value , indices, gb_count_of (indices));
12924+ LLVMValueRef src = LLVMConstNamedStruct (lbt_Internal_Test, vals, gb_count_of (vals));
12925+
12926+ LLVMBuildStore (p->builder , src, dst);
1289312927 }
12928+
12929+ lbAddr all_tests_slice = lb_add_local_generated (p, slice_type, true );
12930+ lb_fill_slice (p, all_tests_slice,
12931+ lb_array_elem (p, all_tests_array),
12932+ lb_const_int (m, t_int, m->info ->testing_procedures .count ));
12933+
12934+
12935+ lbValue runner = lb_find_package_value (m, str_lit (" testing" ), str_lit (" runner" ));
12936+
12937+ auto args = array_make<lbValue>(heap_allocator (), 1 );
12938+ args[0 ] = lb_addr_load (p, all_tests_slice);
12939+ lb_emit_call (p, runner, args);
1289412940 } else {
1289512941 lbValue *found = map_get (&m->values , hash_entity (entry_point));
1289612942 GB_ASSERT (found != nullptr );
0 commit comments