Skip to content

Commit 5b092c7

Browse files
committed
Add test for tectonic-biber with cleanups
In particular, refactor the biber tests in tests/executable to reduce duplicated code.
1 parent 7960b43 commit 5b092c7

File tree

2 files changed

+38
-26
lines changed

2 files changed

+38
-26
lines changed

tests/executable.rs

Lines changed: 30 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -268,11 +268,17 @@ fn bad_outfmt_1() {
268268
}
269269

270270
fn run_with_biber(args: &str, stdin: &str) -> Output {
271+
run_with_biber_exe(None, args, stdin, &["subdirectory/empty.bib"])
272+
}
273+
274+
fn run_with_biber_exe(executable: Option<&str>, args: &str, stdin: &str, files: &[&str]) -> Output {
271275
let fmt_arg = get_plain_format_arg();
272-
let tempdir = setup_and_copy_files(&["subdirectory/empty.bib"]);
276+
let tempdir = setup_and_copy_files(files);
273277
let mut command = prep_tectonic(tempdir.path(), &[&fmt_arg, "-"]);
274278

275-
let test_cmd = if cfg!(windows) {
279+
let test_cmd = if let Some(exe) = executable {
280+
format!("{} {}", exe, args)
281+
} else if cfg!(windows) {
276282
format!(
277283
"cmd /c {} {}",
278284
util::test_path(&["fake-biber.bat"]).display(),
@@ -358,28 +364,9 @@ fn biber_failure() {
358364

359365
#[test]
360366
fn biber_no_such_tool() {
361-
let fmt_arg = get_plain_format_arg();
362-
let tempdir = setup_and_copy_files(&[]);
363-
let mut command = prep_tectonic(tempdir.path(), &[&fmt_arg, "-"]);
364-
365-
command.env("TECTONIC_TEST_FAKE_BIBER", "ohnothereisnobiberprogram");
366-
367367
const REST: &str = r"\bye";
368368
let tex = format!("{BIBER_TRIGGER_TEX}{REST}");
369-
370-
command
371-
.stdin(Stdio::piped())
372-
.stdout(Stdio::piped())
373-
.stderr(Stdio::piped());
374-
println!("running {command:?}");
375-
let mut child = command.spawn().expect("tectonic failed to start");
376-
377-
write!(child.stdin.as_mut().unwrap(), "{tex}")
378-
.expect("failed to send data to tectonic subprocess");
379-
380-
let output = child
381-
.wait_with_output()
382-
.expect("failed to wait on tectonic subprocess");
369+
let output = run_with_biber_exe(Some("ohnothereisnobiberprogram"), "", &tex, &[]);
383370
error_or_panic(&output);
384371
}
385372

@@ -390,9 +377,7 @@ fn biber_signal() {
390377
error_or_panic(&output);
391378
}
392379

393-
#[test]
394-
fn biber_success() {
395-
const REST: &str = r"
380+
const BIBER_VALIDATE_TEX: &str = r"
396381
\ifsecond
397382
\ifnum\input{biberout.qqq}=456\relax
398383
a
@@ -401,11 +386,30 @@ a
401386
\fi
402387
\fi
403388
\bye";
404-
let tex = format!("{BIBER_TRIGGER_TEX}{REST}");
389+
390+
#[test]
391+
fn biber_success() {
392+
let tex = format!("{BIBER_TRIGGER_TEX}{BIBER_VALIDATE_TEX}");
405393
let output = run_with_biber("success", &tex);
406394
success_or_panic(&output);
407395
}
408396

397+
/// Test `tectonic-biber` override: when no args passed, fall back to $PATH
398+
/// lookup for `tectonic-biber` first, and then `biber`. Currently defined in:
399+
/// [`tectonic::driver::ProcessingSession::check_biber_requirement`]
400+
#[cfg(unix)]
401+
#[test]
402+
fn biber_tectonic_override() {
403+
let tex = format!("{BIBER_TRIGGER_TEX}{BIBER_VALIDATE_TEX}");
404+
let output = run_with_biber_exe(
405+
Some(""),
406+
"", // no args passed
407+
&tex,
408+
&["subdirectory/empty.bib", "tectonic-biber"],
409+
);
410+
success_or_panic(&output);
411+
}
412+
409413
/// #844: biber input with absolute path blows away the file
410414
///
411415
/// We need to create a separate temporary directory to see if the abspath input

tests/executable/tectonic-biber

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#! /bin/sh
2+
# Copyright 2021 the Tetonic Project
3+
# Licensed under the MIT License.
4+
5+
# A stand-in for biber for our testing framework.
6+
7+
echo "tectonic-biber says success and makes a file"
8+
echo 456 >biberout.qqq

0 commit comments

Comments
 (0)