This commit is contained in:
60
tests/integration_tests.rs
Normal file
60
tests/integration_tests.rs
Normal file
@@ -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();
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user