Initial upload: gitignore-gen Rust CLI tool with 100+ templates
Some checks failed
CI / test (push) Has been cancelled
CI / build (push) Has been cancelled
CI / lint (push) Has been cancelled

This commit is contained in:
2026-02-04 04:43:25 +00:00
parent ad9351cab6
commit 3b5bc0f2d3

View File

@@ -0,0 +1,276 @@
use assert_cmd::Command;
use predicates::prelude::*;
use std::path::PathBuf;
#[test]
fn test_generate_command_exists() {
let mut cmd = Command::cargo_bin("gitignore-gen").unwrap();
cmd.arg("generate").assert().success();
}
#[test]
fn test_list_command_exists() {
let mut cmd = Command::cargo_bin("gitignore-gen").unwrap();
cmd.arg("list").assert().success();
}
#[test]
fn test_search_command_exists() {
let mut cmd = Command::cargo_bin("gitignore-gen").unwrap();
cmd.arg("search").arg("rust").assert().success();
}
#[test]
fn test_interactive_command_exists() {
let mut cmd = Command::cargo_bin("gitignore-gen").unwrap();
cmd.arg("interactive").assert().success();
}
#[test]
fn test_contribute_command_exists() {
let mut cmd = Command::cargo_bin("gitignore-gen").unwrap();
cmd.arg("contribute").arg("test-template").assert().success();
}
#[test]
fn test_info_command_exists() {
let mut cmd = Command::cargo_bin("gitignore-gen").unwrap();
cmd.arg("info").arg("rust").assert().success();
}
#[test]
fn test_update_command_exists() {
let mut cmd = Command::cargo_bin("gitignore-gen").unwrap();
cmd.arg("update").assert().success();
}
#[test]
fn test_generate_with_template() {
let temp_dir = tempfile::tempdir().unwrap();
let output_file = temp_dir.path().join(".gitignore");
let mut cmd = Command::cargo_bin("gitignore-gen").unwrap();
cmd.arg("generate")
.arg("--output")
.arg(&output_file)
.arg("--template")
.arg("rust")
.assert()
.success();
assert!(output_file.exists());
let content = std::fs::read_to_string(&output_file).unwrap();
assert!(content.contains("Generated by gitignore-gen"));
assert!(content.contains("rust"));
}
#[test]
fn test_generate_with_combine() {
let temp_dir = tempfile::tempdir().unwrap();
let output_file = temp_dir.path().join(".gitignore");
let mut cmd = Command::cargo_bin("gitignore-gen").unwrap();
cmd.arg("generate")
.arg("--output")
.arg(&output_file)
.arg("--combine")
.arg("rust,python")
.assert()
.success();
assert!(output_file.exists());
let content = std::fs::read_to_string(&output_file).unwrap();
assert!(content.contains("rust"));
assert!(content.contains("python"));
}
#[test]
fn test_generate_with_custom_patterns() {
let temp_dir = tempfile::tempdir().unwrap();
let output_file = temp_dir.path().join(".gitignore");
let mut cmd = Command::cargo_bin("gitignore-gen").unwrap();
cmd.arg("generate")
.arg("--output")
.arg(&output_file)
.arg("--template")
.arg("rust")
.arg("--custom")
.arg("*.custom,.idea/")
.assert()
.success();
assert!(output_file.exists());
let content = std::fs::read_to_string(&output_file).unwrap();
assert!(content.contains("*.custom"));
assert!(content.contains(".idea/"));
}
#[test]
fn test_list_shows_templates() {
let mut cmd = Command::cargo_bin("gitignore-gen").unwrap();
cmd.arg("list")
.assert()
.success()
.stdout(predicate::str::contains("rust"));
}
#[test]
fn test_list_with_search() {
let mut cmd = Command::cargo_bin("gitignore-gen").unwrap();
cmd.arg("list")
.arg("--search")
.arg("rust")
.assert()
.success()
.stdout(predicate::str::contains("rust"));
}
#[test]
fn test_search_finds_template() {
let mut cmd = Command::cargo_bin("gitignore-gen").unwrap();
cmd.arg("search")
.arg("python")
.assert()
.success()
.stdout(predicate::str::contains("python"));
}
#[test]
fn test_search_no_results() {
let mut cmd = Command::cargo_bin("gitignore-gen").unwrap();
cmd.arg("search")
.arg("xyznonexistent123")
.assert()
.success()
.stdout(predicate::str::contains("No templates found"));
}
#[test]
fn test_info_shows_template() {
let mut cmd = Command::cargo_bin("gitignore-gen").unwrap();
cmd.arg("info")
.arg("rust")
.assert()
.success()
.stdout(predicate::str::contains("rust"))
.stdout(predicate::str::contains("Patterns:"));
}
#[test]
fn test_info_nonexistent_template() {
let mut cmd = Command::cargo_bin("gitignore-gen").unwrap();
cmd.arg("info")
.arg("nonexistent")
.assert()
.success()
.stdout(predicate::str::contains("not found"));
}
#[test]
fn test_update_shows_current_version() {
let mut cmd = Command::cargo_bin("gitignore-gen").unwrap();
cmd.arg("update")
.assert()
.success()
.stdout(predicate::str::contains("up to date"));
}
#[test]
fn test_contribute_shows_guidance() {
let mut cmd = Command::cargo_bin("gitignore-gen").unwrap();
cmd.arg("contribute")
.arg("my-template")
.assert()
.success()
.stdout(predicate::str::contains("my-template"))
.stdout(predicate::str::contains("PR"));
}
#[test]
fn test_version_flag() {
let mut cmd = Command::cargo_bin("gitignore-gen").unwrap();
cmd.arg("--version")
.assert()
.success()
.stdout(predicate::str::contains("gitignore-gen"));
}
#[test]
fn test_help_flag() {
let mut cmd = Command::cargo_bin("gitignore-gen").unwrap();
cmd.arg("--help")
.assert()
.success()
.stdout(predicate::str::contains("USAGE"))
.stdout(predicate::str::contains("SUBCOMMANDS"));
}
#[test]
fn test_generate_help() {
let mut cmd = Command::cargo_bin("gitignore-gen").unwrap();
cmd.arg("generate")
.arg("--help")
.assert()
.success()
.stdout(predicate::str::contains("USAGE"))
.stdout(predicate::str::contains("--output"))
.stdout(predicate::str::contains("--template"));
}
#[test]
fn test_list_help() {
let mut cmd = Command::cargo_bin("gitignore-gen").unwrap();
cmd.arg("list")
.arg("--help")
.assert()
.success()
.stdout(predicate::str::contains("--category"))
.stdout(predicate::str::contains("--search"));
}
#[test]
fn test_generate_default_output() {
let temp_dir = tempfile::tempdir().unwrap();
std::env::set_current_dir(&temp_dir).unwrap();
let mut cmd = Command::cargo_bin("gitignore-gen").unwrap();
cmd.arg("generate")
.arg("--template")
.arg("rust")
.assert()
.success();
let gitignore = PathBuf::from(".gitignore");
assert!(gitignore.exists());
let content = std::fs::read_to_string(&gitignore).unwrap();
assert!(content.contains("Generated by gitignore-gen"));
std::env::set_current_dir("/app").unwrap();
}
#[test]
fn test_generate_append_custom_patterns() {
let temp_dir = tempfile::tempdir().unwrap();
let output_file = temp_dir.path().join(".gitignore");
let mut cmd = Command::cargo_bin("gitignore-gen").unwrap();
cmd.arg("generate")
.arg("--output")
.arg(&output_file)
.arg("--template")
.arg("rust")
.arg("--custom")
.arg("*.app")
.arg("--append")
.assert()
.success();
let content = std::fs::read_to_string(&output_file).unwrap();
assert!(content.contains("*.app"));
assert!(content.contains("# Custom patterns"));
}