diff --git a/tests/integration_tests.rs b/tests/integration_tests.rs new file mode 100644 index 0000000..373e180 --- /dev/null +++ b/tests/integration_tests.rs @@ -0,0 +1,60 @@ +use assert_cmd::Command; +use tempfile::TempDir; +use std::fs; + +#[test] fn test_cli_help() { + let mut cmd = Command::cargo_bin("git-commit-prefix-gen").unwrap(); + cmd.arg("--help").assert().success(); +} + +#[test] fn test_cli_version() { + let mut cmd = Command::cargo_bin("git-commit-prefix-gen").unwrap(); + cmd.arg("--version").assert().success(); +} + +#[test] fn test_cli_format_short() { + let mut cmd = Command::cargo_bin("git-commit-prefix-gen").unwrap(); + cmd.arg("--format").arg("short").assert().success(); +} + +#[test] fn test_cli_format_json() { + let mut cmd = Command::cargo_bin("git-commit-prefix-gen").unwrap(); + cmd.arg("--format").arg("json").assert().success(); +} + +#[test] fn test_cli_type_flag() { + let mut cmd = Command::cargo_bin("git-commit-prefix-gen").unwrap(); + cmd.arg("--type").arg("feat").assert().success(); +} + +#[test] fn test_cli_scope_flag() { + let mut cmd = Command::cargo_bin("git-commit-prefix-gen").unwrap(); + cmd.arg("--scope").arg("auth").assert().success(); +} + +#[test] fn test_cli_dry_run() { + let mut cmd = Command::cargo_bin("git-commit-prefix-gen").unwrap(); + cmd.arg("--dry-run").assert().success(); +} + +#[test] fn test_non_git_directory() { + let temp_dir = TempDir::new().unwrap(); + let mut cmd = Command::cargo_bin("git-commit-prefix-gen").unwrap(); + cmd.current_dir(temp_dir.path()).assert().failure(); +} + +#[test] fn test_git_repository_with_changes() { + let temp_dir = TempDir::new().unwrap(); + fs::write(temp_dir.path().join("Cargo.toml"), "[package]\nname = \"test\"").unwrap(); + fs::write(temp_dir.path().join("main.rs"), "fn main() {}").unwrap(); + std::process::Command::new("git").args(&["init"]).current_dir(temp_dir.path()).output().expect("Failed to run git init"); + let mut cmd = Command::cargo_bin("git-commit-prefix-gen").unwrap(); + cmd.current_dir(temp_dir.path()).arg("--format").arg("compact").assert().success(); +} + +#[test] fn test_all_format_options() { + for format in &["short", "verbose", "compact", "json"] { + let mut cmd = Command::cargo_bin("git-commit-prefix-gen").unwrap(); + cmd.arg("--format").arg(format).assert().success(); + } +}