CLI text tests: each protected-PDF test writes its own files (#267)

text_of_a_protected_document_without_the_password_fails failed on main: both protected
tests wrote to-protect.pdf / protected.pdf / protect.json at the same paths, and tests run
in parallel. Each now uses its own names.

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Brandon Thomas 2026-10-08 08:33:26 -04:00 committed by GitHub
parent d2a59121fd
commit 4dd738b60f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 8 additions and 7 deletions

View File

@ -59,12 +59,13 @@ fn text_of_a_readable_document_succeeds() {
assert!(stdout.contains("Page 1") && stdout.contains("Page 3"), "{stdout}");
}
/// `three.pdf` encrypted with the open password `openme`, via `run --script`.
fn protected_fixture() -> std::path::PathBuf {
let src = tmp("to-protect.pdf");
/// `three.pdf` encrypted with the open password `openme`, via `run --script`. `tag` keeps each
/// test's files apart: tests run in parallel and would otherwise overwrite each other's.
fn protected_fixture(tag: &str) -> std::path::PathBuf {
let src = tmp(&format!("to-protect-{tag}.pdf"));
std::fs::write(&src, fixture(3)).unwrap();
let out_path = tmp("protected.pdf");
let script = tmp("protect.json");
let out_path = tmp(&format!("protected-{tag}.pdf"));
let script = tmp(&format!("protect-{tag}.json"));
let steps = serde_json::json!([
{ "tool": "doc_open", "args": { "path": src } },
{ "tool": "doc_protect", "args": { "doc": 1, "open_password": "openme" } },
@ -78,7 +79,7 @@ fn protected_fixture() -> std::path::PathBuf {
#[test]
fn text_of_a_protected_document_without_the_password_fails() {
let path = protected_fixture();
let path = protected_fixture("no-password");
let out = Command::new(BIN).args(["text", path.to_str().unwrap()]).output().unwrap();
assert!(!out.status.success(), "a document that cannot be opened must not exit 0");
let stderr = String::from_utf8_lossy(&out.stderr);
@ -88,7 +89,7 @@ fn text_of_a_protected_document_without_the_password_fails() {
#[test]
fn text_of_a_protected_document_with_the_password_succeeds() {
let path = protected_fixture();
let path = protected_fixture("password");
let out = Command::new(BIN).args(["text", path.to_str().unwrap(), "--password", "openme"]).output().unwrap();
assert!(out.status.success(), "{}", String::from_utf8_lossy(&out.stderr));
let stdout = String::from_utf8_lossy(&out.stdout);