use crate::Exit;
use crate::analysis::findings::Severity;
use crate::cli::lint_docs::tests::{repo, run_failing_on, run_in};
#[test]
fn a_clean_tree_exits_clean_under_both_modes() {
let dir = repo(&[("README.md", "# Title\n\nprose\n")]);
assert_eq!(run_in(dir.path(), &[], false).exit, Exit::Clean);
assert_eq!(run_in(dir.path(), &[], true).exit, Exit::Clean);
}
#[test]
fn findings_are_report_only_by_default_and_block_under_strict() {
let dir = repo(&[("README.md", "#Heading\n")]);
let lenient = run_in(dir.path(), &[], false);
assert!(!lenient.findings.is_empty());
assert_eq!(lenient.exit, Exit::Clean);
let strict = run_in(dir.path(), &[], true);
assert_eq!(
strict.findings, lenient.findings,
"same findings, both ways"
);
assert_eq!(strict.exit, Exit::FoundIssues);
}
#[test]
fn an_unanalyzable_file_exits_two_even_report_only() {
let dir = repo(&[("README.md", "# Title\n")]);
let outcome = run_in(dir.path(), &["missing.md"], false);
assert!(outcome.findings.is_empty());
assert_eq!(outcome.exit, Exit::Unanalyzed);
}
#[test]
fn a_failure_outranks_a_finding() {
let dir = repo(&[("README.md", "#Heading\n")]);
let outcome = run_in(dir.path(), &["README.md", "missing.md"], true);
assert!(!outcome.findings.is_empty());
assert!(!outcome.failures.is_empty());
assert_eq!(outcome.exit, Exit::Unanalyzed);
}
#[test]
fn an_empty_repository_is_clean_not_unanalyzed() {
let dir = repo(&[]);
let outcome = run_in(dir.path(), &[], true);
assert_eq!(outcome.exit, Exit::Clean);
assert!(outcome.failures.is_empty());
}
#[test]
fn fail_on_error_ignores_findings_below_the_threshold() {
let dir = repo(&[("README.md", "# Title\n\nprose \n")]);
let outcome = run_failing_on(dir.path(), &[], Severity::Error);
assert!(
!outcome.findings.is_empty(),
"the findings must still be reported"
);
assert!(
outcome
.findings
.iter()
.all(|f| f.severity < Severity::Error),
"fixture must produce only sub-threshold findings, got {:?}",
outcome.findings
);
assert_eq!(outcome.exit, Exit::Clean);
}
#[test]
fn fail_on_error_blocks_on_an_unclosed_fence() {
let dir = repo(&[("README.md", "# Title\n\n```rust\nlet x = 1;\n")]);
let outcome = run_failing_on(dir.path(), &[], Severity::Error);
assert!(
outcome
.findings
.iter()
.any(|f| f.severity == Severity::Error),
"fixture must produce an error-severity finding, got {:?}",
outcome.findings
);
assert_eq!(outcome.exit, Exit::FoundIssues);
}
#[test]
fn strict_gates_exactly_as_fail_on_info_does() {
let dir = repo(&[("README.md", "#Heading\n\nprose \n")]);
let strict = run_in(dir.path(), &[], true);
let explicit = run_failing_on(dir.path(), &[], Severity::Info);
assert_eq!(strict.findings, explicit.findings);
assert_eq!(strict.exit, explicit.exit);
assert_eq!(strict.exit, Exit::FoundIssues);
}
#[test]
fn fail_on_error_still_exits_two_for_a_file_it_could_not_read() {
let dir = repo(&[("README.md", "# Title\n")]);
let outcome = run_failing_on(dir.path(), &["missing.md"], Severity::Error);
assert!(outcome.findings.is_empty());
assert_eq!(outcome.exit, Exit::Unanalyzed);
}