use std::path::PathBuf;
use std::process::{Command, Output};
fn repo_root() -> PathBuf {
PathBuf::from(env!("CARGO_MANIFEST_DIR"))
}
fn script_path() -> PathBuf {
repo_root().join("scripts/publish/normalize-release-targets.sh")
}
fn run_normalize(raw_targets: Option<&str>) -> Output {
let mut command = Command::new("bash");
command.arg(script_path());
if let Some(raw) = raw_targets {
command.env("RAW_TARGETS", raw);
} else {
command.env_remove("RAW_TARGETS");
}
command.output().expect("normalize-release-targets.sh must run")
}
fn assert_normalized(raw_targets: Option<&str>, expected: &str) {
let output = run_normalize(raw_targets);
assert!(
output.status.success(),
"normalize-release-targets.sh exited non-zero for RAW_TARGETS={raw_targets:?}: {}",
String::from_utf8_lossy(&output.stderr)
);
let stdout = String::from_utf8(output.stdout).expect("stdout must be utf8");
assert_eq!(
stdout.trim(),
expected,
"RAW_TARGETS={raw_targets:?} must normalize to {expected:?}"
);
}
#[test]
fn whitespace_only_input_falls_back_to_crates_cli() {
assert_normalized(Some(" "), "crates,cli");
assert_normalized(Some("\t"), "crates,cli");
assert_normalized(Some(" \t \n "), "crates,cli");
}
#[test]
fn empty_input_falls_back_to_crates_cli() {
assert_normalized(Some(""), "crates,cli");
}
#[test]
fn unset_input_falls_back_to_crates_cli() {
assert_normalized(None, "crates,cli");
}
#[test]
fn explicit_all_passes_through_unchanged() {
assert_normalized(Some("all"), "all");
assert_normalized(Some(" all "), "all");
}
#[test]
fn explicit_none_passes_through_unchanged() {
assert_normalized(Some("none"), "none");
assert_normalized(Some(" none "), "none");
}
#[test]
fn ordinary_target_list_is_trimmed_but_otherwise_unchanged() {
assert_normalized(Some("crates,cli"), "crates,cli");
assert_normalized(Some(" cli,scoop "), "cli,scoop");
assert_normalized(Some(" cli,homebrew"), "cli,homebrew");
}