use std::path::PathBuf;
#[test]
fn test_warning_message_content_in_source() {
let source_path =
PathBuf::from(env!("CARGO_MANIFEST_DIR")).join("src/builders/unified_analysis.rs");
let source = std::fs::read_to_string(&source_path).expect("Failed to read source file");
assert!(
source.contains("Coverage data not provided"),
"Source should contain coverage warning message"
);
assert!(
source.contains("Analysis will focus on complexity and code smells"),
"Warning should explain what analysis will focus on"
);
assert!(
source.contains("--lcov-file coverage.info"),
"Warning should show how to provide coverage data"
);
assert!(
source.contains("fn emit_coverage_tip"),
"Should have emit_coverage_tip helper function"
);
assert!(
source.contains("emit_coverage_tip(coverage_data.is_none()"),
"Warning should be emitted when no coverage data"
);
}
#[test]
fn test_unified_analysis_has_coverage_data_flag() {
use debtmap::priority::{CallGraph, UnifiedAnalysis};
let call_graph = CallGraph::new();
let mut analysis = UnifiedAnalysis::new(call_graph);
assert!(
!analysis.has_coverage_data,
"New analysis should default to has_coverage_data=false"
);
analysis.has_coverage_data = true;
assert!(
analysis.has_coverage_data,
"Should be able to set has_coverage_data to true"
);
analysis.has_coverage_data = false;
assert!(
!analysis.has_coverage_data,
"Should be able to set has_coverage_data to false"
);
}
#[test]
fn test_warning_displayed_once_not_multiple_times() {
let source_path =
PathBuf::from(env!("CARGO_MANIFEST_DIR")).join("src/builders/unified_analysis.rs");
let source = std::fs::read_to_string(&source_path).expect("Failed to read source file");
let tip_section = source
.split("fn emit_coverage_tip")
.nth(1)
.expect("Should find emit_coverage_tip function");
let fn_body = tip_section
.split("fn ") .next()
.unwrap_or(tip_section);
assert!(
fn_body.contains("warn!"),
"Warning should use warn! macro for structured logging"
);
let main_fn = source
.split("pub fn perform_unified_analysis_with_options")
.nth(1)
.and_then(|s| s.split("pub fn").next())
.expect("Should find main function");
let emit_calls = main_fn.matches("emit_coverage_tip").count();
assert_eq!(
emit_calls, 1,
"emit_coverage_tip should be called exactly once in main function"
);
}