#![allow(clippy::unwrap_used)]
use std::path::{Path, PathBuf};
use std::process::Command;
const GEOLITH: &str = env!("CARGO_BIN_EXE_geolith");
fn workspace_root() -> PathBuf {
Path::new(env!("CARGO_MANIFEST_DIR"))
.parent()
.unwrap()
.to_path_buf()
}
fn run(args: &[&str]) -> String {
let output = Command::new(GEOLITH).args(args).output().unwrap();
assert!(output.status.success(), "geolith {args:?}: {output:?}");
String::from_utf8(output.stdout).unwrap()
}
#[test]
fn the_long_version_names_the_credit_and_the_licence() {
let text = run(&["--version"]);
let mut lines = text.lines();
assert_eq!(
lines.next().unwrap(),
format!("geolith {}", env!("CARGO_PKG_VERSION"))
);
assert!(text.contains("© geolith"), "{text}");
assert!(text.contains("FSL-1.1-ALv2"), "{text}");
assert!(text.contains("geolith notices"), "{text}");
}
#[test]
fn notices_prints_the_third_party_notices() {
let text = run(&["notices"]);
assert!(text.starts_with("# Notice"), "{text}");
assert!(text.contains("Valhalla"), "{text}");
assert_eq!(
text,
std::fs::read_to_string(workspace_root().join("NOTICE.md")).unwrap()
);
}
#[test]
fn every_crate_ships_the_licence_and_the_notice_of_the_workspace() {
let root = workspace_root();
let licence = std::fs::read(root.join("LICENSE.md")).unwrap();
let notice = std::fs::read(root.join("NOTICE.md")).unwrap();
let mut crates = vec![root.join("geolith")];
for entry in std::fs::read_dir(root.join("packages")).unwrap() {
crates.push(entry.unwrap().path());
}
assert!(crates.len() >= 6, "{crates:?}");
for dir in crates {
assert_eq!(
std::fs::read(dir.join("LICENSE.md")).unwrap(),
licence,
"{dir:?}"
);
assert_eq!(
std::fs::read(dir.join("NOTICE.md")).unwrap(),
notice,
"{dir:?}"
);
let manifest = std::fs::read_to_string(dir.join("Cargo.toml")).unwrap();
assert!(
manifest.contains("license-file = \"LICENSE.md\""),
"{dir:?}"
);
}
}