use cargo_toml::Manifest;
use rstest::rstest;
use serde::Deserialize;
use super::get_license_information;
#[rstest]
fn test_snippet(
#[values(
// Full license names
"Blue Oak Model License 1.0.0",
"Apache License 2.0",
"MIT License",
// Some snippets from the template in `about.hbs`
"In the following you can find the licenses of ecformat and all its dependencies.",
"All license text",
"Used by"
)]
snippet: &str,
) {
let about = get_license_information();
assert!(
about.contains(snippet),
"License information does not contain '{snippet}'"
);
}
#[test]
fn test_direct_dependencies() {
let deps = Manifest::from_str(include_str!("../Cargo.toml"))
.unwrap()
.dependencies;
let about = get_license_information();
for dep in deps.keys() {
assert!(
about.contains(dep),
"Crate {dep} is missing in the license information"
);
}
}
#[derive(Deserialize)]
struct AboutToml {
accepted: Vec<String>,
}
#[test]
fn test_license_spdx_ids() {
let toml_content = include_str!("../about.toml");
let about_toml: AboutToml = toml::from_str(toml_content).unwrap();
let about = get_license_information();
for license in about_toml.accepted {
assert!(
about.contains(&license),
"License {license} is missing in the license information"
);
}
}
#[test]
fn test_license_text_blue_oak() {
let about = get_license_information();
assert!(
about.contains(include_str!("../LICENSES/BlueOak-1.0.0.txt")),
"License information does not contain the license text of BlueOak"
);
}