#[path = "support/native_fonts.rs"] mod native_fonts; use std::{fs, path::PathBuf, process::Command}; fn group_records(text: &str) -> Vec { let mut unwrapped = String::new(); for line in text.lines() { unwrapped.push_str(line); if line.chars().count() != 79 { unwrapped.push('\n'); } } unwrapped .split('{') .skip(1) .filter_map(|part| { let (record, _) = part.split_once('}')?; (record.starts_with("entering ") || record.starts_with("leaving ")) .then(|| record.to_owned()) }) .collect() } #[test] fn group_boundaries_and_restored_channels_match_pdftex() { let root = PathBuf::from(env!("CARGO_MANIFEST_DIR")); let fonts = root.join("examples/native-bootstrap/math-fonts.tex"); let dir = std::env::temp_dir().join(format!("texrra-group-trace-{}", std::process::id())); fs::create_dir_all(&dir).unwrap(); let cases = [ r###"\setbox0=\hbox{A}\hbox{B}\setbox1=\vbox{\hbox{C}}\setbox2=\vtop{\hbox{D}}"###, r###"\setbox0=\hbox{A\discretionary{B}{C}{D}E}"###, r###"\hsize=80pt\vsize=500pt\noindent Before display $$x^2+y$$ after display.\par"###, r###"{\global\tracinggroups=0\relax}"###, r###"\tracinggroups=0 {\global\tracinggroups=1\relax}"###, r###"{\begingroup \count0=7{\count0=8}\endgroup}"###, r###"{\tracinggroups=0 {\count0=7}}{\count0=1}"###, r###"\tracinggroups=0 {\tracinggroups=1{\count0=7}}"###, r###"\def\opengroup{{\count0=4}} \message{BEFORE}\opengroup\message{AFTER}"###, r###"\delcode40="028300 \delcode41="029301 \setbox0=\hbox{$x_{i}^{j}+\left(a+b\right)$}"###, r###"{\tracingonline=0\relax{\count0=2}}"###, r###"\hsize=80pt\vsize=20pt\output={\shipout\box255}\hbox{A}\penalty-10000\hbox{B}"###, r###"\def\done{\message{AFTER}} \message{BEFORE}{\aftergroup\done}"###, r###"\setbox0=\hbox {A} \setbox1=\vbox to10pt {\hbox{B}}"###, r###"\setbox0=\hbox{$ x_{ i}^{j}$}"###, r###"\def\f{{\count0=3}}\toks0={{\count0=4}} \f\the\toks0"###, ]; for online in [0, 1] { for body in cases { let source = format!( "\\input {}\n\\tracingonline={online}\\tracinggroups=1\n{body}\n\\end\n", fonts.display(), ); fs::write(dir.join("probe.tex"), &source).unwrap(); let oracle = Command::new("pdftex") .args([ "-ini", "-etex", "-interaction=nonstopmode", "-halt-on-error", "probe.tex", ]) .current_dir(&dir) .output() .unwrap(); assert!( oracle.status.success(), "{}", String::from_utf8_lossy(&oracle.stdout) ); let native = native_fonts::command() .args([ "native", "--job", "--initex", "--etex", "probe.tex", "native.pdf", ]) .current_dir(&dir) .output() .unwrap(); assert!( native.status.success(), "{}", String::from_utf8_lossy(&native.stderr) ); assert_eq!( group_records(&fs::read_to_string(dir.join("native.log")).unwrap()), group_records(&fs::read_to_string(dir.join("probe.log")).unwrap()), "log: {body}, online={online}", ); assert_eq!( group_records(&String::from_utf8_lossy(&native.stderr)), group_records(&String::from_utf8_lossy(&oracle.stdout)), "terminal: {body}, online={online}", ); } } fs::remove_dir_all(dir).unwrap(); }