Refactor: Move tester module to utils

This commit is contained in:
Michael Schimmel
2026-02-18 18:09:33 +01:00
parent b6d1d41c8b
commit 193414c1da
6 changed files with 12 additions and 9 deletions
-1
View File
@@ -5,4 +5,3 @@ pub mod parser;
pub mod compiler; pub mod compiler;
pub mod environment; pub mod environment;
pub mod vm; pub mod vm;
pub mod tester;
+1 -1
View File
@@ -1,5 +1,5 @@
use myc::ast::environment::Environment; use myc::ast::environment::Environment;
use myc::ast::tester; use myc::utils::tester;
use clap::Parser; use clap::Parser;
use std::fs; use std::fs;
use std::path::PathBuf; use std::path::PathBuf;
+1
View File
@@ -1,4 +1,5 @@
pub mod ast; pub mod ast;
pub mod utils;
#[cfg(test)] #[cfg(test)]
mod integration_test; mod integration_test;
+2 -2
View File
@@ -231,7 +231,7 @@ impl CompilerApp {
} }
fn run_all_tests(&mut self) { fn run_all_tests(&mut self) {
use myc::ast::tester; use myc::utils::tester;
let results = tester::run_functional_tests(); let results = tester::run_functional_tests();
let mut log = String::from("FUNCTIONAL TEST RESULTS:\n\n"); let mut log = String::from("FUNCTIONAL TEST RESULTS:\n\n");
let mut passed = 0; let mut passed = 0;
@@ -244,7 +244,7 @@ impl CompilerApp {
} }
fn run_benchmarks(&mut self, update: bool) { fn run_benchmarks(&mut self, update: bool) {
use myc::ast::tester; use myc::utils::tester;
if cfg!(debug_assertions) && !update { if cfg!(debug_assertions) && !update {
self.output_log = String::from("⚠️ WARNING: Benchmarks in Debug mode are inaccurate!\nUse Release build for real measurements.\n\n"); self.output_log = String::from("⚠️ WARNING: Benchmarks in Debug mode are inaccurate!\nUse Release build for real measurements.\n\n");
} else { } else {
+1
View File
@@ -0,0 +1 @@
pub mod tester;
+7 -5
View File
@@ -87,7 +87,8 @@ pub fn run_benchmarks(update: bool) -> Vec<BenchmarkResult> {
let updated_content = if let Some(m) = baseline_match { let updated_content = if let Some(m) = baseline_match {
content.replace(m.get(0).unwrap().as_str(), &format!(";; Benchmark: {}", new_val)) content.replace(m.get(0).unwrap().as_str(), &format!(";; Benchmark: {}", new_val))
} else { } else {
format!(";; Benchmark: {}\n{}", new_val, content) format!(";; Benchmark: {}
{}", new_val, content)
}; };
fs::write(&path, updated_content).unwrap(); fs::write(&path, updated_content).unwrap();
results.push(BenchmarkResult { name, median, baseline: None, diff_pct: None, status: format!("UPDATED: {}", new_val) }); results.push(BenchmarkResult { name, median, baseline: None, diff_pct: None, status: format!("UPDATED: {}", new_val) });
@@ -134,11 +135,10 @@ fn parse_duration(s: &str) -> Option<Duration> {
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use super::*;
#[test] #[test]
#[cfg(not(debug_assertions))] #[cfg(not(debug_assertions))]
fn benchmark_regression_test() { fn benchmark_regression_test() {
use super::*;
let mut success = false; let mut success = false;
let mut last_failures = String::new(); let mut last_failures = String::new();
@@ -157,14 +157,16 @@ mod tests {
.map(|r| format!("{}: Median {:?}, Baseline {:?}, Diff {:.2}%", .map(|r| format!("{}: Median {:?}, Baseline {:?}, Diff {:.2}%",
r.name, r.median, r.baseline.unwrap_or_default(), r.diff_pct.unwrap_or(0.0))) r.name, r.median, r.baseline.unwrap_or_default(), r.diff_pct.unwrap_or(0.0)))
.collect::<Vec<_>>() .collect::<Vec<_>>()
.join("\n"); .join("
");
// Give the system a tiny bit of breath between retries // Give the system a tiny bit of breath between retries
std::thread::sleep(std::time::Duration::from_millis(50)); std::thread::sleep(std::time::Duration::from_millis(50));
} }
if !success { if !success {
panic!("Performance regression detected after 5 attempts:\n{}", last_failures); panic!("Performance regression detected after 5 attempts:
{}", last_failures);
} }
} }
} }