preserve application and error inference in test builds
This commit is contained in:
+16
-3
@@ -165,20 +165,28 @@ append_runner :: proc(
|
||||
diagnostics: ^source.Diagnostics,
|
||||
symbols: ^symbol.Table,
|
||||
testing_pkg: ast.Package_Id,
|
||||
testing_error: types.Type,
|
||||
tests: []Test_Entry,
|
||||
) {
|
||||
builder := strings.builder_make(module.allocator)
|
||||
defer strings.builder_destroy(&builder)
|
||||
for entry, index in tests {
|
||||
test := module.functions[entry.function]
|
||||
alias := fmt.tprintf("__brolang_test_%d", index)
|
||||
fmt.sbprintf(&builder, "hide __brolang_test_adapter_%d func() void ! __brolang_testing.Error ", index)
|
||||
strings.write_string(&builder, "{\n\t")
|
||||
fmt.sbprintf(&builder, "%s.%s() catch |_| ", alias, symbol.resolve(symbols, test.name))
|
||||
strings.write_string(&builder, "{\n\t\treturn .expectation_failed\n\t}\n}\n\n")
|
||||
}
|
||||
strings.write_string(&builder, "main func() i32 {\n\tfailed i32 = 0\n")
|
||||
for entry, index in tests {
|
||||
test_id := entry.function
|
||||
test := module.functions[test_id]
|
||||
pkg := module.packages[test.pkg]
|
||||
alias := fmt.tprintf("__brolang_test_%d", index)
|
||||
name := fmt.tprintf("%s.%s", filepath.base(pkg.path), symbol.resolve(symbols, test.name))
|
||||
strings.write_string(&builder, "\tif (!__brolang_testing.run(\"")
|
||||
write_brolang_string(&builder, name)
|
||||
fmt.sbprintf(&builder, "\", %s.%s)) ", alias, symbol.resolve(symbols, test.name))
|
||||
fmt.sbprintf(&builder, "\", __brolang_test_adapter_%d)) ", index)
|
||||
strings.write_string(&builder, "{\n\t\tfailed += 1\n\t}\n")
|
||||
}
|
||||
fmt.sbprintf(&builder, "\t__brolang_testing.summary(%d - failed, failed)\n", len(tests))
|
||||
@@ -190,7 +198,11 @@ append_runner :: proc(
|
||||
append(&module.files, ast.File{source=source_id, pkg=0})
|
||||
stream := lexer.lex(&sources.items[source_id], diagnostics, symbols, module.allocator)
|
||||
defer delete(stream.items)
|
||||
function_start := len(module.functions)
|
||||
parser.parse_into(&stream, &sources.items[source_id], diagnostics, module, 0, file_id)
|
||||
for index in 0..<len(tests) {
|
||||
module.functions[function_start+index].error = testing_error
|
||||
}
|
||||
|
||||
append(&module.imports, ast.Import{
|
||||
alias=symbol.intern(symbols, "__brolang_testing"),
|
||||
@@ -271,11 +283,12 @@ prepare_tests :: proc(
|
||||
}
|
||||
} else if function.pkg == 0 && function.name == main_name {
|
||||
function.generated = true
|
||||
function.analysis_root = true
|
||||
}
|
||||
}
|
||||
|
||||
slice.sort_by(tests[:], test_entry_less)
|
||||
inject_assertion_locations(module, sources, symbols, testing_pkg)
|
||||
append_runner(module, sources, diagnostics, symbols, testing_pkg, tests[:])
|
||||
append_runner(module, sources, diagnostics, symbols, testing_pkg, error_type, tests[:])
|
||||
return true
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user