Oregami
Repositories/oxedyne/fe2o3

oxedyne/fe2o3/fe2o3_austenite/tests/corpus_warnings.rs

2.6 KiB, 1 run

created by r1870400018:62385, which is this file's identity for as long as the history lasts, whatever it is later renamed to

download · who wrote it · its history

1//! Every warning a compile of the oracle corpus raises reaches Daimond as plain words: no terminal colour
2//! code and no source location of the engine's own, in a diagnostic's message, in the skip line or in a
3//! strict refusal's hint. The corpus is compiled through the same `compile` functions the wasm
4//! `DaimondTypst` calls, one root after another in this binary's one test, since the image base and the term
5//! dictionary those functions install are process globals.
6
7#[allow(dead_code)]
8#[path = "oracle/mod.rs"]
9mod driver;
10
11use oxedyne_fe2o3_austenite::compile::{
12 self,
13 Report,
14};
15use oxedyne_fe2o3_austenite::fonts;
16
17use oxedyne_fe2o3_core::prelude::*;
18
19use std::path::Path;
20use std::sync::Arc;
21
22/// Why `text` is not plain, or `None` when it is.
23fn not_plain(text: &str) -> Option<&'static str> {
24 if text.contains('\u{1b}') {
25 return Some("a terminal escape");
26 }
27 if text.contains(".rs:") {
28 return Some("an engine source location");
29 }
30 None
31}
32
33#[test]
34fn corpus_warnings_are_plain_text() -> Outcome<()> {
35 let fonts = Arc::new(res!(fonts::libertinus()));
36 let mut checked = 0usize;
37 let mut sites = 0usize;
38 let mut faults: Vec<String> = Vec::new();
39 for root in driver::corpus() {
40 let main = Path::new(root.path);
41 if !main.is_file() {
42 println!("[corpus-warnings] {}: not on this machine, not checked", root.name);
43 continue;
44 }
45 let assembled = res!(compile::assemble(main, || Ok(fonts.clone())));
46 let empty = assembled.blocks.is_empty();
47 let rendered = res!(compile::author_and_run(assembled));
48 let report = Report::new(rendered.out.pages.len(), &rendered.refusals, empty);
49 let mut texts: Vec<(String, String)> = Vec::new();
50 for d in &report.diagnostics {
51 texts.push(("message".to_string(), d.message.clone()));
52 }
53 if let Some(s) = &report.skipped {
54 texts.push(("skipped".to_string(), s.clone()));
55 }
56 if let Some(head) = report.strict_failure(main) {
57 texts.push(("strict message".to_string(), head.message.clone()));
58 if let Some(h) = &head.hint {
59 texts.push(("hint".to_string(), h.clone()));
60 }
61 }
62 for (field, text) in &texts {
63 if let Some(why) = not_plain(text) {
64 faults.push(fmt!("{}: a {} carries {}: {:?}", root.name, field, why, text));
65 }
66 }
67 println!("[corpus-warnings] {}: {} warning(s), plain", root.name, report.diagnostics.len());
68 sites += report.diagnostics.len();
69 checked += 1;
70 }
71 assert!(checked > 0, "no corpus root was on this machine to check");
72 if !faults.is_empty() {
73 return Err(err!("{} warning text(s) are not plain:\n{}", faults.len(), faults.join("\n"); Test, Mismatch));
74 }
75 println!("[corpus-warnings] {} root(s), {} warning(s), all plain", checked, sites);
76 Ok(())
77}