From 86cc82991ff14b20dee07ff904d399aa7b4927db Mon Sep 17 00:00:00 2001 From: winlogon Date: Sat, 28 Feb 2026 16:09:58 +0100 Subject: [PATCH 1/2] fix(tests): fix Windows test failures due to newline differences On Windows, compiled programs output CRLF line endings (\r\n), but expected files use LF (\n), causing test failures. This fix normalizes the expected output before comparison by converting all line endings to LF, making tests pass on both Windows and Unix. --- kitc/tests/examples.rs | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/kitc/tests/examples.rs b/kitc/tests/examples.rs index bc670d7..c5bbfdc 100644 --- a/kitc/tests/examples.rs +++ b/kitc/tests/examples.rs @@ -1,4 +1,4 @@ -use assert_cmd::{Command as AssertCommand, cargo::*}; +use assert_cmd::{cargo::*, Command as AssertCommand}; use predicates::prelude::*; use std::{path::Path, process::Command, sync::OnceLock}; @@ -10,6 +10,10 @@ fn setup_logging() { }); } +fn normalize_line_endings(s: &str) -> String { + s.replace("\r\n", "\n").replace("\r", "\n") +} + const MANIFEST_DIR: &str = env!("CARGO_MANIFEST_DIR"); fn run_example_test( @@ -68,11 +72,12 @@ 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())) + .stdout(predicate::eq(expected_normalized.as_str())) .success(); // TODO: executable files are actually generated in the CWD, not in the examples folder. From 846558396397ad6dfd4f36b7f1e9c3d4d1e6bdc8 Mon Sep 17 00:00:00 2001 From: winlogon Date: Tue, 17 Mar 2026 13:45:06 +0100 Subject: [PATCH 2/2] fix: improve output comparison in examples test Refactor output assertion and normalize line endings. --- kitc/tests/examples.rs | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/kitc/tests/examples.rs b/kitc/tests/examples.rs index c5bbfdc..7dde17f 100644 --- a/kitc/tests/examples.rs +++ b/kitc/tests/examples.rs @@ -1,5 +1,4 @@ -use assert_cmd::{cargo::*, Command as AssertCommand}; -use predicates::prelude::*; +use assert_cmd::{Command as AssertCommand, cargo::*}; use std::{path::Path, process::Command, sync::OnceLock}; static LOGGER_INIT: OnceLock<()> = OnceLock::new(); @@ -11,7 +10,7 @@ fn setup_logging() { } fn normalize_line_endings(s: &str) -> String { - s.replace("\r\n", "\n").replace("\r", "\n") + s.replace("\r\n", "\n") } const MANIFEST_DIR: &str = env!("CARGO_MANIFEST_DIR"); @@ -74,14 +73,16 @@ fn run_example_test( 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_normalized.as_str())) - .success(); + // Run the compiled executable, capture output, normalize line endings, compare + let output = compiled_cmd.assert().success().get_output().stdout.clone(); - // 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. + let actual = String::from_utf8_lossy(&output).replace("\r\n", "\n"); + assert_eq!( + actual, expected_normalized, + "stdout did not match expected output" + ); + + // Clean up generated files if let Err(err) = std::fs::remove_file(&executable_path) { log::error!("Failed to remove executable: {err}"); }