mirror of
https://github.com/Noratrieb/cargo-minimize.git
synced 2026-01-14 16:35:01 +01:00
further test suite
This commit is contained in:
parent
c70d6fa26f
commit
ff26987129
4 changed files with 76 additions and 10 deletions
31
Cargo.lock
generated
31
Cargo.lock
generated
|
|
@ -2,6 +2,15 @@
|
|||
# It is not intended for manual editing.
|
||||
version = 3
|
||||
|
||||
[[package]]
|
||||
name = "aho-corasick"
|
||||
version = "0.7.20"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "cc936419f96fa211c1b9166887b38e5e40b19958e5b895be7c1f93adec7071ac"
|
||||
dependencies = [
|
||||
"memchr",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "anyhow"
|
||||
version = "1.0.65"
|
||||
|
|
@ -34,10 +43,12 @@ dependencies = [
|
|||
"ctrlc",
|
||||
"fs_extra",
|
||||
"libc",
|
||||
"once_cell",
|
||||
"owo-colors",
|
||||
"prettyplease",
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"regex",
|
||||
"rustfix",
|
||||
"serde",
|
||||
"serde_json",
|
||||
|
|
@ -241,6 +252,12 @@ dependencies = [
|
|||
"regex-automata",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "memchr"
|
||||
version = "2.5.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "2dffe52ecf27772e601905b7522cb4ef790d2cc203488bbd0e2fe85fcb74566d"
|
||||
|
||||
[[package]]
|
||||
name = "nix"
|
||||
version = "0.26.2"
|
||||
|
|
@ -265,9 +282,9 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "once_cell"
|
||||
version = "1.15.0"
|
||||
version = "1.17.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e82dad04139b71a90c080c8463fe0dc7902db5192d939bd0950f074d014339e1"
|
||||
checksum = "b7e5500299e16ebb147ae15a00a942af264cf3688f47923b8fc2cd5858f23ad3"
|
||||
|
||||
[[package]]
|
||||
name = "os_str_bytes"
|
||||
|
|
@ -354,10 +371,12 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "regex"
|
||||
version = "1.6.0"
|
||||
version = "1.7.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "4c4eb3267174b8c6c2f654116623910a0fef09c4753f8dd83db29c48a0df988b"
|
||||
checksum = "8b1f693b24f6ac912f4893ef08244d70b6067480d2f1a46e950c9691e6749d1d"
|
||||
dependencies = [
|
||||
"aho-corasick",
|
||||
"memchr",
|
||||
"regex-syntax",
|
||||
]
|
||||
|
||||
|
|
@ -372,9 +391,9 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "regex-syntax"
|
||||
version = "0.6.27"
|
||||
version = "0.6.29"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a3f87b73ce11b1619a3c6332f45341e0047173771e8b8b73f87bfeefb7b56244"
|
||||
checksum = "f162c6dd7b008981e4d40210aca20b4bd0f9b60ca9271061b07f78537722f2e1"
|
||||
|
||||
[[package]]
|
||||
name = "remove_dir_all"
|
||||
|
|
|
|||
|
|
@ -33,3 +33,5 @@ libc = "0.2.138"
|
|||
|
||||
[dev-dependencies]
|
||||
fs_extra = "1.3.0"
|
||||
once_cell = "1.17.1"
|
||||
regex = "1.7.3"
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
use std::collecions::HashMap;
|
||||
use std::collections::HashMap;
|
||||
|
||||
/// ~REQUIRE-DELETED
|
||||
fn user(map: HashMap<(), ()>) {
|
||||
/// ~REQUIRE-DELETED user-fn
|
||||
fn user(mut map: HashMap<(), ()>) {
|
||||
map.insert((), ());
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,4 +1,6 @@
|
|||
use anyhow::{ensure, Context, Result};
|
||||
use once_cell::sync::Lazy;
|
||||
use regex::Regex;
|
||||
use std::process::Command;
|
||||
use std::{
|
||||
fs,
|
||||
|
|
@ -7,6 +9,7 @@ use std::{
|
|||
};
|
||||
|
||||
#[test]
|
||||
#[ignore = "unfinished"]
|
||||
fn full_tests() -> Result<()> {
|
||||
let path = Path::new(file!())
|
||||
.canonicalize()?
|
||||
|
|
@ -40,6 +43,9 @@ fn build(path: &Path) -> Result<()> {
|
|||
|
||||
let proj_dir = tempdir.path().join(proj_dir).canonicalize()?;
|
||||
|
||||
let start_roots = get_roots(&proj_dir).context("getting initial roots")?;
|
||||
eprintln!("Roots: {:?}", start_roots);
|
||||
|
||||
let mut cmd = Command::new(cargo_minimize);
|
||||
cmd.current_dir(&proj_dir);
|
||||
|
||||
|
|
@ -48,7 +54,46 @@ fn build(path: &Path) -> Result<()> {
|
|||
let out = cmd.output().context("spawning cargo-minimize")?;
|
||||
let stderr = String::from_utf8(out.stderr).unwrap();
|
||||
|
||||
// ensure!(out.status.success(), "Command failed:\n{stderr}",);
|
||||
ensure!(out.status.success(), "Command failed:\n{stderr}");
|
||||
|
||||
let required_deleted = get_required_deleted(&proj_dir)?;
|
||||
|
||||
ensure!(
|
||||
required_deleted.len() > 0,
|
||||
"Some REQUIRE-DELETED have not been deleted: {required_deleted:?}"
|
||||
);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn get_roots(path: &Path) -> Result<Vec<String>> {
|
||||
static REGEX: Lazy<Regex> = Lazy::new(|| Regex::new(r"~MINIMIZE-ROOT ([\w\-_]+)").unwrap());
|
||||
|
||||
grep(path, ®EX)
|
||||
}
|
||||
|
||||
fn get_required_deleted(path: &Path) -> Result<Vec<String>> {
|
||||
static REGEX: Lazy<Regex> = Lazy::new(|| Regex::new(r"~REQUIRE-DELETED ([\w\-_]+)").unwrap());
|
||||
|
||||
grep(path, ®EX)
|
||||
}
|
||||
|
||||
fn grep(path: &Path, regex: &Regex) -> Result<Vec<String>> {
|
||||
let mut results = Vec::new();
|
||||
let walk = walkdir::WalkDir::new(path);
|
||||
|
||||
for entry in walk {
|
||||
let entry = entry?;
|
||||
if !entry.metadata()?.is_file() {
|
||||
continue;
|
||||
}
|
||||
let src = fs::read_to_string(entry.path())?;
|
||||
let captures = regex.captures_iter(&src);
|
||||
for cap in captures {
|
||||
let root_name = cap.get(1).unwrap();
|
||||
results.push(root_name.as_str().to_owned());
|
||||
}
|
||||
}
|
||||
|
||||
Ok(results)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue