use std::{fs, process::Command}; use texrra_tex_core::execution::*; struct Host; impl SourceProvider for Host { fn read(&mut self, name: &str, _from: &str) -> Result { Err(format!("unexpected input {name}")) } } fn records(text: &str) -> Vec<&str> { text.lines() .filter(|line| line.starts_with('{') && line.ends_with('}')) .collect() } #[test] fn command_trace_matches_pdftex_at_execution_expansion_and_prefix_boundaries() { let dir = std::env::temp_dir().join(format!("texrra-command-trace-{}", std::process::id())); fs::create_dir_all(&dir).unwrap(); for (level, ifs) in [(1, 0), (2, 0), (3, 0), (3, 1)] { let source = format!( r"\catcode123=1 \catcode125=2 \catcode35=6 \countdef\foo=3 \def\mac{{\relax}} \tracingonline=1 \tracingifs={ifs} \tracingcommands={level} \relax \global\foo=2 \ifnum\foo=2 \message{{Y}}\else\message{{N}}\fi \ifcase1 \or\expandafter\mac\fi \unless\iffalse\begingroup{{}}\endgroup\fi \noexpand\mac\noexpand\iftrue \setbox0=\hbox{{}} \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 result = Executor::new(State::initex().with_etex(), Limits::default()) .run( SourceFile { name: "probe.tex".into(), data: source.into_bytes(), }, &mut Host, ) .unwrap(); let mut native = String::new(); for event in result.events { if let Event::CommandTrace { destination, text } | Event::ConditionalTrace { destination, text, .. } = event { assert_eq!(destination, WriteDestination::TerminalAndLog); native.push_str(&text); } } assert_eq!(records(&native), records(&log), "level={level} ifs={ifs}"); assert_eq!( records(&native), records(&terminal), "level={level} ifs={ifs}" ); } fs::remove_dir_all(dir).unwrap(); }