use pmat::mcp_pmcp::tool_functions::*;
use std::fs;
use std::path::PathBuf;
use tempfile::tempdir;
#[tokio::test]
async fn test_analyze_complexity_empty_paths() {
let result = analyze_complexity(&[], None, None).await;
assert!(result.is_err());
let err = result.unwrap_err();
assert!(err.to_string().contains("path") || err.to_string().contains("provided"));
}
#[tokio::test]
async fn test_analyze_satd_empty_paths() {
let result = analyze_satd(&[], false).await;
assert!(result.is_err());
let err = result.unwrap_err();
assert!(err.to_string().contains("path") || err.to_string().contains("provided"));
}
#[tokio::test]
async fn test_analyze_dead_code_empty_paths() {
let result = analyze_dead_code(&[], false).await;
assert!(result.is_err());
let err = result.unwrap_err();
assert!(err.to_string().contains("path") || err.to_string().contains("provided"));
}
#[tokio::test]
async fn test_analyze_lint_hotspots_empty_paths() {
let result = analyze_lint_hotspots(&[], None).await;
assert!(result.is_err());
let err = result.unwrap_err();
assert!(err.to_string().contains("path") || err.to_string().contains("provided"));
}
#[tokio::test]
async fn test_analyze_churn_empty_paths() {
let result = analyze_churn(&[], None, None).await;
assert!(result.is_err());
let err = result.unwrap_err();
assert!(err.to_string().contains("path") || err.to_string().contains("provided"));
}
#[tokio::test]
async fn test_analyze_coupling_empty_paths() {
let result = analyze_coupling(&[], None).await;
assert!(result.is_err());
let err = result.unwrap_err();
assert!(err.to_string().contains("path") || err.to_string().contains("provided"));
}
#[tokio::test]
async fn test_analyze_complexity_nonexistent_path() {
let nonexistent = PathBuf::from("/nonexistent/file.rs");
let result = analyze_complexity(&[nonexistent], None, None).await;
assert!(result.is_ok());
let output = result.unwrap();
assert_eq!(output["status"], "completed");
}
#[tokio::test]
async fn test_analyze_satd_nonexistent_path() {
let nonexistent = PathBuf::from("/nonexistent/file.rs");
let result = analyze_satd(&[nonexistent], false).await;
assert!(result.is_ok());
let output = result.unwrap();
assert_eq!(output["results"]["total_satd"], 0);
}
#[tokio::test]
async fn test_analyze_dead_code_nonexistent_path() {
let nonexistent = PathBuf::from("/nonexistent/file.rs");
let result = analyze_dead_code(&[nonexistent], false).await;
assert!(result.is_ok());
let output = result.unwrap();
assert_eq!(output["results"]["total_dead_code"], 0);
}
#[tokio::test]
async fn test_analyze_complexity_with_threshold() {
let temp_dir = tempdir().unwrap();
let rust_file = temp_dir.path().join("test.rs");
fs::write(
&rust_file,
r#"
fn simple() { }
fn complex() {
if true { if false { } }
match 42 { 1 => {}, _ => {} }
}
"#,
)
.unwrap();
let result = analyze_complexity(&[rust_file], None, Some(5)).await;
assert!(result.is_ok());
let output = result.unwrap();
assert_eq!(output["status"], "completed");
assert!(output["results"]["violations"].is_array());
}
#[tokio::test]
async fn test_analyze_complexity_with_top_files() {
let temp_dir = tempdir().unwrap();
let rust_file = temp_dir.path().join("test.rs");
fs::write(
&rust_file,
r#"
fn a() { }
fn b() { if true {} }
fn c() { if true { if false {} } }
"#,
)
.unwrap();
let result = analyze_complexity(&[rust_file], Some(2), None).await;
assert!(result.is_ok());
let output = result.unwrap();
let top_files = output["results"]["top_files"].as_array().unwrap();
assert!(top_files.len() <= 2);
}
#[tokio::test]
async fn test_analyze_complexity_threshold_zero() {
let temp_dir = tempdir().unwrap();
let rust_file = temp_dir.path().join("test.rs");
fs::write(&rust_file, "fn simple() { }").unwrap();
let result = analyze_complexity(&[rust_file], None, Some(0)).await;
assert!(result.is_ok());
let output = result.unwrap();
assert!(output["results"]["violations"].is_array());
}
#[tokio::test]
async fn test_analyze_coupling_threshold_parameter() {
let temp_dir = tempdir().unwrap();
let rust_file = temp_dir.path().join("test.rs");
fs::write(&rust_file, "fn test() {}").unwrap();
let result = analyze_coupling(&[rust_file], Some(0.5)).await;
match result {
Ok(_) | Err(_) => {} }
}
#[tokio::test]
async fn test_analyze_satd_detects_todo_comments() {
let temp_dir = tempdir().unwrap();
let rust_file = temp_dir.path().join("test.rs");
fs::write(
&rust_file,
r#"
// TODO: Implement this feature
fn placeholder() { }
// FIXME: This is broken
fn broken() { }
"#,
)
.unwrap();
let result = analyze_satd(&[rust_file], false).await;
assert!(result.is_ok());
let output = result.unwrap();
assert!(output["results"]["total_satd"].as_u64().unwrap() >= 1);
}
#[tokio::test]
async fn test_analyze_satd_no_markers() {
let temp_dir = tempdir().unwrap();
let rust_file = temp_dir.path().join("test.rs");
fs::write(
&rust_file,
r#"
fn clean_code() {
println!("No technical debt here!");
}
"#,
)
.unwrap();
let result = analyze_satd(&[rust_file], false).await;
assert!(result.is_ok());
let output = result.unwrap();
assert_eq!(output["results"]["total_satd"], 0);
}
#[tokio::test]
async fn test_analyze_complexity_multiple_files() {
let temp_dir = tempdir().unwrap();
let file1 = temp_dir.path().join("file1.rs");
let file2 = temp_dir.path().join("file2.rs");
fs::write(&file1, "fn a() {}").unwrap();
fs::write(&file2, "fn b() {}").unwrap();
let result = analyze_complexity(&[file1, file2], None, None).await;
assert!(result.is_ok());
let output = result.unwrap();
assert!(output["results"]["total_files"].as_u64().unwrap() >= 1);
}
#[tokio::test]
async fn test_check_quality_gates_empty_paths() {
let result = check_quality_gates(&[], false).await;
assert!(result.is_err());
let err = result.unwrap_err();
assert!(err.to_string().contains("path") || err.to_string().contains("provided"));
}
#[tokio::test]
async fn test_check_quality_gates_strict_mode() {
let temp_dir = tempdir().unwrap();
let rust_file = temp_dir.path().join("test.rs");
fs::write(&rust_file, "fn test() {}").unwrap();
let result_strict = check_quality_gates(&[rust_file.clone()], true).await;
let result_lenient = check_quality_gates(&[rust_file], false).await;
assert!(result_strict.is_ok() || result_strict.is_err());
assert!(result_lenient.is_ok() || result_lenient.is_err());
}
#[tokio::test]
async fn test_quality_gate_summary_empty_paths() {
let result = quality_gate_summary(&[]).await;
assert!(result.is_err());
let err = result.unwrap_err();
assert!(err.to_string().contains("path") || err.to_string().contains("provided"));
}
#[tokio::test]
async fn test_quality_gate_baseline_empty_paths() {
let result = quality_gate_baseline(&[], None).await;
assert!(result.is_err());
let err = result.unwrap_err();
assert!(err.to_string().contains("path") || err.to_string().contains("provided"));
}
#[tokio::test]
async fn test_generate_context_empty_paths() {
let result = generate_context(&[], None, false).await;
assert!(result.is_err());
let err = result.unwrap_err();
assert!(err.to_string().contains("path") || err.to_string().contains("provided"));
}
#[tokio::test]
async fn test_generate_deep_context_empty_paths() {
let result = generate_deep_context(&[], None).await;
assert!(result.is_err());
let err = result.unwrap_err();
assert!(err.to_string().contains("path") || err.to_string().contains("provided"));
}
#[tokio::test]
async fn test_analyze_context_empty_paths() {
let result = analyze_context(&[], &[]).await;
assert!(result.is_err());
let err = result.unwrap_err();
assert!(err.to_string().contains("path") || err.to_string().contains("provided"));
}
#[tokio::test]
async fn test_context_summary_empty_paths() {
let result = context_summary(&[], None).await;
assert!(result.is_err());
let err = result.unwrap_err();
assert!(err.to_string().contains("path") || err.to_string().contains("provided"));
}
#[tokio::test]
async fn test_analyze_tdg_empty_paths() {
let result = analyze_tdg(&[], None, None, None, None).await;
assert!(result.is_err());
let err = result.unwrap_err();
assert!(err.to_string().contains("path") || err.to_string().contains("provided"));
}
#[tokio::test]
async fn test_analyze_tdg_with_threshold() {
let temp_dir = tempdir().unwrap();
let rust_file = temp_dir.path().join("test.rs");
fs::write(&rust_file, "fn test() {}").unwrap();
let result = analyze_tdg(&[rust_file], Some(0.8), None, None, None).await;
match result {
Ok(_) | Err(_) => {} }
}
#[tokio::test]
async fn test_tdg_health_check() {
let result = tdg_health_check().await;
assert!(result.is_ok());
let output = result.unwrap();
assert!(output.is_object());
}
#[tokio::test]
async fn test_tdg_performance_metrics() {
let result = tdg_performance_metrics().await;
assert!(result.is_ok());
let output = result.unwrap();
assert!(output.is_object());
}
#[tokio::test]
async fn test_git_status_nonexistent_path() {
let nonexistent = PathBuf::from("/nonexistent/repo");
let result = git_status(&nonexistent).await;
assert!(result.is_err());
}
#[tokio::test]
async fn test_git_status_non_git_directory() {
let temp_dir = tempdir().unwrap();
let result = git_status(temp_dir.path()).await;
assert!(result.is_err());
}
#[tokio::test]
async fn test_analyze_complexity_very_high_threshold() {
let temp_dir = tempdir().unwrap();
let rust_file = temp_dir.path().join("test.rs");
fs::write(&rust_file, "fn simple() {}").unwrap();
let result = analyze_complexity(&[rust_file], None, Some(999999)).await;
assert!(result.is_ok());
let output = result.unwrap();
let violations = output["results"]["violations"].as_array().unwrap();
assert_eq!(violations.len(), 0);
}
#[tokio::test]
async fn test_analyze_complexity_top_files_zero() {
let temp_dir = tempdir().unwrap();
let rust_file = temp_dir.path().join("test.rs");
fs::write(&rust_file, "fn test() {}").unwrap();
let result = analyze_complexity(&[rust_file], Some(0), None).await;
assert!(result.is_ok());
let output = result.unwrap();
let top_files = output["results"]["top_files"].as_array().unwrap();
assert_eq!(top_files.len(), 0);
}
#[tokio::test]
async fn test_analyze_coupling_threshold_zero() {
let temp_dir = tempdir().unwrap();
let rust_file = temp_dir.path().join("test.rs");
fs::write(&rust_file, "fn test() {}").unwrap();
let result = analyze_coupling(&[rust_file], Some(0.0)).await;
match result {
Ok(_) | Err(_) => {}
}
}
#[tokio::test]
async fn test_analyze_coupling_threshold_one() {
let temp_dir = tempdir().unwrap();
let rust_file = temp_dir.path().join("test.rs");
fs::write(&rust_file, "fn test() {}").unwrap();
let result = analyze_coupling(&[rust_file], Some(1.0)).await;
match result {
Ok(_) | Err(_) => {}
}
}
#[tokio::test]
async fn test_analyze_complexity_output_structure() {
let temp_dir = tempdir().unwrap();
let rust_file = temp_dir.path().join("test.rs");
fs::write(&rust_file, "fn test() {}").unwrap();
let result = analyze_complexity(&[rust_file], None, None).await;
assert!(result.is_ok());
let output = result.unwrap();
assert_eq!(output["status"], "completed");
assert!(output["message"].is_string());
assert!(output["results"].is_object());
assert!(output["results"]["total_files"].is_number());
assert!(output["results"]["violations"].is_array());
}
#[tokio::test]
async fn test_analyze_satd_output_structure() {
let temp_dir = tempdir().unwrap();
let rust_file = temp_dir.path().join("test.rs");
fs::write(&rust_file, "// TODO: test\nfn test() {}").unwrap();
let result = analyze_satd(&[rust_file], false).await;
assert!(result.is_ok());
let output = result.unwrap();
assert_eq!(output["status"], "completed");
assert!(output["message"].is_string());
assert!(output["results"].is_object());
assert!(output["results"]["total_satd"].is_number());
assert!(output["results"]["files"].is_array());
}
#[tokio::test]
async fn test_analyze_dead_code_output_structure() {
let temp_dir = tempdir().unwrap();
let rust_file = temp_dir.path().join("test.rs");
fs::write(&rust_file, "fn test() {}").unwrap();
let result = analyze_dead_code(&[rust_file], false).await;
assert!(result.is_ok());
let output = result.unwrap();
assert_eq!(output["status"], "completed");
assert!(output["results"].is_object());
assert!(output["results"]["total_dead_code"].is_number());
}