From 45c0581fa9ac94f539fc6d5f7bf01a991310b00e Mon Sep 17 00:00:00 2001 From: nils <48135649+Nilstrieb@users.noreply.github.com> Date: Tue, 4 Apr 2023 14:17:51 +0200 Subject: [PATCH] Support single file tests --- .../src/main.rs => to-empty-main.rs} | 0 full-tests/to-empty-main/Cargo.toml | 8 ----- tests/full_tests.rs | 29 +++++++++++++++---- 3 files changed, 24 insertions(+), 13 deletions(-) rename full-tests/{to-empty-main/src/main.rs => to-empty-main.rs} (100%) delete mode 100644 full-tests/to-empty-main/Cargo.toml diff --git a/full-tests/to-empty-main/src/main.rs b/full-tests/to-empty-main.rs similarity index 100% rename from full-tests/to-empty-main/src/main.rs rename to full-tests/to-empty-main.rs diff --git a/full-tests/to-empty-main/Cargo.toml b/full-tests/to-empty-main/Cargo.toml deleted file mode 100644 index c574a2d..0000000 --- a/full-tests/to-empty-main/Cargo.toml +++ /dev/null @@ -1,8 +0,0 @@ -[package] -name = "to-empty-main" -version = "0.1.0" -edition = "2021" - -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html - -[dependencies] diff --git a/tests/full_tests.rs b/tests/full_tests.rs index 070c5bb..ca97eaf 100644 --- a/tests/full_tests.rs +++ b/tests/full_tests.rs @@ -48,15 +48,34 @@ fn full_tests() -> Result<()> { } fn setup_dir(path: &Path) -> Result<(TempDir, PathBuf)> { - let proj_dir = path.file_name().unwrap().to_str().unwrap(); - - writeln!(io::stdout(), ".... Testing {}", proj_dir)?; - let tempdir = tempfile::tempdir()?; + let proj_name = path.file_name().unwrap().to_str().unwrap(); + let proj_name = if let Some(proj_name) = proj_name.strip_suffix(".rs") { + let out = Command::new("cargo") + .arg("new") + .arg(proj_name) + .current_dir(tempdir.path()) + .output() + .context("spawning cargo new")?; + + ensure!(out.status.success(), "Failed to run cargo new"); + + fs::copy( + path, + tempdir.path().join(proj_name).join("src").join("main.rs"), + ) + .context("copying to main.rs")?; + proj_name + } else { + proj_name + }; + + writeln!(io::stdout(), ".... Testing {}", proj_name)?; + fs_extra::copy_items(&[path], &tempdir, &fs_extra::dir::CopyOptions::new())?; - let proj_dir = tempdir.path().join(proj_dir).canonicalize()?; + let proj_dir = tempdir.path().join(proj_name).canonicalize()?; Ok((tempdir, proj_dir)) }