#![allow(
clippy::unwrap_used,
clippy::expect_used,
clippy::panic,
clippy::needless_raw_string_hashes,
clippy::duration_suboptimal_units,
clippy::branches_sharing_code,
clippy::used_underscore_binding,
clippy::single_char_pattern,
clippy::ignore_without_reason,
clippy::cloned_ref_to_slice_refs,
clippy::doc_overindented_list_items,
clippy::match_wildcard_for_single_variants,
clippy::ignored_unit_patterns,
clippy::needless_collect,
clippy::unnecessary_map_or,
clippy::manual_flatten,
clippy::manual_strip,
clippy::future_not_send,
clippy::unnested_or_patterns,
clippy::no_effect_underscore_binding,
clippy::literal_string_with_formatting_args
)]
use assert_cmd::Command;
use predicates::prelude::*;
use std::fs;
use tempfile::TempDir;
fn ggen() -> Command {
Command::cargo_bin("ggen").expect("Failed to find ggen binary")
}
#[test]
#[ignore]
fn test_project_new_creates_project() {
let temp_dir = TempDir::new().unwrap();
ggen()
.arg("project")
.arg("new")
.arg("test-project")
.arg("--type")
.arg("rust-cli")
.current_dir(&temp_dir)
.assert()
.success();
let project_path = temp_dir.path().join("test-project");
assert!(project_path.exists(), "Project directory should be created");
}
#[test]
#[ignore]
fn test_project_new_with_custom_output() {
let temp_dir = TempDir::new().unwrap();
ggen()
.arg("project")
.arg("new")
.arg("my-app")
.arg("--type")
.arg("rust-cli")
.arg("--output")
.arg(temp_dir.path().join("workspace"))
.current_dir(&temp_dir)
.assert()
.success();
let workspace_path = temp_dir.path().join("workspace");
assert!(
workspace_path.exists(),
"Custom output directory should be created"
);
}
#[test]
#[ignore]
fn test_project_init_creates_structure() {
let temp_dir = TempDir::new().unwrap();
ggen()
.arg("project")
.arg("init")
.arg("--name")
.arg("test-init")
.current_dir(&temp_dir)
.assert()
.success();
let ggen_dir = temp_dir.path().join(".ggen");
assert!(ggen_dir.exists(), ".ggen directory should be created");
}
#[test]
#[ignore]
fn test_project_init_with_preset() {
let temp_dir = TempDir::new().unwrap();
ggen()
.arg("project")
.arg("init")
.arg("--name")
.arg("preset-test")
.arg("--preset")
.arg("clap-noun-verb")
.current_dir(&temp_dir)
.assert()
.success();
let config_path = temp_dir.path().join(".ggen/conventions.toml");
assert!(config_path.exists(), "Config file should be created");
}
#[test]
#[ignore]
fn test_project_plan_generates_plan() {
let temp_dir = TempDir::new().unwrap();
let templates_dir = temp_dir.path().join("templates");
fs::create_dir_all(&templates_dir).unwrap();
let template_path = templates_dir.join("test.tmpl");
fs::write(&template_path, "Hello {{ name }}!").unwrap();
ggen()
.arg("project")
.arg("plan")
.arg("--template")
.arg(template_path.to_str().unwrap())
.arg("--var")
.arg("name=world")
.arg("--output")
.arg("plan.json")
.current_dir(&temp_dir)
.assert()
.success();
let plan_path = temp_dir.path().join("plan.json");
assert!(plan_path.exists(), "Plan file should be created");
}
#[test]
#[ignore]
fn test_project_gen_creates_files() {
let temp_dir = TempDir::new().unwrap();
let templates_dir = temp_dir.path().join("templates");
fs::create_dir_all(&templates_dir).unwrap();
let template_path = templates_dir.join("output.tmpl");
fs::write(&template_path, "Generated: {{ name }}").unwrap();
ggen()
.arg("project")
.arg("gen")
.arg("--template")
.arg(template_path.to_str().unwrap())
.arg("--var")
.arg("name=test")
.current_dir(&temp_dir)
.assert()
.success();
}
#[test]
#[ignore]
fn test_project_gen_dry_run() {
let temp_dir = TempDir::new().unwrap();
let templates_dir = temp_dir.path().join("templates");
fs::create_dir_all(&templates_dir).unwrap();
let template_path = templates_dir.join("test.tmpl");
fs::write(&template_path, "Test content").unwrap();
ggen()
.arg("project")
.arg("gen")
.arg("--template")
.arg(template_path.to_str().unwrap())
.arg("--dry-run")
.current_dir(&temp_dir)
.assert()
.success();
}
#[test]
#[ignore]
fn test_project_help_shows_verbs() {
ggen()
.arg("project")
.arg("--help")
.assert()
.success()
.stdout(predicate::str::contains("new"))
.stdout(predicate::str::contains("plan"))
.stdout(predicate::str::contains("gen"))
.stdout(predicate::str::contains("init"))
.stdout(predicate::str::contains("generate"))
.stdout(predicate::str::contains("watch"));
}
#[test]
#[ignore]
fn test_project_invalid_verb() {
ggen()
.arg("project")
.arg("invalid-verb")
.assert()
.failure()
.stderr(predicate::str::contains("error").or(predicate::str::contains("invalid")));
}
#[test]
#[ignore]
fn test_project_new_invalid_type() {
let temp_dir = TempDir::new().unwrap();
let _ = ggen()
.arg("project")
.arg("new")
.arg("test")
.arg("--type")
.arg("invalid-type-xyz")
.current_dir(&temp_dir)
.output();
}
#[test]
#[ignore]
fn test_project_init_empty_name() {
let temp_dir = TempDir::new().unwrap();
ggen()
.arg("project")
.arg("init")
.arg("--name")
.arg("")
.current_dir(&temp_dir)
.assert()
.failure()
.stderr(predicate::str::contains("empty").or(predicate::str::contains("error")));
}
#[test]
#[ignore]
fn test_project_init_whitespace_name() {
let temp_dir = TempDir::new().unwrap();
ggen()
.arg("project")
.arg("init")
.arg("--name")
.arg("test project")
.current_dir(&temp_dir)
.assert()
.failure()
.stderr(predicate::str::contains("whitespace").or(predicate::str::contains("error")));
}