Files
git-commit-prefix-gen/tests/integration_tests.rs
7000pctAUTO 86d1fd74dc
Some checks failed
CI / test (push) Has been cancelled
Add integration tests
2026-01-31 11:41:43 +00:00

61 lines
2.1 KiB
Rust

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();
}
}