oxedyne/fe2o3/fe2o3_austenite/tests/support/typst_command.rs
1.3 KiB, 1 run
created by r1870400018:66218, 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 | // The one way a test runs `typst`, shared by every harness that does: the structure oracle |
| 2 | // (`tests/eval_oracle/`), its PDF comparators and the corpus oracle (`tests/oracle/`). It lives in a |
| 3 | // directory of its own because a bare `tests/*.rs` file would be built as a test target, and each |
| 4 | // harness includes it by `#[path]`. |
| 5 | |
| 6 | use oxedyne_fe2o3_core::prelude::*; |
| 7 | |
| 8 | use std::path::Path; |
| 9 | use std::process::Command; |
| 10 | |
| 11 | /// The one way a test runs `typst`: under `systemd-run`'s memory cap when `cap` is given, and with the |
| 12 | /// account's own fonts hidden. Typst looks for them under `$XDG_DATA_HOME/fonts`; a face installed there (a |
| 13 | /// second Libertinus Serif of another version, say) outranks Typst's own and would move a glyph on one side |
| 14 | /// only. Typst sees the faces the system and Typst carry, whoever runs the test, which is what the oracle's cache key, `fonts=system`, says. |
| 15 | /// `work` is where the directory that does not exist is named, so that it never does. |
| 16 | pub fn typst_command(bin: &str, cap: Option<&str>, work: &Path) -> Command { |
| 17 | let mut c = match cap { |
| 18 | Some(cap) => { |
| 19 | let mut c = Command::new("systemd-run"); |
| 20 | c.args(["--user", "--scope", "--quiet", "-p"]); |
| 21 | c.arg(fmt!("MemoryMax={}", cap)); |
| 22 | c.arg("--slice=claude-rc.slice"); |
| 23 | c.arg(bin); |
| 24 | c |
| 25 | } |
| 26 | None => Command::new(bin), |
| 27 | }; |
| 28 | c.env("XDG_DATA_HOME", work.join("no-user-fonts")); |
| 29 | c |
| 30 | } |