oxedyne/fe2o3/fe2o3_austenite/tests/cli_engine.rs
6.7 KiB, 1 run
created by r1870400018:72541, 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 | //! FIRE-2 (2026-10-11): every `.typ` source compiles through the evaluator -- plain `austenite`, `--explain` |
| 2 | //! and `--eval` alike -- a book opts back to the curated reader with `"engine": "curated"` in its |
| 3 | //! `austenite.jdat`, and a flag the chosen engine would not read is refused by name. |
| 4 | //! |
| 5 | //! The two engines are told apart by what they leave: the evaluator writes `document.pdf` alone and reports |
| 6 | //! its bytes; the curated reader writes an SVG per page beside it and reports its ledger's anchors. |
| 7 | |
| 8 | use std::path::{ |
| 9 | Path, |
| 10 | PathBuf, |
| 11 | }; |
| 12 | use std::process::{ |
| 13 | Command, |
| 14 | Output, |
| 15 | }; |
| 16 | |
| 17 | // One unsupported construct (the gradient fill) and one lint, so `--explain` has sites to report. |
| 18 | const SRC: &str = "= Title\n\nSome text.\n\n#rect(fill: gradient.linear(red, blue))\n"; |
| 19 | |
| 20 | // A fresh case directory holding `main.typ`, and an `austenite.jdat` beside it when `jdat` is given. |
| 21 | fn case(name: &str, jdat: Option<&str>) -> PathBuf { |
| 22 | let dir = PathBuf::from(env!("CARGO_TARGET_TMPDIR")).join("cli_engine").join(name); |
| 23 | let _ = std::fs::remove_dir_all(&dir); |
| 24 | std::fs::create_dir_all(&dir).expect("the case's directory"); |
| 25 | std::fs::write(dir.join("main.typ"), SRC).expect("the case's source"); |
| 26 | if let Some(j) = jdat { |
| 27 | std::fs::write(dir.join("austenite.jdat"), j).expect("the case's settings"); |
| 28 | } |
| 29 | dir |
| 30 | } |
| 31 | |
| 32 | // Runs the built binary in `dir` with `args`, then `main.typ out`. |
| 33 | fn run(dir: &Path, args: &[&str]) -> Output { |
| 34 | Command::new(env!("CARGO_BIN_EXE_austenite")) |
| 35 | .current_dir(dir) |
| 36 | .args(args) |
| 37 | .args(["main.typ", "out"]) |
| 38 | .output() |
| 39 | .expect("the built austenite binary") |
| 40 | } |
| 41 | |
| 42 | fn text(out: &Output) -> (String, String) { |
| 43 | (String::from_utf8_lossy(&out.stdout).to_string(), String::from_utf8_lossy(&out.stderr).to_string()) |
| 44 | } |
| 45 | |
| 46 | // Did the evaluator compile it: a PDF, its byte count reported, and no per-page SVG? |
| 47 | fn by_evaluator(dir: &Path, out: &Output) -> bool { |
| 48 | let (o, _) = text(out); |
| 49 | out.status.success() && dir.join("out/document.pdf").is_file() |
| 50 | && o.contains("byte(s)") && !dir.join("out/page-001.svg").exists() |
| 51 | } |
| 52 | |
| 53 | // Did the curated reader compile it: a PDF, an SVG per page, and the ledger's anchors reported? |
| 54 | fn by_curated(dir: &Path, out: &Output) -> bool { |
| 55 | let (o, _) = text(out); |
| 56 | out.status.success() && dir.join("out/document.pdf").is_file() |
| 57 | && o.contains("anchor(s) in the ledger") && dir.join("out/page-001.svg").is_file() |
| 58 | } |
| 59 | |
| 60 | #[test] |
| 61 | fn plain_austenite_compiles_through_the_evaluator() { |
| 62 | let dir = case("plain", None); |
| 63 | let out = run(&dir, &[]); |
| 64 | assert!(by_evaluator(&dir, &out), "{:?}", text(&out)); |
| 65 | } |
| 66 | |
| 67 | #[test] |
| 68 | fn eval_is_accepted_and_changes_nothing() { |
| 69 | let dir = case("eval_alias", None); |
| 70 | let out = run(&dir, &["--eval"]); |
| 71 | assert!(by_evaluator(&dir, &out), "{:?}", text(&out)); |
| 72 | } |
| 73 | |
| 74 | #[test] |
| 75 | fn explain_reports_the_evaluators_sites_with_line_and_column() { |
| 76 | let dir = case("explain", None); |
| 77 | let out = run(&dir, &["--explain"]); |
| 78 | assert!(by_evaluator(&dir, &out), "{:?}", text(&out)); |
| 79 | let (o, e) = text(&out); |
| 80 | let head = o.lines().find(|l| l.contains("main.typ:5:2: warning: unsupported: gradients")); |
| 81 | assert!(head.is_some(), "the gradient fill is reported at line 5:\n{}\n{}", o, e); |
| 82 | assert!(o.contains("#rect(fill: gradient.linear(red, blue))\n"), "the source line is shown:\n{}", o); |
| 83 | assert!(o.lines().any(|l| l.trim_start() == "^"), "a caret marks the column:\n{}", o); |
| 84 | assert!(!e.contains("skipped:"), "the detailed report stands in for the terse line:\n{}", e); |
| 85 | } |
| 86 | |
| 87 | #[test] |
| 88 | fn a_book_opted_back_reaches_the_curated_reader() { |
| 89 | let dir = case("opted_back", Some("{\"engine\": \"curated\"}")); |
| 90 | let out = run(&dir, &[]); |
| 91 | assert!(by_curated(&dir, &out), "{:?}", text(&out)); |
| 92 | } |
| 93 | |
| 94 | #[test] |
| 95 | fn a_book_opted_back_still_reaches_the_evaluator_by_name() { |
| 96 | let dir = case("opted_back_eval", Some("{\"engine\": \"curated\"}")); |
| 97 | let out = run(&dir, &["--engine", "evaluator"]); |
| 98 | assert!(by_evaluator(&dir, &out), "{:?}", text(&out)); |
| 99 | let dir = case("opted_back_eval_flag", Some("{\"engine\": \"curated\"}")); |
| 100 | let out = run(&dir, &["--eval"]); |
| 101 | assert!(by_evaluator(&dir, &out), "{:?}", text(&out)); |
| 102 | } |
| 103 | |
| 104 | #[test] |
| 105 | fn a_jdat_that_does_not_opt_back_leaves_the_evaluator() { |
| 106 | let dir = case("jdat_evaluator", Some("{\"engine\": \"evaluator\", \"strict\": true}")); |
| 107 | let out = run(&dir, &[]); |
| 108 | assert!(by_evaluator(&dir, &out), "{:?}", text(&out)); |
| 109 | } |
| 110 | |
| 111 | #[test] |
| 112 | fn an_engine_austenite_does_not_have_is_refused_by_the_key() { |
| 113 | let dir = case("jdat_bad", Some("{\"engine\": \"typst\"}")); |
| 114 | let out = run(&dir, &[]); |
| 115 | let (_, e) = text(&out); |
| 116 | assert!(!out.status.success() && e.contains("'engine'"), "{}", e); |
| 117 | } |
| 118 | |
| 119 | #[test] |
| 120 | fn the_curated_readers_flags_are_refused_on_the_evaluator() { |
| 121 | for args in [&["--pearl"][..], &["--ledger-out", "l.json"][..]] { |
| 122 | let dir = case("refuse_eval", None); |
| 123 | let out = run(&dir, args); |
| 124 | let (_, e) = text(&out); |
| 125 | let want = fmt(args[0], "the evaluator path"); |
| 126 | assert!(!out.status.success() && e.contains(&want), "{:?}: {}", args, e); |
| 127 | assert!(!dir.join("out/document.pdf").exists(), "nothing is compiled: {:?}", args); |
| 128 | } |
| 129 | } |
| 130 | |
| 131 | #[test] |
| 132 | fn the_evaluators_flags_are_refused_on_the_curated_reader() { |
| 133 | for args in [ |
| 134 | &["--strict"][..], |
| 135 | &["--diag-summary"][..], |
| 136 | &["--timings", "t.json"][..], |
| 137 | &["--root", "."][..], |
| 138 | &["--font-path", "."][..], |
| 139 | ] { |
| 140 | let dir = case("refuse_curated", Some("{\"engine\": \"curated\"}")); |
| 141 | let out = run(&dir, args); |
| 142 | let (_, e) = text(&out); |
| 143 | let want = fmt(args[0], "the curated reader path"); |
| 144 | assert!(!out.status.success() && e.contains(&want), "{:?}: {}", args, e); |
| 145 | assert!(e.contains("austenite.jdat"), "the file that chose the engine is named: {}", e); |
| 146 | } |
| 147 | } |
| 148 | |
| 149 | #[test] |
| 150 | fn explain_with_watch_is_refused_on_both_engines() { |
| 151 | let dir = case("explain_watch", None); |
| 152 | let out = run(&dir, &["--explain", "--watch"]); |
| 153 | let (_, e) = text(&out); |
| 154 | assert!(!out.status.success() && e.contains(&fmt("--explain", "the evaluator path")), "{}", e); |
| 155 | let dir = case("explain_watch_curated", Some("{\"engine\": \"curated\"}")); |
| 156 | let out = run(&dir, &["--explain", "--watch"]); |
| 157 | let (_, e) = text(&out); |
| 158 | assert!(!out.status.success() && e.contains(&fmt("--explain", "the curated reader path")), "{}", e); |
| 159 | } |
| 160 | |
| 161 | #[test] |
| 162 | fn eval_and_engine_curated_together_are_refused() { |
| 163 | let dir = case("two_engines", None); |
| 164 | let out = run(&dir, &["--eval", "--engine", "curated"]); |
| 165 | let (_, e) = text(&out); |
| 166 | assert!(!out.status.success() && e.contains("two engines"), "{}", e); |
| 167 | } |
| 168 | |
| 169 | #[test] |
| 170 | fn build_refuses_a_book_opted_back_to_the_curated_reader() { |
| 171 | let dir = case("build_curated", Some("{\"engine\": \"curated\"}")); |
| 172 | let out = Command::new(env!("CARGO_BIN_EXE_austenite")) |
| 173 | .current_dir(&dir) |
| 174 | .args(["build", "main.typ"]) |
| 175 | .output() |
| 176 | .expect("the built austenite binary"); |
| 177 | let (_, e) = text(&out); |
| 178 | assert!(!out.status.success() && e.contains("'engine'") && e.contains("curated"), "{}", e); |
| 179 | } |
| 180 | |
| 181 | fn fmt(flag: &str, path: &str) -> String { |
| 182 | format!("{} is not read on {}", flag, path) |
| 183 | } |