use crate::cli::commands::AnalyzeCommands;
use anyhow::Result;
#[provable_contracts_macros::contract("pmat-core.yaml", equation = "check_compliance")]
pub async fn handle_complexity(cmd: AnalyzeCommands) -> Result<()> {
crate::cli::handlers::route_analyze_command(cmd).await
}
#[cfg_attr(coverage_nightly, coverage(off))]
#[cfg(test)]
mod unit_tests {
use super::*;
#[test]
fn test_handle_complexity_signature() {
let _fn_ref: fn(AnalyzeCommands) -> _ = handle_complexity;
}
#[test]
fn test_module_exports_handler() {
fn _verify_export() {
let _complexity: fn(AnalyzeCommands) -> _ = handle_complexity;
}
}
#[test]
fn test_result_type_compatibility() {
fn _check_result_type() -> Result<()> {
Ok(())
}
assert!(_check_result_type().is_ok());
}
#[test]
fn test_handler_is_async() {
fn _verify_async_nature() {
}
}
}
#[cfg_attr(coverage_nightly, coverage(off))]
#[cfg(test)]
mod coverage_tests {
use super::*;
use crate::cli::enums::ComplexityOutputFormat;
use std::path::PathBuf;
#[tokio::test]
async fn test_handle_complexity_basic() {
let cmd = AnalyzeCommands::Complexity {
path: PathBuf::from("/nonexistent/path/for/complexity/test"),
project_path: None,
file: None,
files: vec![],
toolchain: None,
format: ComplexityOutputFormat::Summary,
output: None,
max_cyclomatic: None,
max_cognitive: None,
include: vec![],
watch: false,
top_files: 10,
fail_on_violation: false,
timeout: 60,
ml: false,
};
let result = handle_complexity(cmd).await;
assert!(result.is_ok() || result.is_err());
}
#[tokio::test]
async fn test_handle_complexity_with_file_and_thresholds() {
let cmd = AnalyzeCommands::Complexity {
path: PathBuf::from("/tmp/test-complexity"),
project_path: None,
file: Some(PathBuf::from("/tmp/test-complexity/main.rs")),
files: vec![],
toolchain: Some("rust".to_string()),
format: ComplexityOutputFormat::Json,
output: Some(PathBuf::from("/tmp/complexity-output.json")),
max_cyclomatic: Some(15),
max_cognitive: Some(10),
include: vec![],
watch: false,
top_files: 5,
fail_on_violation: true,
timeout: 120,
ml: false,
};
let result = handle_complexity(cmd).await;
assert!(result.is_ok() || result.is_err());
}
#[tokio::test]
async fn test_handle_complexity_with_files_list() {
let cmd = AnalyzeCommands::Complexity {
path: PathBuf::from("/nonexistent"),
project_path: None,
file: None,
files: vec![
PathBuf::from("/tmp/file1.rs"),
PathBuf::from("/tmp/file2.rs"),
PathBuf::from("/tmp/file3.rs"),
],
toolchain: None,
format: ComplexityOutputFormat::Summary,
output: None,
max_cyclomatic: None,
max_cognitive: None,
include: vec![],
watch: false,
top_files: 0,
fail_on_violation: false,
timeout: 30,
ml: true,
};
let result = handle_complexity(cmd).await;
assert!(result.is_ok() || result.is_err());
}
#[tokio::test]
async fn test_handle_complexity_deprecated_project_path() {
let cmd = AnalyzeCommands::Complexity {
path: PathBuf::from("."),
project_path: Some(PathBuf::from("/tmp/deprecated-path")),
file: None,
files: vec![],
toolchain: None,
format: ComplexityOutputFormat::Full,
output: None,
max_cyclomatic: Some(20),
max_cognitive: Some(15),
include: vec!["**/*.rs".to_string()],
watch: false,
top_files: 10,
fail_on_violation: false,
timeout: 60,
ml: false,
};
let result = handle_complexity(cmd).await;
assert!(result.is_ok() || result.is_err());
}
#[test]
fn test_handler_function_signature() {
let _: fn(AnalyzeCommands) -> _ = handle_complexity;
}
}