fix(ci): fix tests

This commit is contained in:
2026-07-23 19:53:24 +08:00
parent 594007f022
commit 5aefbc6498
2 changed files with 66 additions and 20 deletions

View File

@@ -126,20 +126,27 @@ fn build_with_target_config() {
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);
if !out.status.success() {
eprintln!("stdout: {}", String::from_utf8_lossy(&out.stdout));
eprintln!("stderr: {}", String::from_utf8_lossy(&out.stderr));
if cfg!(windows) {
eprintln!("skipping linux-target path assert: build failed (no linux cross toolchain)");
return;
}
}
assert!( assert!(
out.status.success(), out.status.success(),
"dcr build with target = \"linux\" should succeed" "dcr build with target = \"linux\" should succeed"
); );
let artifact = dir let out_dir = dir
.join("target") .join("target")
.join("x86_64-unknown-linux-gnu") .join("x86_64-unknown-linux-gnu")
.join("debug") .join("debug");
.join(&project_name); assert_artifact_in(
assert!( &out_dir,
artifact.is_file(), &project_name,
"artifact should be at target/x86_64-unknown-linux-gnu/debug/{} (build.target=linux), got missing; dir listing may differ on host", "build.target=linux should place artifact under target/x86_64-unknown-linux-gnu/debug",
project_name
); );
} }
@@ -171,11 +178,10 @@ fn build_with_out_dir() {
"dcr build with out_dir should succeed" "dcr build with out_dir should succeed"
); );
let artifact = dir.join("_BUILD").join(&project_name); assert_artifact_in(
assert!( &dir.join("_BUILD"),
artifact.is_file(), &project_name,
"artifact should be at _BUILD/{} (custom out_dir)", "artifact should be under custom out_dir _BUILD",
project_name
); );
let default_path = default_artifact_path(&dir, &project_name); let default_path = default_artifact_path(&dir, &project_name);
@@ -260,13 +266,23 @@ fn package_build_target_used_without_cli_flag() {
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);
if !out.status.success() {
eprintln!("stdout: {}", String::from_utf8_lossy(&out.stdout));
eprintln!("stderr: {}", String::from_utf8_lossy(&out.stderr));
if cfg!(windows) {
eprintln!("skipping linux-target path assert: build failed (no linux cross toolchain)");
return;
}
}
assert!(out.status.success(), "build should use package target"); assert!(out.status.success(), "build should use package target");
let artifact = dir let out_dir = dir
.join("target/x86_64-unknown-linux-gnu/debug") .join("target")
.join(&project_name); .join("x86_64-unknown-linux-gnu")
assert!( .join("debug");
artifact.is_file(), assert_artifact_in(
"artifact should be under package build.target path" &out_dir,
&project_name,
"artifact should be under package build.target path",
); );
} }

View File

@@ -119,6 +119,36 @@ pub fn host_profile_dir(project_root: &Path, profile: &str) -> PathBuf {
} }
#[allow(dead_code)] #[allow(dead_code)]
pub fn default_artifact_path(project_root: &Path, project_name: &str) -> PathBuf { pub fn bin_name(project_name: &str) -> String {
host_profile_dir(project_root, "debug").join(project_name) if cfg!(windows) {
format!("{project_name}.exe")
} else {
project_name.to_string()
}
}
#[allow(dead_code)]
pub fn default_artifact_path(project_root: &Path, project_name: &str) -> PathBuf {
host_profile_dir(project_root, "debug").join(bin_name(project_name))
}
#[allow(dead_code)]
pub fn artifact_candidates(dir: &Path, project_name: &str) -> Vec<PathBuf> {
let base = bin_name(project_name);
let bare = project_name.to_string();
vec![
dir.join(&base),
dir.join(&bare),
dir.join(format!("{project_name}.exe")),
]
}
#[allow(dead_code)]
pub fn assert_artifact_in(dir: &Path, project_name: &str, ctx: &str) {
let candidates = artifact_candidates(dir, project_name);
assert!(
candidates.iter().any(|p| p.is_file()),
"{ctx}: expected binary in {}, candidates: {candidates:?}",
dir.display()
);
} }