diff --git a/kitc/tests/examples.rs b/kitc/tests/examples.rs index d2690f9..4aca461 100644 --- a/kitc/tests/examples.rs +++ b/kitc/tests/examples.rs @@ -46,12 +46,18 @@ fn run_example_test( ); let source_path = workspace_root.join(example_file); - let c_path = source_path.with_extension("c"); - let executable_path = source_path.with_extension(""); + let ext = if cfg!(windows) { "exe" } else { "" }; + let executable_path = source_path.with_extension(ext); // Compile the example let kitc = cargo_bin!("kitc"); log::info!("kitc path: {}", kitc.display()); + + // Note: C file cleanup is handled by the compiler itself (see frontend.rs). + // SAFETY: these unit tests are single-threaded, so no race conditions + // unsafe { + // std::env::set_var("KEEP_C", ""); + // } let mut cmd = AssertCommand::from_std(Command::new(kitc)); // Run from workspace root @@ -75,14 +81,10 @@ fn run_example_test( .stdout(predicate::eq(expected_output.as_str())) .success(); - // TODO: executable files are actually generated in the CWD, not in the examples folder. - // This explains why the executable is not actually generated in the examples folder. + // Cleanup generated files if let Err(err) = std::fs::remove_file(&executable_path) { log::error!("Failed to remove executable: {err}"); } - if let Err(err) = std::fs::remove_file(&c_path) { - log::error!("Failed to remove C source file: {err}"); - } Ok(()) }