From 250f0cd557fccfd478ac82ebadb1f029cf845a25 Mon Sep 17 00:00:00 2001 From: nils <48135649+Nilstrieb@users.noreply.github.com> Date: Tue, 11 Apr 2023 11:24:09 +0200 Subject: [PATCH] Dont use script --- testsuite/src/bin/regression_checker.rs | 11 +++- testsuite/src/lib.rs | 72 ++++++++++++++++--------- 2 files changed, 58 insertions(+), 25 deletions(-) diff --git a/testsuite/src/bin/regression_checker.rs b/testsuite/src/bin/regression_checker.rs index eb02856..7c1c6bf 100644 --- a/testsuite/src/bin/regression_checker.rs +++ b/testsuite/src/bin/regression_checker.rs @@ -1,9 +1,18 @@ fn main() -> anyhow::Result<()> { + if std::env::var("MINIMIZE_LINTS").as_deref() == Ok("1") { + std::process::Command::new("cargo") + .arg("check") + .spawn() + .unwrap() + .wait() + .unwrap(); + } + 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) + testsuite::ensure_roots_kept(&proj_dir, roots) } diff --git a/testsuite/src/lib.rs b/testsuite/src/lib.rs index a914e53..9819d79 100644 --- a/testsuite/src/lib.rs +++ b/testsuite/src/lib.rs @@ -4,6 +4,7 @@ use rayon::prelude::{IntoParallelIterator, ParallelIterator}; use regex::Regex; use std::collections::hash_map::RandomState; use std::collections::HashSet; +use std::ffi::OsString; use std::fs::Permissions; use std::io::BufWriter; #[cfg(unix)] @@ -18,17 +19,10 @@ 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( +pub fn ensure_roots_kept( 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")?, ); @@ -72,17 +66,31 @@ pub fn full_tests() -> Result<()> { ])) .context("running cargo build")?; - let path = Path::new(file!()) - .canonicalize()? - .parent() - .unwrap() - .parent() - .unwrap() - .parent() - .unwrap() - .join("full-tests"); + let this_file = Path::new(file!()) + .canonicalize() + .with_context(|| format!("failed to find current file: {}", file!()))?; - let children = fs::read_dir(&path).with_context(|| format!("reading {}", path.display()))?; + let root_dir = this_file + .parent() + .unwrap() + .parent() + .unwrap() + .parent() + .unwrap(); + + let full_tests_path = root_dir.join("full-tests"); + + let mut regression_checker_path = root_dir + .join("target") + .join("debug") + .join("regression_checker"); + + if cfg!(windows) { + regression_checker_path.set_extension("exe"); + } + + let children = fs::read_dir(&full_tests_path) + .with_context(|| format!("reading {}", full_tests_path.display()))?; let children = children .map(|e| e.map_err(Into::into)) @@ -94,14 +102,16 @@ pub fn full_tests() -> Result<()> { .map(|child| { let path = child.path(); - build(&path).with_context(|| format!("building {:?}", path.file_name().unwrap())) + build(&path, ®ression_checker_path) + .with_context(|| format!("building {:?}", path.file_name().unwrap())) }) .collect::>>()?; } else { for child in children { let path = child.path(); - build(&path).with_context(|| format!("building {:?}", path.file_name().unwrap()))?; + build(&path, ®ression_checker_path) + .with_context(|| format!("building {:?}", path.file_name().unwrap()))?; } } @@ -206,7 +216,7 @@ cargo check Ok(()) } -fn build(path: &Path) -> Result<()> { +fn build(path: &Path, regression_checker_path: &Path) -> Result<()> { let (_tempdir, proj_dir) = setup_dir(path).context("setting up tempdir")?; let mut cargo_minimize_path = PathBuf::from("target/debug/cargo-minimize"); if cfg!(windows) { @@ -224,8 +234,15 @@ fn build(path: &Path) -> Result<()> { cmd.current_dir(&proj_dir); cmd.arg("minimize"); - cmd.arg("--script-path=./check.sh"); - cmd.arg("--script-path-lints=./lint.sh"); + cmd.arg({ + let mut flag = OsString::from("--script-path="); + flag.push(regression_checker_path); + flag + }); + + let minimize_roots = start_roots.join(","); + + cmd.env("MINIMIZE_RUNTEST_ROOTS", &minimize_roots); let out = cmd.output().context("spawning cargo-minimize")?; let stderr = String::from_utf8(out.stderr).unwrap(); @@ -236,7 +253,14 @@ fn build(path: &Path) -> Result<()> { "Command failed:\n--- stderr:\n{stderr}\n--- stdout:\n{stdout}" ); - ensure_correct_minimization(&proj_dir, &start_roots)?; + 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:?}" + ); + + ensure_roots_kept(&proj_dir, &start_roots)?; Ok(()) }