|
| 1 | +use code_guardian_cli::cli_definitions::{Cli, StackPreset}; |
| 2 | +use clap::Parser; |
| 3 | +use std::path::PathBuf; |
| 4 | + |
| 5 | +#[cfg(test)] |
| 6 | +#[test] |
| 7 | +fn test_cli_help_generation() { |
| 8 | + use clap::CommandFactory; |
| 9 | + let mut cli = Cli::command(); |
| 10 | + let help_output = cli.render_help(); |
| 11 | + |
| 12 | + // Verify the CLI help contains our new commands |
| 13 | + assert!(help_output.to_string().contains("production-check")); |
| 14 | + assert!(help_output.to_string().contains("pre-commit")); |
| 15 | + assert!(help_output.to_string().contains("ci-gate")); |
| 16 | + assert!(help_output.to_string().contains("lang")); |
| 17 | + assert!(help_output.to_string().contains("stack")); |
| 18 | + assert!(help_output.to_string().contains("watch")); |
| 19 | +} |
| 20 | + |
| 21 | +#[cfg(test)] |
| 22 | +#[test] |
| 23 | +fn test_cli_description() { |
| 24 | + use clap::CommandFactory; |
| 25 | + let cli = Cli::command(); |
| 26 | + let about = cli.get_about().unwrap().to_string(); |
| 27 | + |
| 28 | + // Verify the CLI description mentions key features |
| 29 | + assert!(about.contains("Multi-language")); |
| 30 | + assert!(about.contains("production readiness")); |
| 31 | + assert!(about.contains("code quality")); |
| 32 | + // The about text is: "Multi-language code analysis tool for production readiness and code quality" |
| 33 | +} |
| 34 | + |
| 35 | +#[cfg(test)] |
| 36 | +#[test] |
| 37 | +fn test_stack_preset_variants() { |
| 38 | + // Test that all stack presets are properly defined |
| 39 | + let web_preset = StackPreset::Web { |
| 40 | + path: PathBuf::from("."), |
| 41 | + production: false, |
| 42 | + }; |
| 43 | + let backend_preset = StackPreset::Backend { |
| 44 | + path: PathBuf::from("."), |
| 45 | + production: false, |
| 46 | + }; |
| 47 | + let fullstack_preset = StackPreset::Fullstack { |
| 48 | + path: PathBuf::from("."), |
| 49 | + production: false, |
| 50 | + }; |
| 51 | + let mobile_preset = StackPreset::Mobile { |
| 52 | + path: PathBuf::from("."), |
| 53 | + production: false, |
| 54 | + }; |
| 55 | + let systems_preset = StackPreset::Systems { |
| 56 | + path: PathBuf::from("."), |
| 57 | + production: false, |
| 58 | + }; |
| 59 | + |
| 60 | + // Basic validation that variants exist |
| 61 | + match web_preset { |
| 62 | + StackPreset::Web { .. } => (), |
| 63 | + _ => panic!("Web preset should match"), |
| 64 | + } |
| 65 | + match backend_preset { |
| 66 | + StackPreset::Backend { .. } => (), |
| 67 | + _ => panic!("Backend preset should match"), |
| 68 | + } |
| 69 | + match fullstack_preset { |
| 70 | + StackPreset::Fullstack { .. } => (), |
| 71 | + _ => panic!("Fullstack preset should match"), |
| 72 | + } |
| 73 | + match mobile_preset { |
| 74 | + StackPreset::Mobile { .. } => (), |
| 75 | + _ => panic!("Mobile preset should match"), |
| 76 | + } |
| 77 | + match systems_preset { |
| 78 | + StackPreset::Systems { .. } => (), |
| 79 | + _ => panic!("Systems preset should match"), |
| 80 | + } |
| 81 | +} |
| 82 | + |
| 83 | +#[cfg(test)] |
| 84 | +#[test] |
| 85 | +fn test_cli_parse_invalid_subcommand() { |
| 86 | + let args = vec!["code-guardian", "invalid"]; |
| 87 | + let result = Cli::try_parse_from(args); |
| 88 | + assert!(result.is_err()); |
| 89 | +} |
| 90 | + |
| 91 | +#[cfg(test)] |
| 92 | +#[test] |
| 93 | +fn test_cli_parse_scan_missing_path() { |
| 94 | + let args = vec!["code-guardian", "scan"]; |
| 95 | + let result = Cli::try_parse_from(args); |
| 96 | + assert!(result.is_err()); |
| 97 | +} |
| 98 | + |
| 99 | +#[cfg(test)] |
| 100 | +#[test] |
| 101 | +fn test_cli_parse_report_missing_id() { |
| 102 | + let args = vec!["code-guardian", "report"]; |
| 103 | + let result = Cli::try_parse_from(args); |
| 104 | + assert!(result.is_err()); |
| 105 | +} |
| 106 | + |
| 107 | +#[cfg(test)] |
| 108 | +#[test] |
| 109 | +fn test_handle_history_invalid_db() { |
| 110 | + use code_guardian_cli::command_handlers::handle_history; |
| 111 | + let invalid_db = PathBuf::from("/invalid/path/db.db"); |
| 112 | + let result = handle_history(Some(invalid_db)); |
| 113 | + assert!(result.is_err()); |
| 114 | +} |
| 115 | + |
| 116 | +#[cfg(test)] |
| 117 | +#[test] |
| 118 | +fn test_handle_benchmark_invalid_path() { |
| 119 | + use code_guardian_cli::command_handlers::handle_benchmark; |
| 120 | + let invalid_path = PathBuf::from("/invalid/path"); |
| 121 | + let result = handle_benchmark(Some(invalid_path), false); |
| 122 | + assert!(result.is_err()); |
| 123 | +} |
0 commit comments