Expand native PDF checksums over resolved input bytes

This commit is contained in:
gloamxun committed 2026-11-21 04:41:46 +08:00
1 parent 6d2a4921cf
commit e113033b8a
10 files changed
+141 -7

No files matched your search

+50
View File
@@ -189,3 +189,53 @@ fn format_load_checks_positive_and_missing_file_date_dependencies() {
);
fs::remove_dir_all(work).unwrap();
}
#[test]
fn pdf_file_digest_uses_binary_input_and_reports_a_missing_file_as_empty() {
let root = scratch("digest");
let asset = root.join("asset with spaces.dat");
fs::write(&asset, [0, 255, 17]).unwrap();
fs::write(
root.join("probe.tex"),
r#"\catcode123=1 \catcode125=2
\def\name{"asset with spaces.dat"}
\def\text{abc}
\immediate\openout5=digest.dat
\immediate\write5{[\pdfmdfivesum{\text}][\pdfmdfivesum file{\name}][\pdfmdfivesum file{absent.dat}]}
\immediate\write5{[\pdffilesize{asset with spaces.dat}]}
\immediate\closeout5
\end"#,
)
.unwrap();
let output = Command::new(env!("CARGO_BIN_EXE_texrra"))
.args([
"native",
"--initex",
"--etex",
"--resource-manifest",
"resources.json",
"probe.tex",
"probe.pdf",
])
.current_dir(&root)
.output()
.unwrap();
assert!(
output.status.success(),
"{}",
String::from_utf8_lossy(&output.stderr)
);
assert_eq!(
fs::read(root.join("digest.dat")).unwrap(),
b"[900150983CD24FB0D6963F7D28E17F72][5D3EE27BCBE27B1ED2D5191FA8CFE156][]\n[3]\n"
);
let trace: ResourceTrace =
serde_json::from_slice(&fs::read(root.join("resources.json")).unwrap()).unwrap();
assert!(
trace
.reads
.iter()
.any(|item| item.path == asset && item.bytes == 3)
);
fs::remove_dir_all(root).unwrap();
}