//! Every corpus states where its content comes from (CONTRIBUTING, *Corpus content*). //! //! Each `wai/*-conformance/` directory has a `README.md` with a line that begins //! `**Provenance.**`, and `tests/vectors/README.md` has a row for every directory under //! `tests/vectors/` whose provenance cell is not empty. A provenance line names the //! generator that writes the content and the generator's input; an input not generated //! in this repository is named with its source and its licence. The test holds the //! line's presence, not its truth: that is a reviewer's, and for audio also //! `tools/wai_audio_provenance_check.py`'s. use std::path::PathBuf; fn wai() -> PathBuf { PathBuf::from(env!("CARGO_MANIFEST_DIR")).join("..") } /// The line a README states its provenance in, if it has one with text after the label. fn provenance_line(readme: &str) -> Option<&str> { readme .lines() .map(str::trim_start) .find(|l| l.starts_with("**Provenance.**") && l.len() > "**Provenance.**".len() + 1) } #[test] fn every_conformance_corpus_states_its_provenance() { // OER/2 is settled: no change edits its documents or its corpus. let settled = ["oer-conformance"]; let mut dirs: Vec = std::fs::read_dir(wai()) .unwrap() .flatten() .filter(|e| e.path().is_dir()) .map(|e| e.file_name().to_string_lossy().into_owned()) .filter(|n| n.ends_with("-conformance")) .collect(); dirs.sort(); assert!(dirs.len() > 10, "found {} corpora", dirs.len()); let mut missing = Vec::new(); for d in &dirs { if settled.contains(&d.as_str()) { continue; } match std::fs::read_to_string(wai().join(d).join("README.md")) { Ok(text) if provenance_line(&text).is_some() => {} Ok(_) => missing.push(format!("{d}/README.md has no `**Provenance.**` line")), Err(_) => missing.push(format!("{d} has no README.md")), } } assert!(missing.is_empty(), "corpora without a provenance line:\n {}", missing.join("\n ")); } #[test] fn every_vector_directory_states_its_provenance() { let root = wai().join("wai-rs/tests/vectors"); let index = std::fs::read_to_string(root.join("README.md")).expect("tests/vectors/README.md"); let mut dirs: Vec = std::fs::read_dir(&root) .unwrap() .flatten() .filter(|e| e.path().is_dir()) .map(|e| e.file_name().to_string_lossy().into_owned()) .collect(); dirs.sort(); let mut missing = Vec::new(); for d in &dirs { // A row: | `/` | | … let row = index.lines().find(|l| l.trim_start().starts_with(&format!("| `{d}/` |"))); let cell = row.and_then(|r| r.split('|').nth(2)).map(str::trim).unwrap_or(""); if cell.is_empty() { missing.push(d.clone()); } } assert!(missing.is_empty(), "tests/vectors/README.md states no provenance for: {missing:?}"); }