use std::{fs, process::Command}; use texrra_tex_core::execution::*; #[path = "support/font_world.rs"] mod font_world; fn records(text: &str) -> Vec<&str> { text.lines() .filter(|line| { line.starts_with("Completed box") || line.starts_with('\\') || line.starts_with('.') }) .collect() } #[test] fn shipout_traces_use_the_real_box_counters_and_channel() { let dir = std::env::temp_dir().join(format!("texrra-shipout-{}", std::process::id())); fs::create_dir_all(&dir).unwrap(); let source = r"\catcode123=1 \catcode125=2 \pdfoutput=1 \tracingoutput=1 \showboxbreadth=1 \showboxdepth=1 \count0=4 \count2=7 \shipout\hbox{\kern1pt\kern2pt} \tracingonline=1 \showboxdepth=-1 \shipout\vbox{\kern3pt} \end "; fs::write(dir.join("probe.tex"), source).unwrap(); let reference = Command::new("pdftex") .args([ "-ini", "-etex", "-interaction=nonstopmode", "-halt-on-error", "probe.tex", ]) .current_dir(&dir) .output() .unwrap(); let terminal = String::from_utf8_lossy(&reference.stdout); assert!(reference.status.success(), "{terminal}"); let log = fs::read_to_string(dir.join("probe.log")).unwrap(); let execution = Executor::new(State::initex().with_etex(), Limits::default()) .with_native_pages() .run( SourceFile { name: "probe.tex".into(), data: source.as_bytes().into(), }, &mut font_world::FontFiles, ) .unwrap(); let mut native_log = String::new(); let mut native_terminal = String::new(); let mut shipped = 0; for event in execution.events { match event { Event::ShipoutTrace { log, terminal } => { native_log.push_str(&log); native_terminal.push_str(&terminal); } Event::Shipout(_) => shipped += 1, _ => {} } } assert_eq!(shipped, 2); assert_eq!(records(&native_log), records(&log)); assert_eq!(records(&native_terminal), records(&terminal)); fs::remove_dir_all(dir).unwrap(); }