#[test]
fn test_check_muda_waste_score() {
let temp_dir = TempDir::new().unwrap();
let src_dir = temp_dir.path().join("src");
std::fs::create_dir_all(&src_dir).unwrap();
std::fs::write(src_dir.join("lib.rs"), "pub fn main() {}").unwrap();
let check = crate::cli::handlers::comply_handlers::check_muda_waste_score(temp_dir.path());
assert!(check.name.contains("Muda"));
assert!(check.message.contains("/100"));
}
#[test]
fn test_check_reproducibility_level_none() {
let temp_dir = TempDir::new().unwrap();
let check = crate::cli::handlers::comply_handlers::check_reproducibility_level(temp_dir.path());
assert_eq!(check.status, CheckStatus::Fail);
assert!(check.name.contains("Reproducibility"));
}
#[test]
fn test_check_reproducibility_level_with_lockfile() {
let temp_dir = TempDir::new().unwrap();
std::fs::write(temp_dir.path().join("Cargo.lock"), "").unwrap();
let check = crate::cli::handlers::comply_handlers::check_reproducibility_level(temp_dir.path());
assert!(check.status == CheckStatus::Pass || check.status == CheckStatus::Warn);
}
#[test]
fn test_check_golden_trace_drift_no_config() {
let temp_dir = TempDir::new().unwrap();
let check = crate::cli::handlers::comply_handlers::check_golden_trace_drift(temp_dir.path());
assert_eq!(check.status, CheckStatus::Skip);
}
#[test]
fn test_check_golden_trace_drift_with_config() {
let temp_dir = TempDir::new().unwrap();
std::fs::write(temp_dir.path().join("renacer.toml"), "[golden_traces]").unwrap();
let check = crate::cli::handlers::comply_handlers::check_golden_trace_drift(temp_dir.path());
assert!(check.status == CheckStatus::Pass || check.status == CheckStatus::Fail);
}
#[test]
fn test_check_edd_compliance_not_simulation() {
let temp_dir = TempDir::new().unwrap();
std::fs::write(
temp_dir.path().join("Cargo.toml"),
"[package]\nname = \"test\"\nversion = \"0.1.0\"",
)
.unwrap();
let check = crate::cli::handlers::comply_handlers::check_edd_compliance(temp_dir.path());
assert_eq!(check.status, CheckStatus::Skip);
assert!(check.message.contains("Not a simulation project"));
}
#[test]
fn test_load_or_create_project_config_new() {
let temp_dir = TempDir::new().unwrap();
let config =
crate::cli::handlers::comply_handlers::load_or_create_project_config(temp_dir.path())
.unwrap();
assert_eq!(config.pmat.version, PMAT_VERSION);
assert!(temp_dir.path().join(".pmat").join("project.toml").exists());
}
#[test]
fn test_load_or_create_project_config_existing() {
let temp_dir = TempDir::new().unwrap();
let pmat_dir = temp_dir.path().join(".pmat");
std::fs::create_dir_all(&pmat_dir).unwrap();
std::fs::write(
pmat_dir.join("project.toml"),
"[pmat]\nversion = \"1.0.0\"\nauto_update = true",
)
.unwrap();
let config =
crate::cli::handlers::comply_handlers::load_or_create_project_config(temp_dir.path())
.unwrap();
assert_eq!(config.pmat.version, "1.0.0");
assert!(config.pmat.auto_update);
}
#[test]
fn test_update_last_check_timestamp() {
let temp_dir = TempDir::new().unwrap();
let pmat_dir = temp_dir.path().join(".pmat");
std::fs::create_dir_all(&pmat_dir).unwrap();
std::fs::write(pmat_dir.join("project.toml"), "[pmat]\nversion = \"1.0.0\"").unwrap();
let result =
crate::cli::handlers::comply_handlers::update_last_check_timestamp(temp_dir.path());
assert!(result.is_ok());
let content = std::fs::read_to_string(pmat_dir.join("project.toml")).unwrap();
assert!(content.contains("last_compliance_check"));
}
#[test]
fn test_check_paiml_deps_workspace() {
let temp_dir = TempDir::new().unwrap();
std::fs::write(
temp_dir.path().join("Cargo.toml"),
"[package]\nname = \"test\"\nversion = \"0.1.0\"",
)
.unwrap();
let check = crate::cli::handlers::comply_handlers::check_paiml_deps_workspace(temp_dir.path());
assert!(
check.status == CheckStatus::Pass
|| check.status == CheckStatus::Warn
|| check.status == CheckStatus::Skip
);
}
#[test]
fn test_check_sovereign_stack_patterns() {
let temp_dir = TempDir::new().unwrap();
std::fs::write(
temp_dir.path().join("Cargo.toml"),
"[package]\nname = \"test\"\nversion = \"0.1.0\"",
)
.unwrap();
let check =
crate::cli::handlers::comply_handlers::check_sovereign_stack_patterns(temp_dir.path());
assert!(check.name.contains("Sovereign") || check.name.contains("Stack"));
}
#[test]
fn test_check_file_health() {
let temp_dir = TempDir::new().unwrap();
let src_dir = temp_dir.path().join("src");
std::fs::create_dir_all(&src_dir).unwrap();
std::fs::write(src_dir.join("lib.rs"), "pub fn main() {}").unwrap();
let check = crate::cli::handlers::comply_handlers::check_file_health(temp_dir.path());
assert!(
check.status == CheckStatus::Pass
|| check.status == CheckStatus::Warn
|| check.status == CheckStatus::Fail
|| check.status == CheckStatus::Skip
);
}
#[test]
fn test_collect_production_rs_files_excludes_tests() {
let temp_dir = TempDir::new().unwrap();
let src_dir = temp_dir.path().join("src");
let tests_dir = src_dir.join("tests");
std::fs::create_dir_all(&tests_dir).unwrap();
std::fs::write(src_dir.join("lib.rs"), "").unwrap();
std::fs::write(src_dir.join("main_tests.rs"), "").unwrap();
std::fs::write(tests_dir.join("integration.rs"), "").unwrap();
let files = crate::cli::handlers::comply_handlers::collect_production_rs_files(&src_dir);
assert_eq!(files.len(), 1);
assert!(files[0].to_string_lossy().contains("lib.rs"));
}
#[test]
fn test_collect_production_rs_files_excludes_falsification() {
let temp_dir = TempDir::new().unwrap();
let src_dir = temp_dir.path().join("src");
let falsification_dir = src_dir.join("falsification");
std::fs::create_dir_all(&falsification_dir).unwrap();
std::fs::write(src_dir.join("lib.rs"), "").unwrap();
std::fs::write(falsification_dir.join("property_tests.rs"), "").unwrap();
let files = crate::cli::handlers::comply_handlers::collect_production_rs_files(&src_dir);
assert_eq!(files.len(), 1);
}
#[test]
fn test_scan_dead_code_indicators_empty() {
let temp_dir = TempDir::new().unwrap();
let src_dir = temp_dir.path().join("src");
std::fs::create_dir_all(&src_dir).unwrap();
let (total, dead, lines, dead_lines) =
crate::cli::handlers::comply_handlers::scan_dead_code_indicators(&src_dir);
assert_eq!(total, 0);
assert_eq!(dead, 0);
assert_eq!(lines, 0);
assert_eq!(dead_lines, 0);
}
#[test]
fn test_scan_dead_code_indicators_with_code() {
let temp_dir = TempDir::new().unwrap();
let src_dir = temp_dir.path().join("src");
std::fs::create_dir_all(&src_dir).unwrap();
std::fs::write(
src_dir.join("lib.rs"),
r#"
pub fn active() {}
#[allow(dead_code)]
fn dead() {}
"#,
)
.unwrap();
let (total, dead, lines, dead_lines) =
crate::cli::handlers::comply_handlers::scan_dead_code_indicators(&src_dir);
assert!(total >= 2);
assert!(dead >= 1);
assert!(lines > 0);
assert!(dead_lines >= 10);
}
#[test]
fn test_pmat_version_is_set() {
assert!(!PMAT_VERSION.is_empty());
let parts: Vec<&str> = PMAT_VERSION.split('.').collect();
assert!(parts.len() >= 2);
}