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 trace_lines(text: &str) -> Vec<&str> { text.lines() .filter(|line| line.contains("->") || line.contains("<-")) .collect() } #[test] fn macro_trace_follows_real_calls_and_parameters_in_each_channel() { let dir = std::env::temp_dir().join(format!("texrra-macro-trace-{}", std::process::id())); fs::create_dir_all(&dir).unwrap(); let source = r"\catcode123=1 \catcode125=2 \catcode35=6 \def\foo P#1/#2!{\message{arg=#1,#2}} \protected\long\def\empty#1{} \def\nested#1{\foo P{#1}/beta!} \catcode33=6 \def\alt!1{\message{arg=!1}} \tracingmacros=1 \relax \nested{alpha} \tracingonline=1 \relax \empty{} \alt{gamma} \tracingmacros=0 \relax \empty{QUIET} \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(); assert!( reference.status.success(), "{}", String::from_utf8_lossy(&reference.stdout) ); let log = fs::read_to_string(dir.join("probe.log")).unwrap(); let terminal = String::from_utf8_lossy(&reference.stdout); let result = Executor::new(State::initex().with_etex(), Limits::default()) .run( SourceFile { name: "probe.tex".into(), data: source.as_bytes().into(), }, &mut Host, ) .unwrap(); let mut native_log = String::new(); let mut native_terminal = String::new(); for event in result.events { if let Event::MacroTrace { destination, text } = event { native_log.push_str(&text); if destination == WriteDestination::TerminalAndLog { native_terminal.push_str(&text); } } } assert_eq!(trace_lines(&native_log), trace_lines(&log)); assert_eq!(trace_lines(&native_terminal), trace_lines(&terminal)); assert_eq!(trace_lines(&native_log).len(), 9); fs::remove_dir_all(dir).unwrap(); }