use crate::cli::commands::AnalyzeCommands;
use anyhow::Result;
#[provable_contracts_macros::contract("pmat-core.yaml", equation = "check_compliance")]
pub async fn handle_tdg(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_tdg_signature() {
let _fn_ref: fn(AnalyzeCommands) -> _ = handle_tdg;
}
#[test]
fn test_module_exports_handler() {
fn _verify_export() {
let _tdg: fn(AnalyzeCommands) -> _ = handle_tdg;
}
}
#[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::TdgOutputFormat;
use std::path::PathBuf;
#[tokio::test]
async fn test_handle_tdg_basic() {
let cmd = AnalyzeCommands::Tdg {
path: PathBuf::from("/nonexistent/path/for/tdg/test"),
threshold: 1.5,
top_files: 10,
format: TdgOutputFormat::Table,
include_components: false,
output: None,
critical_only: false,
verbose: false,
ml: false,
};
let result = handle_tdg(cmd).await;
assert!(result.is_ok() || result.is_err());
}
#[tokio::test]
async fn test_handle_tdg_critical_verbose() {
let cmd = AnalyzeCommands::Tdg {
path: PathBuf::from("/tmp/test-tdg"),
threshold: 2.5,
top_files: 5,
format: TdgOutputFormat::Json,
include_components: true,
output: Some(PathBuf::from("/tmp/tdg-output.json")),
critical_only: true,
verbose: true,
ml: false,
};
let result = handle_tdg(cmd).await;
assert!(result.is_ok() || result.is_err());
}
#[tokio::test]
async fn test_handle_tdg_with_ml() {
let cmd = AnalyzeCommands::Tdg {
path: PathBuf::from("/nonexistent"),
threshold: 1.0,
top_files: 20,
format: TdgOutputFormat::Markdown,
include_components: false,
output: None,
critical_only: false,
verbose: false,
ml: true,
};
let result = handle_tdg(cmd).await;
assert!(result.is_ok() || result.is_err());
}
#[tokio::test]
async fn test_handle_tdg_with_components() {
let cmd = AnalyzeCommands::Tdg {
path: PathBuf::from("/tmp/test-tdg-components"),
threshold: 0.5,
top_files: 0,
format: TdgOutputFormat::Table,
include_components: true,
output: Some(PathBuf::from("/tmp/tdg-components.txt")),
critical_only: false,
verbose: true,
ml: false,
};
let result = handle_tdg(cmd).await;
assert!(result.is_ok() || result.is_err());
}
#[tokio::test]
async fn test_handle_tdg_high_threshold() {
let cmd = AnalyzeCommands::Tdg {
path: PathBuf::from("/nonexistent"),
threshold: 5.0,
top_files: 3,
format: TdgOutputFormat::Markdown,
include_components: false,
output: None,
critical_only: true,
verbose: false,
ml: true,
};
let result = handle_tdg(cmd).await;
assert!(result.is_ok() || result.is_err());
}
#[test]
fn test_handler_function_signature() {
let _: fn(AnalyzeCommands) -> _ = handle_tdg;
}
}