use std::process::Command;
const PMAT_BINARY: &str = env!("CARGO_BIN_EXE_pmat");
#[test]
#[ignore] fn test_agent_analyze_suggests_correct_command() {
let output = Command::new(PMAT_BINARY)
.args(["agent", "analyze"])
.output()
.expect("Failed to run command");
let stderr = String::from_utf8_lossy(&output.stderr);
assert!(
!output.status.success(),
"Command should fail with unrecognized subcommand"
);
assert!(
stderr.contains("Did you mean"),
"Error should contain 'Did you mean' suggestion. Got: {}",
stderr
);
assert!(
stderr.contains("pmat analyze"),
"Should suggest 'pmat analyze'. Got: {}",
stderr
);
}
#[test]
#[ignore] fn test_typo_analize_suggests_analyze() {
let output = Command::new(PMAT_BINARY)
.args(["analize", "complexity"])
.output()
.expect("Failed to run command");
let stderr = String::from_utf8_lossy(&output.stderr);
assert!(!output.status.success(), "Command should fail");
assert!(
stderr.contains("Did you mean"),
"Should suggest correction. Got: {}",
stderr
);
assert!(
stderr.contains("analyze"),
"Should suggest 'analyze'. Got: {}",
stderr
);
}
#[test]
#[ignore] fn test_missing_analyze_prefix_suggests_full_command() {
let output = Command::new(PMAT_BINARY)
.args(["complexity"])
.output()
.expect("Failed to run command");
let stderr = String::from_utf8_lossy(&output.stderr);
assert!(!output.status.success(), "Command should fail");
assert!(
stderr.contains("Did you mean"),
"Should suggest correction. Got: {}",
stderr
);
assert!(
stderr.contains("analyze complexity"),
"Should suggest 'analyze complexity'. Got: {}",
stderr
);
}
#[test]
#[ignore] fn test_satd_typo_suggests_correct_command() {
let test_cases = vec![("std", "satd"), ("stad", "satd"), ("sadt", "satd")];
for (typo, _correct) in test_cases {
let output = Command::new(PMAT_BINARY)
.args(["analyze", typo])
.output()
.expect("Failed to run command");
let stderr = String::from_utf8_lossy(&output.stderr);
assert!(
!output.status.success(),
"Command 'analyze {}' should fail",
typo
);
assert!(
stderr.contains("Did you mean") || stderr.contains("try"),
"Should suggest correction for '{}'. Got: {}",
typo,
stderr
);
}
}
#[test]
#[ignore] fn test_help_provides_working_examples() {
let output = Command::new(PMAT_BINARY)
.args(["--help"])
.output()
.expect("Failed to run command");
let stdout = String::from_utf8_lossy(&output.stdout);
assert!(output.status.success(), "Help command should succeed");
assert!(
stdout.contains("Examples:") || stdout.contains("EXAMPLES"),
"Help should contain examples section. Got: {}",
stdout
);
let working_commands = [
"pmat analyze complexity --project-path .",
"pmat analyze satd --path .",
"pmat context",
"pmat quality-gate",
];
let mut found_examples = 0;
for cmd in &working_commands {
if stdout.contains(cmd) {
found_examples += 1;
}
}
assert!(
found_examples > 0,
"Help should contain at least one working example. Checked: {:?}",
working_commands
);
}
#[test]
#[ignore] fn test_analyze_help_shows_subcommands_clearly() {
let output = Command::new(PMAT_BINARY)
.args(["analyze", "--help"])
.output()
.expect("Failed to run command");
let stdout = String::from_utf8_lossy(&output.stdout);
assert!(output.status.success(), "Analyze help should succeed");
let expected_subcommands = ["complexity", "satd", "dead-code", "tdg"];
for subcmd in &expected_subcommands {
assert!(
stdout.contains(subcmd),
"Help should mention '{}' subcommand. Got: {}",
subcmd,
stdout
);
}
}
#[test]
#[ignore] fn test_command_suggestions_are_ranked_by_similarity() {
let output = Command::new(PMAT_BINARY)
.args(["analyz"]) .output()
.expect("Failed to run command");
let stderr = String::from_utf8_lossy(&output.stderr);
assert!(!output.status.success(), "Command should fail");
if stderr.contains("Did you mean") {
let analyze_pos = stderr.find("analyze");
assert!(
analyze_pos.is_some(),
"Should suggest 'analyze' for 'analyz'. Got: {}",
stderr
);
}
}
#[test]
#[ignore] fn test_valid_commands_dont_show_suggestions() {
let output = Command::new(PMAT_BINARY)
.args(["analyze", "complexity", "--help"])
.output()
.expect("Failed to run command");
let stderr = String::from_utf8_lossy(&output.stderr);
assert!(output.status.success(), "Valid command should succeed");
assert!(
!stderr.contains("Did you mean"),
"Valid commands should not show suggestions. Got: {}",
stderr
);
}