use std::path::{Path, PathBuf};
fn repo_root() -> PathBuf {
Path::new(env!("CARGO_MANIFEST_DIR"))
.parent()
.and_then(Path::parent)
.expect("crates/frink-cli has two ancestors")
.to_path_buf()
}
fn read(rel: &str) -> String {
let p = repo_root().join(rel);
std::fs::read_to_string(&p).unwrap_or_else(|e| panic!("reading {}: {e}", p.display()))
}
fn flatten(text: &str) -> String {
text.split_whitespace().collect::<Vec<_>>().join(" ")
}
fn ledger_gaps(results: &str) -> Vec<String> {
let mut out = Vec::new();
for line in results.lines() {
if !line.starts_with('|') {
continue;
}
let mut rest = line;
while let Some(i) = rest.find("**") {
rest = &rest[i + 2..];
let Some(j) = rest.find("×**") else { break };
let cell = &rest[..j];
if cell.chars().all(|c| c.is_ascii_digit() || c == '.') && !cell.is_empty() {
out.push(cell.to_string());
}
rest = &rest[j + 3..];
}
}
out
}
#[test]
fn a_stale_ledger_is_admitted_in_the_prose() {
let results = read("benchmarks/RESULTS.md");
let features = flatten(&read("docs/FEATURES.md"));
if !results.contains("⚠️") {
return;
}
assert!(
features.contains("stale"),
"the ledger marks rows stale and docs/FEATURES.md does not say so anywhere"
);
}
#[test]
fn the_ledgers_cuda_range_is_the_one_the_prose_quotes() {
let results = read("benchmarks/RESULTS.md");
let features = read("docs/FEATURES.md");
let gaps = ledger_gaps(&results);
assert!(!gaps.is_empty(), "no gap cells parsed out of the ledger");
let row = features
.lines()
.find(|l| l.starts_with('|') && l.contains("NVIDIA RTX"))
.unwrap_or_else(|| panic!("no NVIDIA row in docs/FEATURES.md"))
.to_string();
let row = row.as_str();
for quoted in ["22x", "43x"] {
assert!(
row.contains(quoted),
"the NVIDIA row no longer quotes {quoted}; if the ledger moved, \
re-derive the sentence from it rather than dropping the range"
);
let bare = quoted.trim_end_matches('x');
assert!(
gaps.iter().any(|g| g.starts_with(bare)),
"docs/FEATURES.md quotes {quoted} for NVIDIA and no ledger gap \
starts with {bare}: {gaps:?}"
);
}
assert!(
row.contains("4.2x") && row.contains("1932") && row.contains("8,200"),
"the post-fix 4.2x figure must keep the two throughputs it was \
divided from, since no receipt backs it: {row}"
);
}
#[test]
fn every_ledger_section_names_the_build_it_was_measured_on() {
let results = read("benchmarks/RESULTS.md");
let after = results
.split("### At a glance")
.nth(1)
.unwrap_or_else(|| panic!("no summary table in benchmarks/RESULTS.md"));
let summary = after.split("\n###").next().unwrap_or(after);
assert!(
summary.contains("Measured at"),
"the summary table has no column naming the build each row came from"
);
for line in summary.lines().filter(|l| l.starts_with('|')) {
if line.contains("---") || line.contains("Measured at") {
continue;
}
if line.trim().is_empty() {
continue;
}
assert!(
line.contains('`'),
"a summary row carries no version: {line}"
);
}
}