From d5f4d6e8cee6f7ab343e35ce97328202af70b2c1 Mon Sep 17 00:00:00 2001 From: nils <48135649+Nilstrieb@users.noreply.github.com> Date: Tue, 11 Apr 2023 10:55:25 +0200 Subject: [PATCH] build regression checker as well --- testsuite/src/bin/regression_checker.rs | 10 +++- testsuite/src/lib.rs | 72 ++++++++++++++++--------- 2 files changed, 57 insertions(+), 25 deletions(-) diff --git a/testsuite/src/bin/regression_checker.rs b/testsuite/src/bin/regression_checker.rs index e71fdf5..eb02856 100644 --- a/testsuite/src/bin/regression_checker.rs +++ b/testsuite/src/bin/regression_checker.rs @@ -1 +1,9 @@ -fn main() {} \ No newline at end of file +fn main() -> anyhow::Result<()> { + let root_var = + std::env::var("MINIMIZE_RUNTEST_ROOTS").expect("MINIMIZE_RUNTEST_ROOTS env var not found"); + let roots = root_var.split(",").collect::>(); + + let proj_dir = std::env::current_dir().expect("current dir not found"); + + testsuite::ensure_correct_minimization(&proj_dir, roots) +} diff --git a/testsuite/src/lib.rs b/testsuite/src/lib.rs index 83d65ab..e711e00 100644 --- a/testsuite/src/lib.rs +++ b/testsuite/src/lib.rs @@ -17,6 +17,43 @@ use std::{ }; use tempfile::TempDir; +/// This is called by the regression_checked binary during minimization and by the test runner at the end. +pub fn ensure_correct_minimization( + proj_dir: &Path, + start_roots: impl IntoIterator>, +) -> Result<()> { + let required_deleted = get_required_deleted(&proj_dir).context("get REQUIRED-DELETED")?; + + ensure!( + required_deleted.is_empty(), + "Some REQUIRE-DELETED have not been deleted: {required_deleted:?}" + ); + + let end_roots = HashSet::<_, RandomState>::from_iter( + get_roots(proj_dir).context("getting final MINIMIZE-ROOTs")?, + ); + for root in start_roots { + let root = root.as_ref(); + ensure!( + end_roots.contains(root), + "{root} was not found after minimization" + ); + } + + Ok(()) +} + +fn run_build(command: &mut Command) -> Result<()> { + let exit = command + .spawn() + .context("failed to spawn command")? + .wait() + .context("failed to wait for command")?; + + ensure!(exit.success(), "command failed"); + Ok(()) +} + #[cfg(not(unix))] pub fn full_tests() -> Result<()> { todo!("FIXME: Make this not cursed.") @@ -24,14 +61,16 @@ pub fn full_tests() -> Result<()> { #[cfg(unix)] pub fn full_tests() -> Result<()> { - let exit = Command::new("cargo") - .arg("build") - .spawn() - .context("spawn: cargo build")? - .wait() - .context("wait: cargo build")?; - - ensure!(exit.success(), "cargo build failed"); + run_build(Command::new("cargo").args([ + "build", + "-p", + "cargo-minimize", + "-p", + "testsuite", + "--bin", + "regression_checker", + ])) + .context("running cargo build")?; let path = Path::new(file!()) .canonicalize()? @@ -193,22 +232,7 @@ fn build(path: &Path) -> Result<()> { "Command failed:\n--- stderr:\n{stderr}\n--- stdout:\n{stdout}" ); - let required_deleted = get_required_deleted(&proj_dir).context("get REQUIRED-DELETED")?; - - ensure!( - required_deleted.is_empty(), - "Some REQUIRE-DELETED have not been deleted: {required_deleted:?}" - ); - - let end_roots = HashSet::<_, RandomState>::from_iter( - get_roots(&proj_dir).context("getting final MINIMIZE-ROOTs")?, - ); - for root in &start_roots { - ensure!( - end_roots.contains(root), - "{root} was not found after minimization" - ); - } + ensure_correct_minimization(&proj_dir, &start_roots)?; Ok(()) }