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:
Michael Schimmel
2026-02-21 15:01:36 +01:00
parent 212afd76df
commit 26f0ed9531
2 changed files with 14 additions and 57 deletions
+11 -31
View File
@@ -103,14 +103,14 @@ pub fn run_benchmarks(update: bool) -> Vec<BenchmarkResult> {
}
};
// Helper to measure sum of VM execution times over N fresh environments
// Helper to measure sum of VM execution times over N executions in one environment
let measure_sum =
|n: u32, node: &crate::ast::compiler::TypedNode| -> Result<Duration, String> {
let env = Environment::new();
// Link once per sample
let linked = env.link(node.clone());
let mut total = Duration::ZERO;
for _ in 0..n {
let env = Environment::new();
// Link is still required per environment as it populates registries
let linked = env.link(node.clone());
let start = Instant::now();
let _ = env.run(&linked)?;
total += start.elapsed();
@@ -234,7 +234,7 @@ pub fn run_benchmarks(update: bool) -> Vec<BenchmarkResult> {
let diff = (median_single.as_nanos() as f64 / baseline.as_nanos() as f64) - 1.0;
let threshold = if is_release { 0.10 } else { 0.25 };
let threshold = if is_release { 0.15 } else { 0.30 };
let status = if median_single > baseline && diff > threshold {
"FAILED"
} else {
@@ -296,19 +296,11 @@ mod tests {
#[cfg(not(debug_assertions))]
fn benchmark_regression_test() {
use super::*;
let mut success = false;
let mut last_failures = String::new();
let results = run_benchmarks(false);
let failures: Vec<_> = results.iter().filter(|r| r.status == "FAILED").collect();
for _ in 0..5 {
let results = run_benchmarks(false);
let failures: Vec<_> = results.iter().filter(|r| r.status == "FAILED").collect();
if failures.is_empty() {
success = true;
break;
}
last_failures = failures
if !failures.is_empty() {
let error_msg = failures
.iter()
.map(|r| {
format!(
@@ -320,21 +312,9 @@ mod tests {
)
})
.collect::<Vec<_>>()
.join(
"
",
);
.join("\n");
// Give the system a tiny bit of breath between retries
std::thread::sleep(std::time::Duration::from_millis(50));
}
if !success {
panic!(
"Performance regression detected after 5 attempts:
{}",
last_failures
);
panic!("Performance regression detected:\n{}", error_msg);
}
}
}