Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 9 additions & 7 deletions kitc/tests/examples.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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(())
}
Expand Down