Advance native LaTeX execution and preview
This commit is contained in:
1 parent
91f9d76b16
commit
2741546ca8
414 files changed
+99872
-933
No files matched your search
@@ -0,0 +1,59 @@
|
||||
use std::{fs, path::Path, process::Command};
|
||||
use texrra_tex_core::execution::*;
|
||||
|
||||
struct Host;
|
||||
impl SourceProvider for Host {
|
||||
fn read(&mut self, name: &str, from: &str) -> Result<SourceFile, String> {
|
||||
let path = Path::new(from).with_file_name(name);
|
||||
Ok(SourceFile {
|
||||
data: fs::read(&path).map_err(|error| error.to_string())?,
|
||||
name: path.to_string_lossy().into_owned(),
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn jobname_uses_the_entry_identity_in_child_input_and_aux_lookup() {
|
||||
let dir = std::env::temp_dir().join(format!("texrra-jobname-{}", std::process::id()));
|
||||
fs::create_dir_all(&dir).unwrap();
|
||||
let entry = dir.join("main.part.tex");
|
||||
let text = r"\catcode123=1 \catcode125=2
|
||||
\message{ROOT=[\jobname]}\input \jobname.aux \end
|
||||
";
|
||||
fs::write(&entry, text).unwrap();
|
||||
fs::write(dir.join("main.part.aux"), r"\message{CHILD=[\jobname]}").unwrap();
|
||||
let reference = Command::new("pdftex")
|
||||
.args([
|
||||
"-ini",
|
||||
"-etex",
|
||||
"-interaction=nonstopmode",
|
||||
"-halt-on-error",
|
||||
"main.part.tex",
|
||||
])
|
||||
.current_dir(&dir)
|
||||
.output()
|
||||
.unwrap();
|
||||
let terminal = String::from_utf8_lossy(&reference.stdout);
|
||||
assert!(reference.status.success(), "{terminal}");
|
||||
let execution = Executor::new(State::initex().with_etex(), Limits::default())
|
||||
.run(
|
||||
SourceFile {
|
||||
name: entry.to_string_lossy().into_owned(),
|
||||
data: text.as_bytes().into(),
|
||||
},
|
||||
&mut Host,
|
||||
)
|
||||
.unwrap();
|
||||
assert!(execution.reads.contains(&Dependency::JobName));
|
||||
for message in ["ROOT=[main.part]", "CHILD=[main.part]"] {
|
||||
assert!(terminal.contains(message), "{terminal}");
|
||||
assert!(
|
||||
execution
|
||||
.events
|
||||
.iter()
|
||||
.any(|event| matches!(event, Event::Message { text, .. } if text == message))
|
||||
);
|
||||
}
|
||||
assert_eq!(execution.job_name.as_deref(), Some("main.part"));
|
||||
fs::remove_dir_all(dir).unwrap();
|
||||
}
|
||||
Reference in new issue
Block a user