use std::path::PathBuf;
use std::process::Command;
fn repo_root() -> PathBuf {
PathBuf::from(env!("CARGO_MANIFEST_DIR"))
.join("../..")
.canonicalize()
.expect("repo root")
}
fn tool_present(name: &str) -> bool {
Command::new(name)
.arg("--version")
.output()
.map(|o| o.status.success() || !o.stdout.is_empty() || !o.stderr.is_empty())
.unwrap_or(false)
}
#[test]
#[ignore = "needs poppler + python3; run with --ignored"]
fn layout_matches_upstream_satysfi_within_baseline() {
let root = repo_root();
let script = root.join("layout-tests/fidelity.py");
assert!(script.exists(), "missing {}", script.display());
if !tool_present("python3") {
eprintln!("SKIP layout_fidelity: python3 not available");
return;
}
if !tool_present("pdftotext") {
eprintln!("SKIP layout_fidelity: poppler pdftotext not available");
return;
}
if !root
.join("layout-tests/corpus/latexcmds/doc/latexcmds-doc.pdf")
.exists()
{
eprintln!("SKIP layout_fidelity: vendored corpus missing");
return;
}
let bin = env!("CARGO_BIN_EXE_rustyfi");
let mut cmd = Command::new("python3");
cmd.arg(&script).arg("--bin").arg(bin).arg("--keep-going");
if std::env::var_os("RUSTYFI_GEN_REFS").is_some() {
assert!(
tool_present("satysfi"),
"RUSTYFI_GEN_REFS is set but the original `satysfi` is not on PATH \
(try `nix develop`); refusing to silently fall back to the vendored \
references, since the point of the flag is to replace them"
);
cmd.arg("--gen-refs");
}
let output = cmd
.current_dir(&root)
.output()
.expect("failed to spawn python3");
let stdout = String::from_utf8_lossy(&output.stdout);
let stderr = String::from_utf8_lossy(&output.stderr);
print!("{stdout}");
if !stderr.is_empty() {
eprint!("{stderr}");
}
assert!(
output.status.success(),
"layout fidelity regressed vs upstream SATySFi (or a corpus doc failed to \
build). Full report above; re-baseline intentional changes with \
`layout-tests/fidelity.py --update`.\n--- stdout ---\n{stdout}\n--- stderr ---\n{stderr}"
);
}