Skip to content

Commit

Permalink
Rework custom_build_name test to use a fixture
Browse files Browse the repository at this point in the history
Instead of creating a new package on the fly
  • Loading branch information
smoelius committed Mar 25, 2024
1 parent e57408a commit 1a57e41
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 33 deletions.
7 changes: 7 additions & 0 deletions fixtures/custom_build_name/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[package]
name = "custom_build_name"
version = "0.1.0"
edition = "2021"
publish = false

build = "custom_build_name.rs"
1 change: 1 addition & 0 deletions fixtures/custom_build_name/custom_build_name.rs
1 change: 1 addition & 0 deletions fixtures/custom_build_name/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

36 changes: 3 additions & 33 deletions tests/custom_build_name.rs
Original file line number Diff line number Diff line change
@@ -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());
Expand All @@ -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<TempDir> {
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"
"#;

0 comments on commit 1a57e41

Please sign in to comment.