Skip to main content

build_test_binary

Function build_test_binary 

Source
pub fn build_test_binary(path: &Path) -> Result<(PathBuf, Vec<TestFn>)>
Expand description

Compile path as a test binary (nova test, Task 5): main is synthesized to dispatch to exactly one collected @test by index (Builtin::TestSelector) rather than to the file’s own main — a test file need not define one, since a missing main is enforced only at MIR lowering (E0601 in nova_mir::lower_module), which the synthesized function supplies before that check ever runs.

If the source does declare its own main, that function is renamed (never removed — something else in the module may still call it by DefId) before the synthesized dispatcher is pushed, so the dispatcher is the only function left named "main". This matters because nova-mir/src/mono.rs’s entry-point search is module.functions.iter().find(|f| f.name == "main") — the first match — while pushing onto module.functions puts the dispatcher last: without the rename, a source file with both @test functions and its own main would silently run the user’s main instead of any test, compiling and linking cleanly with no diagnostic anywhere.

Returns the built executable’s path and the collected tests in source order, so a caller can run the binary once per test with NOVA_TEST_INDEX set without recompiling or re-deriving either the path or the inventory from the source again.