mirror of
https://github.com/Noratrieb/cargo-minimize.git
synced 2026-01-14 08:25:01 +01:00
Support single file tests
This commit is contained in:
parent
c9198c0111
commit
45c0581fa9
3 changed files with 24 additions and 13 deletions
|
|
@ -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]
|
||||
|
|
@ -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))
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue