use std::process::Command;
fn alef_binary() -> std::path::PathBuf {
if let Ok(path) = std::env::var("CARGO_BIN_EXE_alef") {
return std::path::PathBuf::from(path);
}
let mut dir = std::env::current_exe()
.expect("current_exe")
.parent()
.expect("parent")
.to_path_buf();
if dir.ends_with("deps") {
dir = dir.parent().expect("parent of deps").to_path_buf();
}
dir.join("alef")
}
#[test]
fn generate_help_shows_format_flag() {
let output = Command::new(alef_binary())
.args(["generate", "--help"])
.output()
.expect("failed to run alef generate --help");
let stdout = String::from_utf8_lossy(&output.stdout);
let stderr = String::from_utf8_lossy(&output.stderr);
let combined = format!("{stdout}{stderr}");
assert!(
combined.contains(" --format"),
"`alef generate --help` must list --format flag; got:\n{combined}"
);
assert!(
!combined.contains("--no-format"),
"`alef generate --help` must not list --no-format; got:\n{combined}"
);
}
#[test]
fn all_help_shows_no_format_flag() {
let output = Command::new(alef_binary())
.args(["all", "--help"])
.output()
.expect("failed to run alef all --help");
let stdout = String::from_utf8_lossy(&output.stdout);
let stderr = String::from_utf8_lossy(&output.stderr);
let combined = format!("{stdout}{stderr}");
assert!(
combined.contains("--no-format"),
"`alef all --help` must list --no-format flag; got:\n{combined}"
);
assert!(
!combined.contains(" --format"),
"`alef all --help` must not list --format (opt-in); got:\n{combined}"
);
}
#[test]
fn generate_accepts_format_flag() {
let output = Command::new(alef_binary())
.args(["generate", "--format"])
.output()
.expect("failed to spawn alef");
assert_ne!(
output.status.code(),
Some(2),
"alef generate --format must be accepted by clap (not an unknown argument); got exit code 2"
);
}
#[test]
fn all_rejects_format_flag() {
let output = Command::new(alef_binary())
.args(["all", "--format"])
.output()
.expect("failed to spawn alef");
assert!(
!output.status.success(),
"alef all --format must exit non-zero; it was accepted unexpectedly"
);
}