From d4b4afb84a22b6f0890f9c5581a83c5ad7958538 Mon Sep 17 00:00:00 2001 From: Samuel Moelius Date: Sun, 24 Mar 2024 20:21:34 -0400 Subject: [PATCH] Rework `custom_build_name` test to use a fixture Instead of creating a new package on the fly --- fixtures/custom_build_name/Cargo.toml | 7 ++++ .../custom_build_name/custom_build_name.rs | 1 + fixtures/custom_build_name/src/lib.rs | 1 + tests/custom_build_name.rs | 36 ++----------------- 4 files changed, 12 insertions(+), 33 deletions(-) create mode 100644 fixtures/custom_build_name/Cargo.toml create mode 120000 fixtures/custom_build_name/custom_build_name.rs create mode 100644 fixtures/custom_build_name/src/lib.rs diff --git a/fixtures/custom_build_name/Cargo.toml b/fixtures/custom_build_name/Cargo.toml new file mode 100644 index 0000000..133de06 --- /dev/null +++ b/fixtures/custom_build_name/Cargo.toml @@ -0,0 +1,7 @@ +[package] +name = "custom_build_name" +version = "0.1.0" +edition = "2021" +publish = false + +build = "custom_build_name.rs" diff --git a/fixtures/custom_build_name/custom_build_name.rs b/fixtures/custom_build_name/custom_build_name.rs new file mode 120000 index 0000000..d7327a7 --- /dev/null +++ b/fixtures/custom_build_name/custom_build_name.rs @@ -0,0 +1 @@ +../../tests/cases/ping.rs \ No newline at end of file diff --git a/fixtures/custom_build_name/src/lib.rs b/fixtures/custom_build_name/src/lib.rs new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/fixtures/custom_build_name/src/lib.rs @@ -0,0 +1 @@ + diff --git a/tests/custom_build_name.rs b/tests/custom_build_name.rs index 60d6886..ebc48c9 100644 --- a/tests/custom_build_name.rs +++ b/tests/custom_build_name.rs @@ -1,18 +1,13 @@ -use anyhow::Result; -use std::{ - fs::{copy, create_dir, write}, - path::Path, -}; -use tempfile::{tempdir, TempDir}; +use std::path::Path; pub mod util; #[test] fn custom_build_name() { - let temp_package = temp_package(Path::new("tests/cases/ping.rs")).unwrap(); + let dir = Path::new("fixtures/custom_build_name"); let mut command = util::build_with_build_wrap(); - command.current_dir(&temp_package); + command.current_dir(dir); let output = util::exec(command, false).unwrap(); assert!(!output.status.success()); @@ -23,28 +18,3 @@ fn custom_build_name() { "stderr does not contain expected string:\n```\n{stderr}\n```", ); } - -#[allow(clippy::disallowed_methods)] -fn temp_package(build_script_path: &Path) -> Result { - let tempdir = tempdir()?; - - write(tempdir.path().join("Cargo.toml"), CARGO_TOML)?; - copy( - build_script_path, - tempdir.path().join("custom_build_name.rs"), - )?; - create_dir(tempdir.path().join("src"))?; - write(tempdir.path().join("src/lib.rs"), "")?; - - Ok(tempdir) -} - -const CARGO_TOML: &str = r#" -[package] -name = "temp-package" -version = "0.1.0" -edition = "2021" -publish = false - -build = "custom_build_name.rs" -"#;