mirror of
https://github.com/dexoron/dcr.git
synced 2026-10-21 12:38:30 +00:00
fix(ci): fix tests
This commit is contained in:
@@ -902,58 +902,38 @@ mod tests {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn needs_rebuild_header_modified() {
|
fn needs_rebuild_header_modified() {
|
||||||
use std::fs::{File, FileTimes};
|
|
||||||
use std::time::{Duration, SystemTime};
|
|
||||||
|
|
||||||
let dir = temp_dir("rebuild_header");
|
let dir = temp_dir("rebuild_header");
|
||||||
let src = dir.join("test.c");
|
fs::write(dir.join("test.c"), "int main() {}").unwrap();
|
||||||
let header = dir.join("test.h");
|
fs::write(dir.join("test.h"), "#define A 1").unwrap();
|
||||||
let obj = dir.join("test.o");
|
fs::write(dir.join("test.o"), "").unwrap();
|
||||||
let d_file = dir.join("test.d");
|
|
||||||
|
|
||||||
fs::write(&src, "int main() {}").unwrap();
|
let _guard = cwd_lock();
|
||||||
fs::write(&header, "#define A 1").unwrap();
|
let prev = std::env::current_dir().unwrap();
|
||||||
fs::write(&obj, "").unwrap();
|
std::env::set_current_dir(&dir).unwrap();
|
||||||
|
|
||||||
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);
|
|
||||||
|
|
||||||
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().replace('\\', "/"),
|
|
||||||
src.to_string_lossy().replace('\\', "/"),
|
|
||||||
header.to_string_lossy().replace('\\', "/")
|
|
||||||
);
|
|
||||||
fs::write(&d_file, d_content).unwrap();
|
|
||||||
|
|
||||||
|
fs::write("test.d", "test.o: test.c missing.h").unwrap();
|
||||||
assert!(
|
assert!(
|
||||||
!needs_rebuild(&src.to_string_lossy(), &obj.to_string_lossy()),
|
needs_rebuild("test.c", "test.o"),
|
||||||
"should be fresh"
|
"missing dep in .d must force rebuild"
|
||||||
);
|
);
|
||||||
|
|
||||||
let times = FileTimes::new().set_modified(future);
|
fs::write("test.h", "#define A 1").unwrap();
|
||||||
File::options()
|
std::thread::sleep(std::time::Duration::from_secs(2));
|
||||||
.write(true)
|
fs::write("test.o", "obj").unwrap();
|
||||||
.open(&header)
|
fs::write("test.d", "test.o: test.c test.h").unwrap();
|
||||||
.unwrap()
|
|
||||||
.set_times(times)
|
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
assert!(
|
assert!(
|
||||||
needs_rebuild(&src.to_string_lossy(), &obj.to_string_lossy()),
|
!needs_rebuild("test.c", "test.o"),
|
||||||
|
"object newer than source and headers should be fresh"
|
||||||
|
);
|
||||||
|
|
||||||
|
std::thread::sleep(std::time::Duration::from_secs(2));
|
||||||
|
fs::write("test.h", "#define A 2").unwrap();
|
||||||
|
assert!(
|
||||||
|
needs_rebuild("test.c", "test.o"),
|
||||||
"changed header should trigger rebuild"
|
"changed header should trigger rebuild"
|
||||||
);
|
);
|
||||||
|
|
||||||
|
std::env::set_current_dir(prev).unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
|||||||
@@ -304,19 +304,20 @@ fn staticlib_build() {
|
|||||||
let envs = [("DCR_COMPILER", compiler)];
|
let envs = [("DCR_COMPILER", compiler)];
|
||||||
let out = run_dcr_env(&["build"], &dir, &envs);
|
let out = run_dcr_env(&["build"], &dir, &envs);
|
||||||
assert!(out.status.success(), "staticlib build should succeed");
|
assert!(out.status.success(), "staticlib build should succeed");
|
||||||
// Check that a .a file exists
|
let lib_path = host_profile_dir(&dir, "debug");
|
||||||
let lib_path = dir
|
|
||||||
.join("target")
|
|
||||||
.join("x86_64-unknown-linux-gnu")
|
|
||||||
.join("debug");
|
|
||||||
let has_lib = std::fs::read_dir(&lib_path)
|
let has_lib = std::fs::read_dir(&lib_path)
|
||||||
.map(|entries| {
|
.map(|entries| {
|
||||||
entries
|
entries.filter_map(|e| e.ok()).any(|e| {
|
||||||
.filter_map(|e| e.ok())
|
let name = e.file_name().to_string_lossy().to_string();
|
||||||
.any(|e| e.file_name().to_string_lossy().ends_with(".a"))
|
name.ends_with(".a") || name.ends_with(".lib")
|
||||||
|
})
|
||||||
})
|
})
|
||||||
.unwrap_or(false);
|
.unwrap_or(false);
|
||||||
assert!(has_lib, "staticlib should produce a .a file");
|
assert!(
|
||||||
|
has_lib,
|
||||||
|
"staticlib should produce a .a/.lib in {}",
|
||||||
|
lib_path.display()
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
@@ -332,12 +333,11 @@ fn build_release_profile() {
|
|||||||
let envs = [("DCR_COMPILER", compiler)];
|
let envs = [("DCR_COMPILER", compiler)];
|
||||||
let out = run_dcr_env(&["build", "--release"], &dir, &envs);
|
let out = run_dcr_env(&["build", "--release"], &dir, &envs);
|
||||||
assert!(out.status.success(), "release build should succeed");
|
assert!(out.status.success(), "release build should succeed");
|
||||||
|
let release_dir = host_profile_dir(&dir, "release");
|
||||||
assert!(
|
assert!(
|
||||||
dir.join("target")
|
release_dir.is_dir(),
|
||||||
.join("x86_64-unknown-linux-gnu")
|
"release profile dir should exist: {}",
|
||||||
.join("release")
|
release_dir.display()
|
||||||
.is_dir(),
|
|
||||||
"target/x86_64-unknown-linux-gnu/release should exist"
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user