Advance native LaTeX execution and preview
This commit is contained in:
1 parent
91f9d76b16
commit
2741546ca8
414 files changed
+99872
-933
No files matched your search
@@ -0,0 +1,183 @@
|
||||
//! Actual online native jobs: output/shipout, auxiliary files and strict errors.
|
||||
#[path = "support/native_fonts.rs"]
|
||||
mod native_fonts;
|
||||
use std::{
|
||||
fs,
|
||||
path::PathBuf,
|
||||
process::Command,
|
||||
sync::atomic::{AtomicU64, Ordering},
|
||||
};
|
||||
fn directory() -> PathBuf {
|
||||
static N: AtomicU64 = AtomicU64::new(0);
|
||||
let p = std::env::temp_dir().join(format!(
|
||||
"texrra-native-pages-{}-{}",
|
||||
std::process::id(),
|
||||
N.fetch_add(1, Ordering::Relaxed)
|
||||
));
|
||||
fs::create_dir_all(&p).unwrap();
|
||||
p
|
||||
}
|
||||
#[test]
|
||||
fn native_job_exports_only_actual_shipouts_with_real_fonts_and_auxiliary_bytes() {
|
||||
let p = directory();
|
||||
let root = PathBuf::from(env!("CARGO_MANIFEST_DIR"));
|
||||
let source = root.join("examples/native-bootstrap/native-job.tex");
|
||||
let before = fs::read(&source).unwrap();
|
||||
let r = native_fonts::command()
|
||||
.args([
|
||||
"native",
|
||||
"--job",
|
||||
"--initex",
|
||||
"--etex",
|
||||
"--resource-manifest",
|
||||
"resources.json",
|
||||
])
|
||||
.arg(&source)
|
||||
.arg("native.pdf")
|
||||
.current_dir(&p)
|
||||
.output()
|
||||
.unwrap();
|
||||
assert!(
|
||||
r.status.success(),
|
||||
"{p:?}: {}",
|
||||
String::from_utf8_lossy(&r.stderr)
|
||||
);
|
||||
let r = Command::new("pdfinfo")
|
||||
.arg("native.pdf")
|
||||
.current_dir(&p)
|
||||
.output()
|
||||
.unwrap();
|
||||
assert!(r.status.success());
|
||||
assert!(
|
||||
String::from_utf8_lossy(&r.stdout)
|
||||
.lines()
|
||||
.any(|s| s.starts_with("Pages:") && s.ends_with('4'))
|
||||
);
|
||||
assert_eq!(
|
||||
fs::read(p.join("pages.aux")).unwrap(),
|
||||
b"FIRST-PAGE=1\nLAST-PAGE=4\n"
|
||||
);
|
||||
let r = Command::new("pdftotext")
|
||||
.args(["-layout", "native.pdf", "-"])
|
||||
.current_dir(&p)
|
||||
.output()
|
||||
.unwrap();
|
||||
assert!(r.status.success());
|
||||
let text = String::from_utf8(r.stdout).unwrap();
|
||||
for page in 1..=4 {
|
||||
assert!(
|
||||
text.contains(&format!("Native page {page}"))
|
||||
&& text.contains(&format!("Footer {page}")),
|
||||
"{text}"
|
||||
);
|
||||
}
|
||||
let r = Command::new("pdffonts")
|
||||
.arg("native.pdf")
|
||||
.current_dir(&p)
|
||||
.output()
|
||||
.unwrap();
|
||||
assert!(r.status.success());
|
||||
for font in ["CMR10", "CMMI10", "CMMI7"] {
|
||||
assert!(String::from_utf8_lossy(&r.stdout).contains(font));
|
||||
}
|
||||
let trace: serde_json::Value =
|
||||
serde_json::from_slice(&fs::read(p.join("resources.json")).unwrap()).unwrap();
|
||||
for suffix in [
|
||||
"native-job.tex",
|
||||
"math-fonts.tex",
|
||||
"cmr10.tfm",
|
||||
"cmmi7.tfm",
|
||||
"cmr10.pfb",
|
||||
"cmmi7.pfb",
|
||||
] {
|
||||
assert!(
|
||||
trace["reads"]
|
||||
.as_array()
|
||||
.unwrap()
|
||||
.iter()
|
||||
.any(|r| r["path"].as_str().unwrap().ends_with(suffix)),
|
||||
"missing actual read {suffix}"
|
||||
);
|
||||
}
|
||||
assert_eq!(fs::read(source).unwrap(), before);
|
||||
fs::remove_dir_all(p).unwrap();
|
||||
}
|
||||
#[test]
|
||||
fn native_job_errors_keep_existing_pdf_and_source_intact() {
|
||||
let p = directory();
|
||||
for (body, expected) in [
|
||||
(
|
||||
r"\setbox255=\hbox{}\hbox{}\penalty-10000\end",
|
||||
"box255 is not void",
|
||||
),
|
||||
(
|
||||
r"\output{\relax}\hbox{}\penalty-10000\end",
|
||||
"did not empty box255",
|
||||
),
|
||||
(
|
||||
r"\maxdeadcycles=2\output{\unvbox255}\hbox{}\penalty-10000\end",
|
||||
"dead cycles",
|
||||
),
|
||||
(
|
||||
r"\output{\bad}\hbox{}\penalty-10000\end",
|
||||
"undefined native control sequence",
|
||||
),
|
||||
(r"\hbox{}", "end"),
|
||||
(
|
||||
r"\documentclass{article}\end",
|
||||
"undefined native control sequence",
|
||||
),
|
||||
] {
|
||||
let source = format!("\\catcode123=1\\catcode125=2\n{body}\n");
|
||||
fs::write(p.join("probe.tex"), &source).unwrap();
|
||||
fs::write(p.join("native.pdf"), b"KEEP").unwrap();
|
||||
let r = native_fonts::command()
|
||||
.args([
|
||||
"native",
|
||||
"--job",
|
||||
"--initex",
|
||||
"--etex",
|
||||
"probe.tex",
|
||||
"native.pdf",
|
||||
])
|
||||
.current_dir(&p)
|
||||
.output()
|
||||
.unwrap();
|
||||
assert_eq!(r.status.code(), Some(1), "{body}");
|
||||
assert!(
|
||||
String::from_utf8_lossy(&r.stderr).contains(expected),
|
||||
"{body}: {}",
|
||||
String::from_utf8_lossy(&r.stderr)
|
||||
);
|
||||
assert_eq!(fs::read(p.join("native.pdf")).unwrap(), b"KEEP");
|
||||
assert_eq!(fs::read_to_string(p.join("probe.tex")).unwrap(), source);
|
||||
}
|
||||
fs::remove_dir_all(p).unwrap();
|
||||
}
|
||||
#[test]
|
||||
fn initex_page_parameters_are_not_seeded_from_the_pdf_driver() {
|
||||
let p = directory();
|
||||
let source = r"\catcode123=1\catcode125=2\message{INITEX-VSIZE=\number\vsize;TOP=\number\topskip;DEPTH=\number\maxdepth}\shipout\hbox{}\end";
|
||||
fs::write(p.join("probe.tex"), source).unwrap();
|
||||
let r = native_fonts::command()
|
||||
.args([
|
||||
"native",
|
||||
"--job",
|
||||
"--initex",
|
||||
"--etex",
|
||||
"probe.tex",
|
||||
"native.pdf",
|
||||
])
|
||||
.current_dir(&p)
|
||||
.output()
|
||||
.unwrap();
|
||||
assert!(r.status.success(), "{}", String::from_utf8_lossy(&r.stderr));
|
||||
let log = fs::read_to_string(p.join("native.log")).unwrap();
|
||||
assert!(log.contains("INITEX-VSIZE=0;TOP=0;DEPTH=0"), "{log}");
|
||||
assert!(
|
||||
fs::read(p.join("native.pdf"))
|
||||
.unwrap()
|
||||
.starts_with(b"%PDF-")
|
||||
);
|
||||
fs::remove_dir_all(p).unwrap();
|
||||
}
|
||||
Reference in new issue
Block a user