use super::*;
fn dirs(paths: &[&str]) -> Vec<PathBuf> {
paths.iter().map(PathBuf::from).collect()
}
#[test]
fn every_unset_gap_input_is_named_with_the_check_it_disables() {
let unset = unset_gap_inputs(&[], &[], &[], 1);
let keys: Vec<&str> = unset.iter().map(|input| input.key).collect();
assert_eq!(keys, vec!["docs_dirs", "required_languages", "include_base_paths"]);
for input in &unset {
assert!(
!input.consequence.is_empty(),
"{} must state what went unchecked",
input.key
);
}
}
#[test]
fn a_fully_configured_gap_check_reports_no_unset_input() {
let unset = unset_gap_inputs(&dirs(&["docs"]), &[Language::Python], &dirs(&["."]), 3);
assert!(unset.is_empty(), "nothing may be reported unset; got {unset:?}");
assert!(unset_input_lines(&unset, false).is_empty());
assert!(!has_vacuous_input(&unset));
}
#[test]
fn only_the_vacuity_causing_inputs_are_strict_fatal() {
assert!(has_vacuous_input(&unset_gap_inputs(
&[],
&[Language::Python],
&dirs(&["."]),
2
)));
assert!(has_vacuous_input(&unset_gap_inputs(
&dirs(&["docs"]),
&[],
&dirs(&["."]),
2
)));
assert!(
!has_vacuous_input(&unset_gap_inputs(&dirs(&["docs"]), &[Language::Python], &[], 3)),
"an unset include_base_paths over-reports and must not fail a strict run on its own"
);
}
#[test]
fn the_unset_warning_points_at_strict_mode_only_when_the_verdict_is_vacuous() {
let vacuous = unset_input_lines(&unset_gap_inputs(&[], &[], &[], 1), false).join("\n");
assert!(vacuous.contains("--strict"), "got: {vacuous}");
assert!(vacuous.contains("proves less than it appears to"), "got: {vacuous}");
let only_base_paths = unset_input_lines(&unset_gap_inputs(&dirs(&["docs"]), &[Language::Python], &[], 1), false);
assert_eq!(
only_base_paths.len(),
2,
"a non-vacuous omission gets a heading and its line, and no strict-mode advice: {only_base_paths:?}"
);
}
#[test]
fn a_strict_run_does_not_advise_passing_strict() {
let lines = unset_input_lines(&unset_gap_inputs(&[], &[], &[], 1), true).join("\n");
assert!(lines.contains("docs_dirs unset"), "got: {lines}");
assert!(!lines.contains("pass --strict"), "got: {lines}");
}
#[test]
fn a_docs_tree_with_no_mkdocs_includes_does_not_warn_about_unset_include_base_paths() {
let unset = unset_gap_inputs(&dirs(&["docs"]), &[Language::Python], &[], 0);
assert!(
unset.is_empty(),
"no `--8<--` target was found, so an unset include_base_paths is not actionable: {unset:?}"
);
}
#[test]
fn a_docs_tree_with_mkdocs_includes_still_warns_about_unset_include_base_paths() {
let unset = unset_gap_inputs(&dirs(&["docs"]), &[Language::Python], &[], 1);
assert_eq!(
unset.iter().map(|input| input.key).collect::<Vec<_>>(),
vec!["include_base_paths"],
"a `--8<--` target was found, so the unset base-path list is actionable: {unset:?}"
);
}
#[test]
fn coverage_names_the_zeroes_that_make_a_clean_verdict_vacuous() {
let coverage = GapCoverage {
snippet_roots: 1,
snippets_discovered: 148,
docs_roots: 0,
docs_pages_scanned: 0,
include_references: 0,
mkdocs_include_references: 0,
configured_references: 148,
required_languages: 0,
language_groups: 0,
include_base_paths: 0,
};
let report = coverage.report_lines().join("\n");
assert!(
report.contains("NO documentation page entered this result"),
"got: {report}"
);
assert!(report.contains("compared nothing"), "got: {report}");
assert!(
report.contains("148"),
"the discovered snippet count must appear: {report}"
);
}
#[test]
fn coverage_of_a_configured_run_carries_no_emptiness_warning() {
let coverage = GapCoverage {
snippet_roots: 1,
snippets_discovered: 148,
docs_roots: 1,
docs_pages_scanned: 62,
include_references: 130,
mkdocs_include_references: 130,
configured_references: 18,
required_languages: 3,
language_groups: 40,
include_base_paths: 1,
};
let report = coverage.report_lines().join("\n");
assert!(!report.contains("NO documentation page"), "got: {report}");
assert!(!report.contains("compared nothing"), "got: {report}");
assert!(report.contains("62 page(s) opened"), "got: {report}");
assert!(report.contains("3 required language(s) across 40"), "got: {report}");
}
#[test]
fn required_languages_without_a_single_group_still_reads_as_uncompared() {
let coverage = GapCoverage {
required_languages: 3,
language_groups: 0,
..GapCoverage::default()
};
assert!(coverage.report_lines().join("\n").contains("compared nothing"));
}