start with test runner

This commit is contained in:
nora 2023-04-04 12:23:45 +02:00
parent bf8f13c62a
commit c70d6fa26f
6 changed files with 86 additions and 1 deletions

7
Cargo.lock generated
View file

@ -32,6 +32,7 @@ dependencies = [
"anyhow",
"clap",
"ctrlc",
"fs_extra",
"libc",
"owo-colors",
"prettyplease",
@ -137,6 +138,12 @@ dependencies = [
"instant",
]
[[package]]
name = "fs_extra"
version = "1.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "42703706b716c37f96a77aea830392ad231f44c9e9a67872fa5548707e11b11c"
[[package]]
name = "heck"
version = "0.4.0"

View file

@ -1,6 +1,6 @@
[workspace]
members = ["./", "./prettyplease-forked"]
exclude = ["test-cases/*"]
exclude = ["test-cases/*", "full-tests/*"]
[package]
name = "cargo-minimize"
@ -30,3 +30,6 @@ walkdir = "2.3.2"
[target."cfg(unix)".dependencies]
libc = "0.2.138"
[dev-dependencies]
fs_extra = "1.3.0"

View file

@ -0,0 +1,8 @@
[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]

View file

@ -0,0 +1,12 @@
use std::collecions::HashMap;
/// ~REQUIRE-DELETED
fn user(map: HashMap<(), ()>) {
map.insert((), ());
}
/// ~MINIMIZE-ROOT main
fn main() {
let map = HashMap::new();
user(map);
}

View file

@ -36,5 +36,6 @@ fn main() {
if let Err(err) = cargo_minimize::minimize(options, cancel2) {
error!("An error occured:\n{err}");
std::process::exit(1);
}
}

54
tests/full_tests.rs Normal file
View file

@ -0,0 +1,54 @@
use anyhow::{ensure, Context, Result};
use std::process::Command;
use std::{
fs,
io::{self, Write},
path::Path,
};
#[test]
fn full_tests() -> Result<()> {
let path = Path::new(file!())
.canonicalize()?
.parent()
.unwrap()
.parent()
.unwrap()
.join("full-tests");
let children = fs::read_dir(path)?;
for child in children {
let child = child?;
let path = child.path();
build(&path)?;
}
Ok(())
}
fn build(path: &Path) -> Result<()> {
let cargo_minimize = Path::new("target/debug/cargo-minimize").canonicalize()?;
let proj_dir = path.file_name().unwrap().to_str().unwrap();
writeln!(io::stdout(), ".... Testing {}", proj_dir)?;
let tempdir = tempfile::tempdir()?;
fs_extra::copy_items(&[path], &tempdir, &fs_extra::dir::CopyOptions::new())?;
let proj_dir = tempdir.path().join(proj_dir).canonicalize()?;
let mut cmd = Command::new(cargo_minimize);
cmd.current_dir(&proj_dir);
cmd.arg("minimize");
let out = cmd.output().context("spawning cargo-minimize")?;
let stderr = String::from_utf8(out.stderr).unwrap();
// ensure!(out.status.success(), "Command failed:\n{stderr}",);
Ok(())
}