docs(fermata): the failure list moves out of the READMEs into docs/known-failures.md
One list, merged from both READMEs and security-model.md "Known limits", each entry with its test. Entries fixed on this branch are gone. Both READMEs keep the warning and point at the page. tests/docs_known_failures.rs keeps the page and known_limits.rs in step, and test_crate_export.py checks that the public README's links resolve in the exported tree.
This commit is contained in:
@@ -0,0 +1,51 @@
|
||||
//! `docs/known-failures.md` and `tests/known_limits.rs` stay in step, and the list stays out
|
||||
//! of the README, as a person reading it asked.
|
||||
|
||||
use std::collections::BTreeSet;
|
||||
use std::fs;
|
||||
use std::path::Path;
|
||||
|
||||
fn file(name: &str) -> String {
|
||||
fs::read_to_string(Path::new(env!("CARGO_MANIFEST_DIR")).join(name)).unwrap()
|
||||
}
|
||||
|
||||
/// The names of the `#[test]` functions in a test file's text.
|
||||
fn tests_in(text: &str) -> BTreeSet<String> {
|
||||
let lines: Vec<&str> = text.lines().collect();
|
||||
let after_attribute = lines.windows(2).filter(|pair| pair[0].trim() == "#[test]");
|
||||
after_attribute.filter_map(|pair| pair[1].trim().strip_prefix("fn ")?.split('(').next().map(str::to_string)).collect()
|
||||
}
|
||||
|
||||
/// `a_snake_case_name` words in backticks.
|
||||
fn named_tests(page: &str) -> BTreeSet<String> {
|
||||
let is_name = |word: &&str| word.matches('_').count() >= 3 && word.chars().all(|c| c.is_ascii_lowercase() || c.is_ascii_digit() || c == '_');
|
||||
page.split('`').skip(1).step_by(2).filter(is_name).map(str::to_string).collect()
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn each_limit_test_is_on_the_page_and_each_test_on_the_page_exists() {
|
||||
// Pins that an unclosed quote is handled: no failure to list.
|
||||
let not_a_failure = "a_value_after_an_unclosed_quote_is_masked_in_every_spelling_tried";
|
||||
let page = file("docs/known-failures.md");
|
||||
let on_page = named_tests(&page);
|
||||
let limits = tests_in(&file("tests/known_limits.rs"));
|
||||
for test in limits.iter().filter(|test| *test != not_a_failure) {
|
||||
assert!(on_page.contains(test), "{test} is not named in docs/known-failures.md");
|
||||
}
|
||||
for test in &on_page {
|
||||
assert!(limits.contains(test), "docs/known-failures.md names {test}, which tests/known_limits.rs does not have");
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn the_page_has_no_em_dash_and_the_readme_points_at_it() {
|
||||
assert!(!file("docs/known-failures.md").contains('\u{2014}'));
|
||||
let readme = file("README.md");
|
||||
assert!(readme.contains("**Do not use this software.**"));
|
||||
assert!(readme.contains("](docs/known-failures.md)"));
|
||||
assert!(!readme.contains("Known to fail"));
|
||||
// A failure spelled out in the README is what the page is for.
|
||||
assert!(!readme.contains("cat .env; false"));
|
||||
assert!(file("docs/security-model.md").contains("](known-failures.md)"));
|
||||
assert!(!file("docs/security-model.md").contains("#known-limits"));
|
||||
}
|
||||
Reference in New Issue
Block a user