use std::process::Command;
#[test]
fn test_backends() {
#[cfg(all(target_os = "linux", target_arch = "aarch64"))]
{
assert!(
!has_dependency("test-crates/use-default", &[], &[], &["RUSTFLAGS"], "libc"),
"use-default depends on libc"
);
assert!(
has_dependency(
"test-crates/use-default",
&[],
&[],
&["RUSTFLAGS"],
"linux-raw-sys"
),
"use-default does not depend on linux-raw-sys"
);
}
#[cfg(windows)]
let libc_dep = "winapi";
#[cfg(unix)]
let libc_dep = "libc";
assert!(
has_dependency("test-crates/use-libc", &[], &[], &["RUSTFLAGS"], libc_dep),
"use-libc doesn't depend on {}",
libc_dep
);
assert!(
has_dependency(
"test-crates/use-default",
&[],
&[("RUSTFLAGS", "--cfg=rustix_use_libc")],
&[],
libc_dep
),
"use-default with --cfg=rustix_use_libc does not depend on {}",
libc_dep
);
assert!(
!has_dependency(
"test-crates/use-default",
&[],
&[("RUSTFLAGS", "--cfg=rustix_use_libc")],
&[],
"linux-raw-sys"
),
"use-default with --cfg=rustix_use_libc depends on linux-raw-sys"
);
assert!(
has_dependency(
"test-crates/use-default",
&["--features=rustix/use-libc"],
&[],
&[],
libc_dep
),
"use-default with --features=rustix/use-libc does not depend on {}",
libc_dep
);
}
fn has_dependency(
dir: &str,
args: &[&str],
envs: &[(&str, &str)],
remove_envs: &[&str],
dependency: &str,
) -> bool {
let mut command = Command::new("cargo");
command
.arg("tree")
.arg("--quiet")
.arg("--edges=normal")
.arg(&format!("--invert={}", dependency))
.current_dir(dir);
command.args(args);
for (key, value) in envs {
command.env(key, value);
}
for key in remove_envs {
command.env_remove(key);
}
let child = command.output().unwrap();
child.status.success() && !child.stdout.is_empty()
}