Skip to content

Commit

Permalink
Also target-platform
Browse files Browse the repository at this point in the history
  • Loading branch information
pavelzw committed Jan 24, 2024
1 parent 8f24b81 commit 56f6a4d
Showing 1 changed file with 37 additions and 30 deletions.
67 changes: 37 additions & 30 deletions rust-tests/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,29 +34,31 @@ mod tests {
RattlerBuild::WithBinary(binary) => Command::new(binary),
}
}
fn build<K: AsRef<Path>, T: AsRef<Path>, N: AsRef<Path>>(
fn build<K: AsRef<Path>, T: AsRef<Path>, N: AsRef<Path>, L: AsRef<str>>(
&self,
recipe: K,
output_dir: T,
variant_config: Option<N>,
target_platform: Option<L>
) -> std::io::Result<Output> {
let rs = recipe.as_ref().display().to_string();
let od = output_dir.as_ref().display().to_string();
let iter = [
"build",
"--recipe",
rs.as_str(),
"--output-dir",
od.as_str(),
let mut args = vec![
"build".to_string(),
"--recipe".to_string(),
rs,
"--output-dir".to_string(),
od.to_string(),
];
if let Some(variant_config_path) = variant_config {
self.with_args(iter.into_iter().chain([
"--variant-config",
variant_config_path.as_ref().display().to_string().as_str(),
]))
} else {
self.with_args(iter)
let vcp = variant_config_path.as_ref().display().to_string();
args.extend_from_slice(&["--variant-config".to_string(), vcp]);
}
if let Some(target_platform) = target_platform {
let tp = target_platform.as_ref().to_string();
args.extend_from_slice(&["--target-platform".to_string(), tp]);
}
self.with_args(args)
}
fn with_args(
&self,
Expand Down Expand Up @@ -195,7 +197,7 @@ mod tests {
let recipes = recipes();
let tmp = tmp("test_run_exports_from");
let rattler_build =
rattler().build::<_, _, &str>(recipes.join("run_exports_from"), tmp.as_dir(), None);
rattler().build::<_, _, &str, &str>(recipes.join("run_exports_from"), tmp.as_dir(), None, None);
// ensure rattler build succeeded
assert!(rattler_build.is_ok());
let pkg = get_extracted_package(tmp.as_dir(), "run_exports_test");
Expand All @@ -218,7 +220,7 @@ mod tests {
let recipes = recipes();
let tmp = tmp("test_run_exports");
let rattler_build =
rattler().build::<_, _, &str>(recipes.join("run_exports"), tmp.as_dir(), None);
rattler().build::<_, _, &str, &str>(recipes.join("run_exports"), tmp.as_dir(), None, None);
// ensure rattler build succeeded
assert!(rattler_build.is_ok());
let pkg = get_extracted_package(tmp.as_dir(), "run_exports_test");
Expand Down Expand Up @@ -276,7 +278,7 @@ mod tests {
fn test_pkg_hash() {
let tmp = tmp("test_pkg_hash");
let rattler_build =
rattler().build::<_, _, &str>(recipes().join("pkg_hash"), tmp.as_dir(), None);
rattler().build::<_, _, &str, &str>(recipes().join("pkg_hash"), tmp.as_dir(), None, None);
assert!(rattler_build.is_ok());
let pkg = get_package(tmp.as_dir(), "pkg_hash".to_string());
// yes this was broken because in rust default formatting for map does include that one space in the middle!
Expand All @@ -290,7 +292,7 @@ mod tests {
fn test_license_glob() {
let tmp = tmp("test_license_glob");
let rattler_build =
rattler().build::<_, _, &str>(recipes().join("globtest"), tmp.as_dir(), None);
rattler().build::<_, _, &str, &str>(recipes().join("globtest"), tmp.as_dir(), None, None);
assert!(rattler_build.is_ok());
let pkg = get_extracted_package(tmp.as_dir(), "globtest");
assert!(pkg.join("info/licenses/LICENSE").exists());
Expand Down Expand Up @@ -354,7 +356,7 @@ mod tests {
fn test_python_noarch() {
let tmp = tmp("test_python_noarch");
let rattler_build =
rattler().build::<_, _, &str>(recipes().join("toml"), tmp.as_dir(), None);
rattler().build::<_, _, &str, &str>(recipes().join("toml"), tmp.as_dir(), None, None);
assert!(rattler_build.is_ok());
let pkg = get_extracted_package(tmp.as_dir(), "toml");
assert!(pkg.join("info/licenses/LICENSE").exists());
Expand All @@ -368,7 +370,7 @@ mod tests {
fn test_git_source() {
let tmp = tmp("test_git_source");
let rattler_build =
rattler().build::<_, _, &str>(recipes().join("llamacpp"), tmp.as_dir(), None);
rattler().build::<_, _, &str, &str>(recipes().join("llamacpp"), tmp.as_dir(), None, None);
assert!(rattler_build.is_ok());
let pkg = get_extracted_package(tmp.as_dir(), "llama.cpp");
// this is to ensure that the clone happens correctly
Expand Down Expand Up @@ -396,18 +398,20 @@ mod tests {
// assert!(rattler_build.is_ok());
// assert!(rattler_build.unwrap().status.success());

let rattler_build = rattler().build::<_, _, &str>(
let rattler_build = rattler().build::<_, _, &str, &str>(
recipes().join("package-content-tests/recipe-test-succeed.yaml"),
tmp.as_dir(),
None,
None,
);
assert!(rattler_build.is_ok());
assert!(rattler_build.unwrap().status.success());

let rattler_build = rattler().build::<_, _, &str>(
let rattler_build = rattler().build::<_, _, &str, &str>(
recipes().join("package-content-tests/recipe-test-fail.yaml"),
tmp.as_dir(),
None,
None,
);
assert!(rattler_build.is_ok());
assert!(rattler_build.unwrap().status.code().unwrap() == 1);
Expand All @@ -416,18 +420,20 @@ mod tests {
#[test]
fn test_test_execution() {
let tmp = tmp("test_test_execution");
let rattler_build = rattler().build::<_, _, &str>(
let rattler_build = rattler().build::<_, _, &str, &str>(
recipes().join("test-execution/recipe-test-succeed.yaml"),
tmp.as_dir(),
None,
None,
);
assert!(rattler_build.is_ok());
assert!(rattler_build.unwrap().status.success());

let rattler_build = rattler().build::<_, _, &str>(
let rattler_build = rattler().build::<_, _, &str, &str>(
recipes().join("test-execution/recipe-test-fail.yaml"),
tmp.as_dir(),
None,
None,
);
assert!(rattler_build.is_ok());
assert!(rattler_build.unwrap().status.code().unwrap() == 1);
Expand All @@ -437,7 +443,7 @@ mod tests {
fn test_noarch_flask() {
let tmp = tmp("test_noarch_flask");
let rattler_build =
rattler().build::<_, _, &str>(recipes().join("flask"), tmp.as_dir(), None);
rattler().build::<_, _, &str, &str>(recipes().join("flask"), tmp.as_dir(), None, None);
assert!(rattler_build.is_ok());
assert!(rattler_build.unwrap().status.success());

Expand Down Expand Up @@ -466,7 +472,7 @@ mod tests {
}
let tmp = tmp("test-sources");
let rattler_build =
rattler().build::<_, _, &str>(recipes().join("test-sources"), tmp.as_dir(), None);
rattler().build::<_, _, &str, &str>(recipes().join("test-sources"), tmp.as_dir(), None, None);
assert!(rattler_build.is_ok());
assert!(rattler_build.unwrap().status.success());
}
Expand All @@ -475,7 +481,7 @@ mod tests {
fn test_tar_source() {
let tmp = tmp("test_tar_source");
let rattler_build =
rattler().build::<_, _, &str>(recipes().join("tar-source"), tmp.as_dir(), None);
rattler().build::<_, _, &str, &str>(recipes().join("tar-source"), tmp.as_dir(), None, None);
assert!(rattler_build.is_ok());
assert!(rattler_build.unwrap().status.success());
}
Expand All @@ -484,7 +490,7 @@ mod tests {
fn test_zip_source() {
let tmp = tmp("test_zip_source");
let rattler_build =
rattler().build::<_, _, &str>(recipes().join("zip-source"), tmp.as_dir(), None);
rattler().build::<_, _, &str, &str>(recipes().join("zip-source"), tmp.as_dir(), None, None);
assert!(rattler_build.is_ok());
assert!(rattler_build.unwrap().status.success());
}
Expand All @@ -493,10 +499,11 @@ mod tests {
fn test_dry_run_cf_upload() {
let tmp = tmp("test_polarify");
let variant = recipes().join("polarify").join("linux_64_.yaml");
let rattler_build = rattler().build::<_, _, PathBuf>(
let rattler_build = rattler().build::<_, _, PathBuf, &str>(
recipes().join("polarify"),
tmp.as_dir(),
Some(variant),
None
);

assert!(rattler_build.is_ok());
Expand Down Expand Up @@ -529,7 +536,7 @@ mod tests {
fn test_correct_sha256() {
let tmp = tmp("correct-sha");
let rattler_build =
rattler().build::<_, _, &str>(recipes().join("correct-sha"), tmp.as_dir(), None);
rattler().build::<_, _, &str, &str>(recipes().join("correct-sha"), tmp.as_dir(), None, None);
assert!(rattler_build.is_ok());
assert!(rattler_build.unwrap().status.success());
}
Expand All @@ -538,7 +545,7 @@ mod tests {
fn test_rpath() {
let tmp = tmp("test_rpath");
let rattler_build =
rattler().build::<_, _, &str>(recipes().join("rpath"), tmp.as_dir(), None);
rattler().build::<_, _, &str, &str>(recipes().join("rpath"), tmp.as_dir(), None, Some("linux-64"));
assert!(rattler_build.is_ok());
assert!(rattler_build.unwrap().status.success());
}
Expand Down

0 comments on commit 56f6a4d

Please sign in to comment.