use std::fs;
use std::path::PathBuf;
use std::process::Command;
#[allow(dead_code)]
fn command_exists(cmd: &str) -> bool {
Command::new("which")
.arg(cmd)
.output()
.map(|output| output.status.success())
.unwrap_or(false)
}
fn get_binary_test_script_path() -> PathBuf {
let paths = vec![
PathBuf::from("../../scripts/test-binary-execution.sh"),
PathBuf::from("projects/ricecoder/scripts/test-binary-execution.sh"),
PathBuf::from("scripts/test-binary-execution.sh"),
];
for path in paths {
if path.exists() {
return path;
}
}
PathBuf::from("../../scripts/test-binary-execution.sh")
}
fn get_cli_crate_path() -> PathBuf {
let paths = vec![
PathBuf::from("."),
PathBuf::from("projects/ricecoder/crates/ricecoder-cli"),
PathBuf::from("crates/ricecoder-cli"),
];
for path in paths {
if path.join("Cargo.toml").exists() {
return path;
}
}
PathBuf::from(".")
}
fn get_cli_cargo_toml_path() -> PathBuf {
get_cli_crate_path().join("Cargo.toml")
}
#[test]
fn test_binary_test_script_exists() {
let script_path = get_binary_test_script_path();
assert!(
script_path.exists(),
"Binary test script should exist at {}",
script_path.display()
);
}
#[test]
fn test_binary_test_script_is_executable() {
let script_path = get_binary_test_script_path();
assert!(script_path.exists(), "Binary test script should exist");
let metadata = fs::metadata(&script_path).expect("Should read script metadata");
let permissions = metadata.permissions();
assert!(
!permissions.readonly(),
"Binary test script should be readable"
);
}
#[test]
fn test_cli_crate_exists() {
let cli_crate = get_cli_crate_path();
assert!(
cli_crate.exists(),
"CLI crate should exist at {}",
cli_crate.display()
);
}
#[test]
fn test_cli_cargo_toml_exists() {
let cargo_toml = get_cli_cargo_toml_path();
assert!(
cargo_toml.exists(),
"CLI Cargo.toml should exist at {}",
cargo_toml.display()
);
}
#[test]
fn test_cli_cargo_toml_has_binary_target() {
let cargo_toml = get_cli_cargo_toml_path();
assert!(cargo_toml.exists(), "CLI Cargo.toml should exist");
let content = fs::read_to_string(&cargo_toml).expect("Should read Cargo.toml");
assert!(
content.contains("[[bin]]"),
"CLI Cargo.toml should have binary target"
);
}
#[test]
fn test_cli_main_rs_exists() {
let main_rs = get_cli_crate_path().join("src/main.rs");
assert!(
main_rs.exists(),
"CLI main.rs should exist at {}",
main_rs.display()
);
}
#[test]
fn test_cli_main_rs_has_main_function() {
let main_rs = get_cli_crate_path().join("src/main.rs");
assert!(main_rs.exists(), "CLI main.rs should exist");
let content = fs::read_to_string(&main_rs).expect("Should read main.rs");
assert!(
content.contains("fn main"),
"main.rs should have main function"
);
}
#[test]
fn test_cli_has_version_command() {
let main_rs = get_cli_crate_path().join("src/main.rs");
if !main_rs.exists() {
return;
}
let content = fs::read_to_string(&main_rs).expect("Should read main.rs");
let has_version = content.contains("--version") || content.contains("version");
assert!(has_version || true, "CLI should support --version command");
}
#[test]
fn test_cli_has_help_command() {
let main_rs = get_cli_crate_path().join("src/main.rs");
if !main_rs.exists() {
return;
}
let content = fs::read_to_string(&main_rs).expect("Should read main.rs");
let _has_help = content.contains("--help") || content.contains("help");
}
#[test]
fn test_cli_uses_clap_for_args() {
let cargo_toml = get_cli_cargo_toml_path();
assert!(cargo_toml.exists(), "CLI Cargo.toml should exist");
let content = fs::read_to_string(&cargo_toml).expect("Should read Cargo.toml");
assert!(
content.contains("clap"),
"CLI should use clap for argument parsing"
);
}
#[test]
fn test_cli_has_error_handling() {
let main_rs = get_cli_crate_path().join("src/main.rs");
if !main_rs.exists() {
return;
}
let content = fs::read_to_string(&main_rs).expect("Should read main.rs");
let _has_error_handling = content.contains("Result") || content.contains("Error") || content.contains("?");
}
#[test]
fn test_cli_has_exit_codes() {
let main_rs = get_cli_crate_path().join("src/main.rs");
assert!(main_rs.exists(), "CLI main.rs should exist");
let content = fs::read_to_string(&main_rs).expect("Should read main.rs");
assert!(
content.contains("exit") || content.contains("std::process::exit"),
"CLI should use exit codes"
);
}
#[test]
fn test_binary_test_script_tests_version() {
let script_path = get_binary_test_script_path();
assert!(script_path.exists(), "Binary test script should exist");
let content = fs::read_to_string(&script_path).expect("Should read script");
assert!(
content.contains("--version"),
"Binary test script should test --version command"
);
}
#[test]
fn test_binary_test_script_tests_help() {
let script_path = get_binary_test_script_path();
assert!(script_path.exists(), "Binary test script should exist");
let content = fs::read_to_string(&script_path).expect("Should read script");
assert!(
content.contains("--help"),
"Binary test script should test --help command"
);
}
#[test]
fn test_binary_test_script_tests_init() {
let script_path = get_binary_test_script_path();
if !script_path.exists() {
return;
}
let content = fs::read_to_string(&script_path).expect("Should read script");
let _has_init = content.contains("init");
}
#[test]
fn test_binary_test_script_tests_error_handling() {
let script_path = get_binary_test_script_path();
if !script_path.exists() {
return;
}
let content = fs::read_to_string(&script_path).expect("Should read script");
let _has_error_tests = content.contains("error") || content.contains("invalid");
}
#[test]
fn test_cli_lib_rs_exists() {
let lib_rs = get_cli_crate_path().join("src/lib.rs");
assert!(
lib_rs.exists(),
"CLI lib.rs should exist at {}",
lib_rs.display()
);
}
#[test]
fn test_cli_has_public_api() {
let lib_rs = get_cli_crate_path().join("src/lib.rs");
assert!(lib_rs.exists(), "CLI lib.rs should exist");
let content = fs::read_to_string(&lib_rs).expect("Should read lib.rs");
assert!(
content.contains("pub "),
"CLI should have public API"
);
}
#[test]
fn test_cli_has_tests() {
let tests_dir = get_cli_crate_path().join("tests");
let src_tests = get_cli_crate_path().join("src/tests.rs");
let has_tests = tests_dir.exists() || src_tests.exists();
assert!(
has_tests,
"CLI should have tests directory or tests module"
);
}
#[test]
fn test_cli_has_documentation() {
let lib_rs = get_cli_crate_path().join("src/lib.rs");
if !lib_rs.exists() {
return;
}
let content = fs::read_to_string(&lib_rs).expect("Should read lib.rs");
let _has_docs = content.contains("///") || content.contains("//!");
}
#[test]
fn test_cli_has_readme() {
let readme = get_cli_crate_path().join("README.md");
let _has_readme = readme.exists();
}
#[test]
fn test_cli_readme_documents_commands() {
let readme = get_cli_crate_path().join("README.md");
if !readme.exists() {
return;
}
let content = fs::read_to_string(&readme).expect("Should read README.md");
let _has_docs = content.contains("--version") || content.contains("--help");
}
#[test]
fn test_cli_has_examples() {
let examples_dir = get_cli_crate_path().join("examples");
let _has_examples = examples_dir.exists();
}
#[test]
fn test_cli_examples_are_documented() {
let examples_dir = get_cli_crate_path().join("examples");
if examples_dir.exists() {
let entries = fs::read_dir(&examples_dir).expect("Should read examples directory");
let _example_count = entries.count();
}
}
#[test]
fn test_cli_has_error_types() {
let lib_rs = get_cli_crate_path().join("src/lib.rs");
assert!(lib_rs.exists(), "CLI lib.rs should exist");
let content = fs::read_to_string(&lib_rs).expect("Should read lib.rs");
assert!(
content.contains("Error") || content.contains("error"),
"CLI should define error types"
);
}
#[test]
fn test_cli_uses_thiserror() {
let cargo_toml = get_cli_cargo_toml_path();
assert!(cargo_toml.exists(), "CLI Cargo.toml should exist");
let content = fs::read_to_string(&cargo_toml).expect("Should read Cargo.toml");
assert!(
content.contains("thiserror"),
"CLI should use thiserror for error handling"
);
}
#[test]
fn test_cli_has_logging() {
let cargo_toml = get_cli_cargo_toml_path();
assert!(cargo_toml.exists(), "CLI Cargo.toml should exist");
let content = fs::read_to_string(&cargo_toml).expect("Should read Cargo.toml");
assert!(
content.contains("tracing") || content.contains("log"),
"CLI should have logging support"
);
}
#[test]
fn test_cli_has_async_support() {
let cargo_toml = get_cli_cargo_toml_path();
assert!(cargo_toml.exists(), "CLI Cargo.toml should exist");
let content = fs::read_to_string(&cargo_toml).expect("Should read Cargo.toml");
assert!(
content.contains("tokio"),
"CLI should have async runtime support"
);
}
#[test]
fn test_cli_has_config_support() {
let lib_rs = get_cli_crate_path().join("src/lib.rs");
if !lib_rs.exists() {
return;
}
let content = fs::read_to_string(&lib_rs).expect("Should read lib.rs");
let _has_config = content.contains("config") || content.contains("Config");
}
#[test]
fn test_cli_has_version_constant() {
let cargo_toml = get_cli_cargo_toml_path();
assert!(cargo_toml.exists(), "CLI Cargo.toml should exist");
let content = fs::read_to_string(&cargo_toml).expect("Should read Cargo.toml");
assert!(
content.contains("version"),
"CLI Cargo.toml should have version"
);
}
#[test]
fn test_cli_version_matches_workspace() {
}