Skip to content

Commit e45284f

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 2a3ed8d commit e45284f

File tree

2 files changed

+38
-26
lines changed

2 files changed

+38
-26
lines changed

tests/executable.rs

+30-26
Original file line numberDiff line numberDiff line change
@@ -303,11 +303,17 @@ fn bad_outfmt_1() {
303303
}
304304

305305
fn run_with_biber(args: &str, stdin: &str) -> Output {
306+
run_with_biber_exe(None, args, stdin, &["subdirectory/empty.bib"])
307+
}
308+
309+
fn run_with_biber_exe(executable: Option<&str>, args: &str, stdin: &str, files: &[&str]) -> Output {
306310
let fmt_arg = get_plain_format_arg();
307-
let tempdir = setup_and_copy_files(&["subdirectory/empty.bib"]);
311+
let tempdir = setup_and_copy_files(files);
308312
let mut command = prep_tectonic(tempdir.path(), &[&fmt_arg, "-"]);
309313

310-
let test_cmd = if cfg!(windows) {
314+
let test_cmd = if let Some(exe) = executable {
315+
format!("{} {}", exe, args)
316+
} else if cfg!(windows) {
311317
format!(
312318
"cmd /c {} {}",
313319
util::test_path(&["fake-biber.bat"]).display(),
@@ -393,28 +399,9 @@ fn biber_failure() {
393399

394400
#[test]
395401
fn biber_no_such_tool() {
396-
let fmt_arg = get_plain_format_arg();
397-
let tempdir = setup_and_copy_files(&[]);
398-
let mut command = prep_tectonic(tempdir.path(), &[&fmt_arg, "-"]);
399-
400-
command.env("TECTONIC_TEST_FAKE_BIBER", "ohnothereisnobiberprogram");
401-
402402
const REST: &str = r"\bye";
403403
let tex = format!("{BIBER_TRIGGER_TEX}{REST}");
404-
405-
command
406-
.stdin(Stdio::piped())
407-
.stdout(Stdio::piped())
408-
.stderr(Stdio::piped());
409-
println!("running {command:?}");
410-
let mut child = command.spawn().expect("tectonic failed to start");
411-
412-
write!(child.stdin.as_mut().unwrap(), "{tex}")
413-
.expect("failed to send data to tectonic subprocess");
414-
415-
let output = child
416-
.wait_with_output()
417-
.expect("failed to wait on tectonic subprocess");
404+
let output = run_with_biber_exe(Some("ohnothereisnobiberprogram"), "", &tex, &[]);
418405
error_or_panic(&output);
419406
}
420407

@@ -425,9 +412,7 @@ fn biber_signal() {
425412
error_or_panic(&output);
426413
}
427414

428-
#[test]
429-
fn biber_success() {
430-
const REST: &str = r"
415+
const BIBER_VALIDATE_TEX: &str = r"
431416
\ifsecond
432417
\ifnum\input{biberout.qqq}=456\relax
433418
a
@@ -436,11 +421,30 @@ a
436421
\fi
437422
\fi
438423
\bye";
439-
let tex = format!("{BIBER_TRIGGER_TEX}{REST}");
424+
425+
#[test]
426+
fn biber_success() {
427+
let tex = format!("{BIBER_TRIGGER_TEX}{BIBER_VALIDATE_TEX}");
440428
let output = run_with_biber("success", &tex);
441429
success_or_panic(&output);
442430
}
443431

432+
/// Test `tectonic-biber` override: when no args passed, fall back to $PATH
433+
/// lookup for `tectonic-biber` first, and then `biber`. Currently defined in:
434+
/// [`tectonic::driver::ProcessingSession::check_biber_requirement`]
435+
#[cfg(unix)]
436+
#[test]
437+
fn biber_tectonic_override() {
438+
let tex = format!("{BIBER_TRIGGER_TEX}{BIBER_VALIDATE_TEX}");
439+
let output = run_with_biber_exe(
440+
Some(""),
441+
"", // no args passed
442+
&tex,
443+
&["subdirectory/empty.bib", "tectonic-biber"],
444+
);
445+
success_or_panic(&output);
446+
}
447+
444448
/// #844: biber input with absolute path blows away the file
445449
///
446450
/// We need to create a separate temporary directory to see if the abspath input

tests/executable/tectonic-biber

+8
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)