use std::path::{Path, PathBuf};
fn repo(rel: &str) -> PathBuf {
Path::new(env!("CARGO_MANIFEST_DIR"))
.join("../..")
.join(rel)
}
fn read(rel: &str) -> String {
let p = repo(rel);
std::fs::read_to_string(&p).unwrap_or_else(|e| panic!("{}: {e}", p.display()))
}
fn code_blocks(md: &str) -> Vec<String> {
let mut out = Vec::new();
let mut cur: Option<String> = None;
for line in md.lines() {
if line.trim_start().starts_with("```") {
match cur.take() {
Some(b) => out.push(b),
None => cur = Some(String::new()),
}
} else if let Some(b) = cur.as_mut() {
b.push_str(line);
b.push('\n');
}
}
out
}
fn current_layer() -> String {
read("docs/current-layer.txt").trim().to_string()
}
#[test]
fn no_readme_snippet_pins_a_varve_version() {
let mut bad = Vec::new();
for block in code_blocks(&read("README.md")) {
for line in block.lines() {
let t = line.trim();
if t.starts_with("VERSION=") && t.contains("v0.") {
bad.push(t.to_string());
}
}
}
assert!(
bad.is_empty(),
"README snippets pin a varve version, which is stale on the next \
release — resolve it instead (`gh release view … -q .tagName`):\n {}",
bad.join("\n ")
);
}
#[test]
fn the_docs_pin_the_layer_they_say_they_do() {
let current = current_layer();
let parts: Vec<&str> = current.split('.').collect();
assert!(
parts.len() == 3
&& parts
.iter()
.all(|p| !p.is_empty() && p.bytes().all(|b| b.is_ascii_digit())),
"docs/current-layer.txt does not look like a layer id: {current:?}"
);
let mut stale = Vec::new();
for (file, md) in [("README.md", read("README.md"))] {
for block in code_blocks(&md) {
for line in block.lines() {
let t = line.trim();
if let Some(rest) = t.strip_prefix("layer")
&& let Some(v) = rest.trim_start().strip_prefix('=')
&& let Some(open) = v.find('"')
&& let Some(close) = v[open + 1..].find('"')
{
let id = &v[open + 1..open + 1 + close];
if id != current {
stale.push(format!("{file}: layer = \"{id}\""));
}
}
}
}
}
assert!(
stale.is_empty(),
"these pin examples name a layer other than the current one ({current}). \
A reader who copies a stale pin gets an old toolchain that verifies \
perfectly and is not what they meant — update them, or update \
docs/current-layer.txt:\n {}",
stale.join("\n ")
);
}
#[test]
fn the_readme_does_not_repeat_claims_it_has_already_outlived() {
let readme = read("README.md");
const OUTLIVED: &[&str] = &[
"Not available until v0.26.0",
];
let repeated: Vec<&str> = OUTLIVED
.iter()
.copied()
.filter(|dead| readme.contains(dead))
.collect();
assert!(
repeated.is_empty(),
"README repeats claims that are no longer true: {repeated:?}"
);
}