diff --git a/src/ast/mod.rs b/src/ast/mod.rs index 0381911..fdec5d0 100644 --- a/src/ast/mod.rs +++ b/src/ast/mod.rs @@ -5,4 +5,3 @@ pub mod parser; pub mod compiler; pub mod environment; pub mod vm; -pub mod tester; diff --git a/src/bin/ast.rs b/src/bin/ast.rs index 042ab10..7eff9e9 100644 --- a/src/bin/ast.rs +++ b/src/bin/ast.rs @@ -1,5 +1,5 @@ use myc::ast::environment::Environment; -use myc::ast::tester; +use myc::utils::tester; use clap::Parser; use std::fs; use std::path::PathBuf; diff --git a/src/lib.rs b/src/lib.rs index a885174..5a9d88a 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,4 +1,5 @@ pub mod ast; +pub mod utils; #[cfg(test)] mod integration_test; diff --git a/src/main.rs b/src/main.rs index 94c4a7e..dee46d8 100644 --- a/src/main.rs +++ b/src/main.rs @@ -231,7 +231,7 @@ impl CompilerApp { } fn run_all_tests(&mut self) { - use myc::ast::tester; + use myc::utils::tester; let results = tester::run_functional_tests(); let mut log = String::from("FUNCTIONAL TEST RESULTS:\n\n"); let mut passed = 0; @@ -244,7 +244,7 @@ impl CompilerApp { } fn run_benchmarks(&mut self, update: bool) { - use myc::ast::tester; + use myc::utils::tester; 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"); } else { diff --git a/src/utils/mod.rs b/src/utils/mod.rs new file mode 100644 index 0000000..7814a0d --- /dev/null +++ b/src/utils/mod.rs @@ -0,0 +1 @@ +pub mod tester; diff --git a/src/ast/tester.rs b/src/utils/tester.rs similarity index 95% rename from src/ast/tester.rs rename to src/utils/tester.rs index 7982f3b..0c1d873 100644 --- a/src/ast/tester.rs +++ b/src/utils/tester.rs @@ -87,7 +87,8 @@ pub fn run_benchmarks(update: bool) -> Vec { let updated_content = if let Some(m) = baseline_match { content.replace(m.get(0).unwrap().as_str(), &format!(";; Benchmark: {}", new_val)) } else { - format!(";; Benchmark: {}\n{}", new_val, content) + format!(";; Benchmark: {} +{}", new_val, content) }; fs::write(&path, updated_content).unwrap(); 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 { #[cfg(test)] mod tests { - use super::*; - #[test] #[cfg(not(debug_assertions))] fn benchmark_regression_test() { + use super::*; let mut success = false; let mut last_failures = String::new(); @@ -157,14 +157,16 @@ mod tests { .map(|r| format!("{}: Median {:?}, Baseline {:?}, Diff {:.2}%", r.name, r.median, r.baseline.unwrap_or_default(), r.diff_pct.unwrap_or(0.0))) .collect::>() - .join("\n"); + .join(" +"); // 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:\n{}", last_failures); + panic!("Performance regression detected after 5 attempts: +{}", last_failures); } } }