use std::ffi::OsString;
use std::path::PathBuf;
use testing_conventions::lint::find_violations;
use testing_conventions::run;
fn fixture(name: &str) -> PathBuf {
PathBuf::from(env!("CARGO_MANIFEST_DIR"))
.join("tests/fixtures/integration_lint/python")
.join(name)
}
fn run_cli(args: &[&str]) -> anyhow::Result<i32> {
let argv: Vec<OsString> = std::iter::once(OsString::from("testing-conventions"))
.chain(args.iter().copied().map(OsString::from))
.collect();
run(argv)
}
fn lint_exit(fixture_name: &str) -> i32 {
let argv: Vec<OsString> = vec![
"testing-conventions".into(),
"integration".into(),
"lint".into(),
"--language".into(),
"python".into(),
fixture(fixture_name).into_os_string(),
];
run(argv).expect("a readable tree should not error")
}
#[test]
fn red_fixture_reports_a_monkeypatch_violation() {
let violations =
find_violations(fixture("red")).expect("walking a readable tree should succeed");
assert!(
violations.iter().any(|v| v.rule == "no-monkeypatch"),
"the red fixture uses pytest's `monkeypatch` and must be flagged; got {violations:?}"
);
}
#[test]
fn clean_fixture_reports_no_violations() {
let violations =
find_violations(fixture("clean")).expect("walking a readable tree should succeed");
assert!(
violations.is_empty(),
"the clean fixture patches via a fixture (no monkeypatch); got {violations:?}"
);
}
#[test]
fn red_fixture_exits_nonzero() {
assert_eq!(lint_exit("red"), 1);
}
#[test]
fn clean_fixture_exits_zero() {
assert_eq!(lint_exit("clean"), 0);
}
#[test]
fn integration_lint_requires_language() {
let err = run_cli(&["integration", "lint", "src"]).expect_err("--language is required");
let clap_err = err
.downcast_ref::<clap::Error>()
.expect("a missing required flag should surface as a clap::Error");
assert_eq!(
clap_err.kind(),
clap::error::ErrorKind::MissingRequiredArgument
);
}