diff --git a/kitc/tests/examples.rs b/kitc/tests/examples.rs index bc670d7..7dde17f 100644 --- a/kitc/tests/examples.rs +++ b/kitc/tests/examples.rs @@ -1,5 +1,4 @@ use assert_cmd::{Command as AssertCommand, cargo::*}; -use predicates::prelude::*; use std::{path::Path, process::Command, sync::OnceLock}; static LOGGER_INIT: OnceLock<()> = OnceLock::new(); @@ -10,6 +9,10 @@ fn setup_logging() { }); } +fn normalize_line_endings(s: &str) -> String { + s.replace("\r\n", "\n") +} + const MANIFEST_DIR: &str = env!("CARGO_MANIFEST_DIR"); fn run_example_test( @@ -68,15 +71,18 @@ fn run_example_test( let expected_output_path = workspace_root.join(expected_file); log::info!("Expected output: {}", expected_output_path.display()); let expected_output = std::fs::read_to_string(expected_output_path)?; + let expected_normalized = normalize_line_endings(&expected_output); - // Assert the output - compiled_cmd - .assert() - .stdout(predicate::eq(expected_output.as_str())) - .success(); + // Run the compiled executable, capture output, normalize line endings, compare + let output = compiled_cmd.assert().success().get_output().stdout.clone(); + + let actual = String::from_utf8_lossy(&output).replace("\r\n", "\n"); + assert_eq!( + actual, expected_normalized, + "stdout did not match expected output" + ); - // 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. + // Clean up generated files if let Err(err) = std::fs::remove_file(&executable_path) { log::error!("Failed to remove executable: {err}"); }