use assert_cmd::Command;
use std::fs;
use std::path::Path;
fn ruchy_cmd() -> Command {
assert_cmd::cargo::cargo_bin_cmd!("ruchy")
}
fn test_example_file(file_path: &str) {
assert!(
Path::new(file_path).exists(),
"Example file not found: {file_path}"
);
ruchy_cmd().arg("run").arg(file_path).assert().success();
}
#[test]
fn test_01_basics() {
test_example_file("examples/01_basics.ruchy");
}
#[test]
#[ignore = "BUG: Test failure exposed by workspace testing - needs investigation"]
fn test_02_functions() {
test_example_file("examples/02_functions.ruchy");
}
#[test]
#[ignore = "BUG: Test failure exposed by workspace testing - needs investigation"]
fn test_03_control_flow() {
test_example_file("examples/03_control_flow.ruchy");
}
#[test]
#[ignore = "BUG: Test failure exposed by workspace testing - needs investigation"]
fn test_04_collections() {
test_example_file("examples/04_collections.ruchy");
}
#[test]
fn test_05_strings() {
test_example_file("examples/05_strings.ruchy");
}
#[test]
#[ignore = "Error handling may not be fully implemented"]
fn test_06_error_handling() {
test_example_file("examples/06_error_handling.ruchy");
}
#[test]
#[ignore = "BUG: Test failure exposed by workspace testing - needs investigation"]
fn test_07_pipeline_operator() {
test_example_file("examples/07_pipeline_operator.ruchy");
}
#[test]
#[ignore = "DataFrames may need setup"]
fn test_08_dataframes() {
test_example_file("examples/08_dataframes.ruchy");
}
#[test]
#[ignore = "Async may not be fully implemented"]
fn test_09_async_await() {
test_example_file("examples/09_async_await.ruchy");
}
#[test]
#[ignore = "BUG: Test failure exposed by workspace testing - needs investigation"]
fn test_10_pattern_matching() {
test_example_file("examples/10_pattern_matching.ruchy");
}
#[test]
#[ignore = "BUG: Test failure exposed by workspace testing - needs investigation"]
fn test_11_file_io() {
test_example_file("examples/11_file_io.ruchy");
}
#[test]
#[ignore = "Classes may not be fully implemented"]
fn test_12_classes_structs() {
test_example_file("examples/12_classes_structs.ruchy");
}
#[test]
#[ignore = "BUG: Test failure exposed by workspace testing - needs investigation"]
fn test_13_iterators() {
test_example_file("examples/13_iterators.ruchy");
}
#[test]
#[ignore = "Macros may not be fully implemented"]
fn test_14_macros() {
test_example_file("examples/14_macros.ruchy");
}
#[test]
#[ignore = "Modules may need imports"]
fn test_15_modules() {
test_example_file("examples/15_modules.ruchy");
}
#[test]
#[ignore = "BUG: Test failure exposed by workspace testing - needs investigation"]
fn test_16_testing() {
test_example_file("examples/16_testing.ruchy");
}
#[test]
#[ignore = "BUG: Test failure exposed by workspace testing - needs investigation"]
fn test_17_json_handling() {
test_example_file("examples/17_json_handling.ruchy");
}
#[test]
#[ignore = "BUG: Test failure exposed by workspace testing - needs investigation"]
fn test_18_algorithms() {
test_example_file("examples/18_algorithms.ruchy");
}
#[test]
fn test_19_string_parameters() {
test_example_file("examples/19_string_parameters.ruchy");
}
#[test]
#[ignore = "Web scraping requires network"]
fn test_19_web_scraping() {
test_example_file("examples/19_web_scraping.ruchy");
}
#[test]
#[ignore = "BUG: Test failure exposed by workspace testing - needs investigation"]
fn test_20_cli_apps() {
test_example_file("examples/20_cli_apps.ruchy");
}
#[test]
#[ignore = "Concurrency may not be fully implemented"]
fn test_21_concurrency() {
test_example_file("examples/21_concurrency.ruchy");
}
#[test]
#[ignore = "Database requires setup"]
fn test_22_database() {
test_example_file("examples/22_database.ruchy");
}
#[test]
#[ignore = "Networking requires network"]
fn test_23_networking() {
test_example_file("examples/23_networking.ruchy");
}
#[test]
#[ignore = "BUG: Test failure exposed by workspace testing - needs investigation"]
fn test_24_math_science() {
test_example_file("examples/24_math_science.ruchy");
}
#[test]
#[ignore = "BUG: Test failure exposed by workspace testing - needs investigation"]
fn test_25_regex_text() {
test_example_file("examples/25_regex_text.ruchy");
}
#[test]
#[ignore = "Crypto may require external libs"]
fn test_26_crypto_security() {
test_example_file("examples/26_crypto_security.ruchy");
}
#[test]
#[ignore = "BUG: Test failure exposed by workspace testing - needs investigation"]
fn test_27_datetime() {
test_example_file("examples/27_datetime.ruchy");
}
#[test]
#[ignore = "BUG: Test failure exposed by workspace testing - needs investigation"]
fn test_28_configuration() {
test_example_file("examples/28_configuration.ruchy");
}
#[test]
#[ignore = "BUG: Test failure exposed by workspace testing - needs investigation"]
fn test_all_core_examples_comprehensive() {
let core_examples = vec![
"examples/01_basics.ruchy",
"examples/02_functions.ruchy",
"examples/03_control_flow.ruchy",
"examples/04_collections.ruchy",
"examples/05_strings.ruchy",
];
let mut passed = 0;
let mut failed = Vec::new();
for example in &core_examples {
if Path::new(example).exists() {
let result = ruchy_cmd().arg("run").arg(example).ok();
if result.is_ok() {
passed += 1;
} else {
failed.push(*example);
}
}
}
println!("Core examples: {}/{} passed", passed, core_examples.len());
assert!(
passed >= 3,
"At least 3 core examples should pass, got {passed}"
);
}
#[test]
fn test_property_all_examples_are_valid_utf8() {
let examples_dir = Path::new("examples");
if !examples_dir.exists() {
return;
}
let entries = fs::read_dir(examples_dir).expect("Failed to read examples dir");
for entry in entries {
let entry = entry.expect("Failed to read entry");
let path = entry.path();
if path.extension().and_then(|s| s.to_str()) == Some("ruchy") {
let content =
fs::read_to_string(&path).unwrap_or_else(|_| panic!("Failed to read {path:?}"));
assert!(
content.is_ascii() || content.chars().all(|c| c != '\u{FFFD}'),
"Example {path:?} contains invalid UTF-8"
);
}
}
}
#[test]
fn test_property_all_examples_have_main_or_top_level_code() {
let examples_dir = Path::new("examples");
if !examples_dir.exists() {
return;
}
let entries = fs::read_dir(examples_dir).expect("Failed to read examples dir");
for entry in entries {
let entry = entry.expect("Failed to read entry");
let path = entry.path();
if path.extension().and_then(|s| s.to_str()) == Some("ruchy") {
let content =
fs::read_to_string(&path).unwrap_or_else(|_| panic!("Failed to read {path:?}"));
let has_main = content.contains("fun main()") || content.contains("fn main()");
let has_code = content.lines().any(|l| {
let trimmed = l.trim();
!trimmed.is_empty() && !trimmed.starts_with("//") && !trimmed.starts_with('#')
});
assert!(
has_main || has_code,
"Example {path:?} has no main() and no top-level code"
);
}
}
}