use super::states::handle_analyzing_state;
use super::types::{EnforcementState, QualityProfile};
#[tokio::test]
async fn a_nonexistent_path_is_refused_not_scored() {
let err = handle_analyzing_state(
std::path::Path::new("/nonexistent/pmat/enforce/probe"),
&QualityProfile::default(),
false,
true,
None,
None,
None,
)
.await
.expect_err("a nonexistent path must not produce a verdict");
assert!(
err.to_string().contains("path not found"),
"the refusal must name the cause: {err}"
);
}
#[tokio::test]
async fn an_empty_directory_is_not_complete() {
let dir = tempfile::tempdir().expect("tempdir");
let result = handle_analyzing_state(
dir.path(),
&QualityProfile::default(),
false,
true,
None,
None,
None,
)
.await
.expect("the run reports");
assert_ne!(result.state, EnforcementState::Complete);
assert!(result.score < 1.0, "got {}", result.score);
}
#[tokio::test]
async fn a_clean_project_can_still_reach_complete() {
let dir = tempfile::tempdir().expect("tempdir");
std::fs::create_dir_all(dir.path().join("src")).expect("mkdir");
std::fs::write(
dir.path().join("Cargo.toml"),
"[package]\nname = \"t\"\nversion = \"0.1.0\"\nedition = \"2021\"\n",
)
.expect("manifest");
std::fs::write(
dir.path().join("src/lib.rs"),
"//! Clean.\n\n/// Adds.\npub fn add(a: i32, b: i32) -> i32 { a + b }\n",
)
.expect("source");
std::fs::write(
dir.path().join("lcov.info"),
"SF:src/lib.rs\nDA:4,1\nLF:1\nLH:1\nend_of_record\n",
)
.expect("lcov");
let result = handle_analyzing_state(
dir.path(),
&QualityProfile::default(),
false,
true,
None,
None,
None,
)
.await
.expect("the run reports");
assert!(
result
.violations
.iter()
.all(|v| v.violation_type != "not_measured"),
"a parseable project with a coverage report should measure cleanly: {:?}",
result.violations
);
assert!(result.score > 0.0, "got {}", result.score);
assert_eq!(
result.state,
EnforcementState::Complete,
"a fully measured, clean project must still be able to pass: {:?}",
result.violations
);
}