84 lines
2.5 KiB
Rust
84 lines
2.5 KiB
Rust
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<SourceFile, String> {
|
|
Err(format!("unexpected input {name}"))
|
|
}
|
|
}
|
|
|
|
fn records(text: &str) -> Vec<&str> {
|
|
text.lines()
|
|
.filter_map(|line| {
|
|
[
|
|
"{changing ",
|
|
"{globally changing ",
|
|
"{reassigning ",
|
|
"{into ",
|
|
]
|
|
.iter()
|
|
.find_map(|prefix| line.find(prefix).map(|start| &line[start..]))
|
|
})
|
|
.collect()
|
|
}
|
|
|
|
#[test]
|
|
fn assignment_trace_observes_real_typed_mutations_and_live_switches() {
|
|
let dir = std::env::temp_dir().join(format!("texrra-assign-trace-{}", std::process::id()));
|
|
fs::create_dir_all(&dir).unwrap();
|
|
let source = r"\catcode123=1 \catcode125=2
|
|
\tracingonline=1 \tracingassigns=1
|
|
\count0=10 \count0=10
|
|
\global\advance\count0 by2
|
|
\dimen0=1pt \skip0=2pt plus1fil \toks0={A}
|
|
\def\foo{ONE}\let\bar=\foo\let\bar=\foo
|
|
\catcode64=11 \mathcode65=42
|
|
\tracingonline=0
|
|
\count1=7
|
|
\tracingassigns=0
|
|
\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.as_bytes().into(),
|
|
},
|
|
&mut Host,
|
|
)
|
|
.unwrap();
|
|
assert_eq!(result.state.count(0), 12);
|
|
let mut native_log = String::new();
|
|
let mut native_terminal = String::new();
|
|
for event in result.events {
|
|
if let Event::AssignmentTrace {
|
|
destination, text, ..
|
|
} = event
|
|
{
|
|
native_log.push_str(&text);
|
|
if destination == WriteDestination::TerminalAndLog {
|
|
native_terminal.push_str(&text);
|
|
}
|
|
}
|
|
}
|
|
assert_eq!(records(&native_log), records(&log));
|
|
assert_eq!(records(&native_terminal), records(&terminal));
|
|
fs::remove_dir_all(dir).unwrap();
|
|
}
|