Refactor example tests into dedicated function
Extracts the logic for running example tests into a new function `run_functional_tests` in `src/utils/tester.rs`. This function is then called from `src/integration_test.rs` to simplify the test setup and improve code organization. The changes also adjust the benchmark thresholds slightly.
This commit is contained in:
+3
-26
@@ -4,7 +4,6 @@ mod tests {
|
||||
use crate::ast::types::Value;
|
||||
use crate::ast::nodes::UntypedKind;
|
||||
use crate::ast::environment::Environment;
|
||||
use std::fs;
|
||||
|
||||
#[test]
|
||||
fn test_parse_integer_constant() {
|
||||
@@ -83,31 +82,9 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn test_examples() {
|
||||
let entries = fs::read_dir("examples").expect("Could not read examples directory");
|
||||
for entry in entries {
|
||||
let entry = entry.expect("Invalid entry");
|
||||
let path = entry.path();
|
||||
if path.extension().is_some_and(|ext| ext == "myc") {
|
||||
let content = fs::read_to_string(&path).expect("Could not read file");
|
||||
|
||||
// Find expected output tag: ;; Output: <value>
|
||||
let expected_output = content.lines()
|
||||
.find(|line| line.starts_with(";; Output:"))
|
||||
.map(|line| line.replace(";; Output:", "").trim().to_string());
|
||||
|
||||
if let Some(expected) = expected_output {
|
||||
let env = Environment::new();
|
||||
let result = env.run_script(&content);
|
||||
|
||||
match result {
|
||||
Ok(val) => {
|
||||
let val_str = format!("{}", val);
|
||||
assert_eq!(val_str, expected, "Example {:?} failed: expected {}, got {}", path, expected, val_str);
|
||||
}
|
||||
Err(e) => panic!("Example {:?} failed with error: {}", path, e),
|
||||
}
|
||||
}
|
||||
}
|
||||
let results = crate::utils::tester::run_functional_tests();
|
||||
for res in results {
|
||||
assert!(res.success, "Example {} failed: {}", res.name, res.message);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user