use anyhow::Result;
use ferrisup;
use std::fs;
mod common;
#[test]
fn test_ferrisup_version() -> Result<()> {
let cargo_version = env!("CARGO_PKG_VERSION");
assert!(!cargo_version.is_empty(), "Version should not be empty");
assert!(std::process::Command::new(env!("CARGO_BIN_EXE_ferrisup"))
.arg("--version")
.status()?
.success());
Ok(())
}
#[test]
fn test_cargo_metadata() -> Result<()> {
assert!(!env!("CARGO_PKG_AUTHORS").is_empty(), "Authors should be specified");
assert!(!env!("CARGO_PKG_DESCRIPTION").is_empty(), "Description should be provided");
assert!(!env!("CARGO_PKG_LICENSE").is_empty(), "License should be specified");
assert!(!env!("CARGO_PKG_REPOSITORY").is_empty(), "Repository URL should be provided");
let cargo_toml_content = std::fs::read_to_string("Cargo.toml")?;
assert!(cargo_toml_content.contains("keywords = ["),
"Keywords should be provided in Cargo.toml for crates.io discoverability");
Ok(())
}
#[test]
#[ignore]
fn test_all_templates() -> Result<()> {
use std::process::{Command, Stdio};
use tempfile::TempDir;
let template_tuples = ferrisup::template_manager::list_templates()?;
let _template_count = template_tuples.len();
let mut success_count = 0;
let mut failed_templates = Vec::new();
for (template_name, _template_description) in &template_tuples {
assert!(!template_name.is_empty());
if template_name.contains("embedded") || template_name.contains("edge") {
continue;
}
let temp_dir = TempDir::new()?;
let project_name = format!("test_{}", template_name.replace("-", "_"));
let output = Command::new(env!("CARGO_BIN_EXE_ferrisup"))
.args(&[
"new",
&project_name,
"--template",
&template_name,
"--no-interactive" ])
.current_dir(temp_dir.path())
.stdout(Stdio::piped())
.stderr(Stdio::piped())
.output()?;
let stdout = String::from_utf8_lossy(&output.stdout).to_string();
let stderr = String::from_utf8_lossy(&output.stderr).to_string();
if !stdout.is_empty() {
}
if !stderr.is_empty() {
}
if !output.status.success() {
failed_templates.push(template_name);
} else {
success_count += 1;
let src_dir = temp_dir.path().join(&project_name).join("src");
if src_dir.exists() {
let cargo_toml = temp_dir.path().join(&project_name).join("Cargo.toml");
assert!(cargo_toml.exists(), "Cargo.toml should be created");
let cargo_content = fs::read_to_string(&cargo_toml)?;
assert!(cargo_content.contains(&project_name), "Cargo.toml should contain project name");
} else {
}
}
}
if !failed_templates.is_empty() {
}
assert!(success_count > 0, "At least one template should create successfully");
Ok(())
}
#[test]
fn test_readme_contains_required_sections() -> Result<()> {
use std::fs;
let readme = fs::read_to_string("README.md")?;
assert!(readme.contains("# FerrisUp"), "README should have a title");
assert!(readme.contains("## Installation"), "README should have installation instructions");
assert!(readme.contains("## Usage"), "README should have usage instructions");
assert!(readme.contains("## License"), "README should have license information");
Ok(())
}