fix(ci): fix tests

This commit is contained in:
2026-07-23 19:30:39 +08:00
parent 574ba8b6d0
commit d10ec84004
2 changed files with 35 additions and 31 deletions

View File

@@ -501,7 +501,11 @@ fn parse_d_file(content: &str) -> Vec<String> {
} }
in_escape = false; in_escape = false;
} else if c == '\\' { } 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() { } else if c.is_whitespace() {
if !current_path.is_empty() { if !current_path.is_empty() {
deps.push(current_path.clone()); deps.push(current_path.clone());
@@ -911,36 +915,25 @@ mod tests {
fs::write(&header, "#define A 1").unwrap(); fs::write(&header, "#define A 1").unwrap();
fs::write(&obj, "").unwrap(); fs::write(&obj, "").unwrap();
let past = SystemTime::now() - Duration::from_secs(30); let past = SystemTime::UNIX_EPOCH + Duration::from_secs(1_000_000);
let now = SystemTime::now(); let mid = past + Duration::from_secs(100);
let future = now + Duration::from_secs(30); let future = mid + Duration::from_secs(100);
let past_t = FileTimes::new().set_modified(past); for (path, t) in [(&src, past), (&header, past), (&obj, mid)] {
let times = FileTimes::new().set_modified(t);
File::options() File::options()
.write(true) .write(true)
.open(&src) .open(path)
.unwrap() .unwrap()
.set_times(past_t) .set_times(times)
.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(); .unwrap();
}
let d_content = format!( let d_content = format!(
"{}: {} {}", "{}: {} {}",
obj.to_string_lossy(), obj.to_string_lossy().replace('\\', "/"),
src.to_string_lossy(), src.to_string_lossy().replace('\\', "/"),
header.to_string_lossy() header.to_string_lossy().replace('\\', "/")
); );
fs::write(&d_file, d_content).unwrap(); fs::write(&d_file, d_content).unwrap();
@@ -949,12 +942,12 @@ mod tests {
"should be fresh" "should be fresh"
); );
let future_t = FileTimes::new().set_modified(future); let times = FileTimes::new().set_modified(future);
File::options() File::options()
.write(true) .write(true)
.open(&header) .open(&header)
.unwrap() .unwrap()
.set_times(future_t) .set_times(times)
.unwrap(); .unwrap();
assert!( 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] #[test]
fn asm_lang_flag_returns_correct_flag() { fn asm_lang_flag_returns_correct_flag() {
assert_eq!(asm_lang_flag("foo.S"), Some("assembler-with-cpp")); assert_eq!(asm_lang_flag("foo.S"), Some("assembler-with-cpp"));

View File

@@ -131,10 +131,14 @@ fn build_with_target_config() {
"dcr build with target = \"linux\" should succeed" "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!( assert!(
artifact.is_file(), 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 project_name
); );
} }