crates/monetize-server/tests/no_hidden_warnings.rs
//! **No `#[allow(…)]` hides a warning in the server, its guest host or the
//! ledger.** An allow is where dead code and a signature that grew one
//! argument too many go to stay: a compile-time assert says the same thing
//! out loud, and a struct names what travels together.
//!
//! `estate_order.rs` is the UpCloud order path's and answers on its own branch.
//! `Doors::open`, the positional opener, is called by gunnar's own guest tests
//! (`gunnar-monetize-guest`, through a path dependency), so it goes when they
//! move to `Doors::open_with`.
use std::path::{Path, PathBuf};
const CRATES: [&str; 3] = ["monetize-server", "monetize-product-wasm", "monetize"];
const NOT_OURS: [&str; 1] = ["estate_order.rs"];
/// `(file, the line after the allow)`: an allow another repo still leans on.
const CROSS_REPO: [(&str, &str); 1] = [("monetize-product-wasm/src/doors.rs", "pub fn open(")];
fn rust_files(dir: &Path, out: &mut Vec<PathBuf>) {
for e in std::fs::read_dir(dir).unwrap() {
let p = e.unwrap().path();
if p.is_dir() {
rust_files(&p, out);
} else if p.extension().is_some_and(|x| x == "rs") {
out.push(p);
}
}
}
#[test]
fn no_allow_attribute_hides_a_warning() {
let root = Path::new(env!("CARGO_MANIFEST_DIR")).parent().unwrap();
let mut found = Vec::new();
for c in CRATES {
let mut files = Vec::new();
rust_files(&root.join(c).join("src"), &mut files);
for f in files {
if NOT_OURS
.iter()
.any(|n| f.file_name().is_some_and(|x| x == *n))
{
continue;
}
let rel = f.strip_prefix(root).unwrap().display().to_string();
let text = std::fs::read_to_string(&f).unwrap();
let lines: Vec<&str> = text.lines().collect();
for (i, line) in lines.iter().enumerate() {
if !(line.contains("#[allow(") || line.contains("#![allow(")) {
continue;
}
let next = lines.get(i + 1).map_or("", |l| l.trim());
if CROSS_REPO
.iter()
.any(|(file, item)| rel == *file && next.starts_with(item))
{
continue;
}
found.push(format!("{rel}:{}: {}", i + 1, line.trim()));
}
}
}
assert!(
found.is_empty(),
"allow attributes hide warnings:\n{}",
found.join("\n")
);
}