use assert_cmd::Command;
use std::collections::HashSet;
use std::fs;
use std::path::Path;
use std::time::Duration;
const MANIFEST_PATH: &str = "tests/fixtures/examples_manifest.txt";
const CHECK_TIMEOUT_SECS: u64 = 10;
fn ruchy_cmd() -> Command {
assert_cmd::cargo::cargo_bin_cmd!("ruchy")
}
fn read_manifest() -> Vec<String> {
let contents = fs::read_to_string(MANIFEST_PATH)
.unwrap_or_else(|e| panic!("failed to read {MANIFEST_PATH}: {e}"));
contents
.lines()
.map(str::trim)
.filter(|line| !line.is_empty())
.map(str::to_string)
.collect()
}
fn assert_check_succeeds(file_path: &str) {
assert!(
Path::new(file_path).exists(),
"manifest entry not found on disk: {file_path}"
);
ruchy_cmd()
.arg("check")
.arg(file_path)
.timeout(Duration::from_secs(CHECK_TIMEOUT_SECS))
.assert()
.success();
}
#[test]
fn test_pmat_095_manifest_no_duplicates_and_files_exist() {
let manifest = read_manifest();
assert!(!manifest.is_empty(), "manifest must not be empty");
let unique: HashSet<&String> = manifest.iter().collect();
assert_eq!(
unique.len(),
manifest.len(),
"manifest contains duplicate entries"
);
for file_path in &manifest {
assert!(
Path::new(file_path).exists(),
"manifest entry not found on disk: {file_path}"
);
}
}
#[test]
fn test_pmat_095_all_manifest_examples_parse() {
let manifest = read_manifest();
let mut failures = Vec::new();
for file_path in &manifest {
let result = std::panic::catch_unwind(|| assert_check_succeeds(file_path));
if result.is_err() {
failures.push(file_path.clone());
}
}
assert!(
failures.is_empty(),
"the following manifest examples failed `ruchy check`: {failures:?}"
);
}
#[test]
fn test_pmat_095_math_science_parses_post_migration() {
assert_check_succeeds("examples/24_math_science.ruchy");
}