From d10ec84004d468ce96d5dfa8659f39758863cb94 Mon Sep 17 00:00:00 2001 From: Dexoron Date: Thu, 23 Jul 2026 19:30:39 +0800 Subject: [PATCH] fix(ci): fix tests --- src/core/build/common.rs | 58 ++++++++++++++++++++-------------------- tests/cli_build.rs | 8 ++++-- 2 files changed, 35 insertions(+), 31 deletions(-) diff --git a/src/core/build/common.rs b/src/core/build/common.rs index 4e5bce5..eba4ca6 100644 --- a/src/core/build/common.rs +++ b/src/core/build/common.rs @@ -501,7 +501,11 @@ fn parse_d_file(content: &str) -> Vec { } in_escape = false; } else if c == '\\' { - in_escape = true; + match chars.peek() { + Some('\n' | '\r' | ' ' | '\t' | '\\') => in_escape = true, + Some(_) => current_path.push('\\'), + None => current_path.push('\\'), + } } else if c.is_whitespace() { if !current_path.is_empty() { deps.push(current_path.clone()); @@ -911,36 +915,25 @@ mod tests { fs::write(&header, "#define A 1").unwrap(); fs::write(&obj, "").unwrap(); - let past = SystemTime::now() - Duration::from_secs(30); - let now = SystemTime::now(); - let future = now + Duration::from_secs(30); + let past = SystemTime::UNIX_EPOCH + Duration::from_secs(1_000_000); + let mid = past + Duration::from_secs(100); + let future = mid + Duration::from_secs(100); - let past_t = FileTimes::new().set_modified(past); - File::options() - .write(true) - .open(&src) - .unwrap() - .set_times(past_t) - .unwrap(); - File::options() - .write(true) - .open(&header) - .unwrap() - .set_times(past_t) - .unwrap(); - let now_t = FileTimes::new().set_modified(now); - File::options() - .write(true) - .open(&obj) - .unwrap() - .set_times(now_t) - .unwrap(); + for (path, t) in [(&src, past), (&header, past), (&obj, mid)] { + let times = FileTimes::new().set_modified(t); + File::options() + .write(true) + .open(path) + .unwrap() + .set_times(times) + .unwrap(); + } let d_content = format!( "{}: {} {}", - obj.to_string_lossy(), - src.to_string_lossy(), - header.to_string_lossy() + obj.to_string_lossy().replace('\\', "/"), + src.to_string_lossy().replace('\\', "/"), + header.to_string_lossy().replace('\\', "/") ); fs::write(&d_file, d_content).unwrap(); @@ -949,12 +942,12 @@ mod tests { "should be fresh" ); - let future_t = FileTimes::new().set_modified(future); + let times = FileTimes::new().set_modified(future); File::options() .write(true) .open(&header) .unwrap() - .set_times(future_t) + .set_times(times) .unwrap(); assert!( @@ -963,6 +956,13 @@ mod tests { ); } + #[test] + fn parse_d_file_keeps_windows_path_separators() { + let content = r"target\obj\main.obj: src\main.c src\utils.h"; + let deps = parse_d_file(content); + assert_eq!(deps, vec![r"src\main.c", r"src\utils.h"]); + } + #[test] fn asm_lang_flag_returns_correct_flag() { assert_eq!(asm_lang_flag("foo.S"), Some("assembler-with-cpp")); diff --git a/tests/cli_build.rs b/tests/cli_build.rs index 28e1eef..1b1bc4d 100644 --- a/tests/cli_build.rs +++ b/tests/cli_build.rs @@ -131,10 +131,14 @@ fn build_with_target_config() { "dcr build with target = \"linux\" should succeed" ); - let artifact = default_artifact_path(&dir, &project_name); + let artifact = dir + .join("target") + .join("x86_64-unknown-linux-gnu") + .join("debug") + .join(&project_name); assert!( artifact.is_file(), - "artifact should be at default path target/x86_64-unknown-linux-gnu/debug/{}", + "artifact should be at target/x86_64-unknown-linux-gnu/debug/{} (build.target=linux), got missing; dir listing may differ on host", project_name ); }