Skip to content

Commit

Permalink
Add test for tectonic-biber with cleanups
Browse files Browse the repository at this point in the history
In particular, refactor the biber tests in tests/executable to reduce
duplicated code.
  • Loading branch information
bryango committed Mar 12, 2024
1 parent 4c190f1 commit 307d676
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 26 deletions.
56 changes: 30 additions & 26 deletions tests/executable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -303,11 +303,17 @@ fn bad_outfmt_1() {
}

fn run_with_biber(args: &str, stdin: &str) -> Output {
run_with_biber_exe(None, args, stdin, &["subdirectory/empty.bib"])
}

fn run_with_biber_exe(executable: Option<&str>, args: &str, stdin: &str, files: &[&str]) -> Output {
let fmt_arg = get_plain_format_arg();
let tempdir = setup_and_copy_files(&["subdirectory/empty.bib"]);
let tempdir = setup_and_copy_files(files);
let mut command = prep_tectonic(tempdir.path(), &[&fmt_arg, "-"]);

let test_cmd = if cfg!(windows) {
let test_cmd = if let Some(exe) = executable {
format!("{} {}", exe, args)
} else if cfg!(windows) {
format!(
"cmd /c {} {}",
util::test_path(&["fake-biber.bat"]).display(),
Expand Down Expand Up @@ -393,28 +399,9 @@ fn biber_failure() {

#[test]
fn biber_no_such_tool() {
let fmt_arg = get_plain_format_arg();
let tempdir = setup_and_copy_files(&[]);
let mut command = prep_tectonic(tempdir.path(), &[&fmt_arg, "-"]);

command.env("TECTONIC_TEST_FAKE_BIBER", "ohnothereisnobiberprogram");

const REST: &str = r"\bye";
let tex = format!("{BIBER_TRIGGER_TEX}{REST}");

command
.stdin(Stdio::piped())
.stdout(Stdio::piped())
.stderr(Stdio::piped());
println!("running {command:?}");
let mut child = command.spawn().expect("tectonic failed to start");

write!(child.stdin.as_mut().unwrap(), "{tex}")
.expect("failed to send data to tectonic subprocess");

let output = child
.wait_with_output()
.expect("failed to wait on tectonic subprocess");
let output = run_with_biber_exe(Some("ohnothereisnobiberprogram"), "", &tex, &[]);
error_or_panic(&output);
}

Expand All @@ -425,9 +412,7 @@ fn biber_signal() {
error_or_panic(&output);
}

#[test]
fn biber_success() {
const REST: &str = r"
const BIBER_VALIDATE_TEX: &str = r"
\ifsecond
\ifnum\input{biberout.qqq}=456\relax
a
Expand All @@ -436,11 +421,30 @@ a
\fi
\fi
\bye";
let tex = format!("{BIBER_TRIGGER_TEX}{REST}");

#[test]
fn biber_success() {
let tex = format!("{BIBER_TRIGGER_TEX}{BIBER_VALIDATE_TEX}");
let output = run_with_biber("success", &tex);
success_or_panic(&output);
}

/// Test `tectonic-biber` override: when no args passed, fall back to $PATH
/// lookup for `tectonic-biber` first, and then `biber`. Currently defined in:
/// [`tectonic::driver::ProcessingSession::check_biber_requirement`]
#[cfg(unix)]
#[test]
fn biber_tectonic_override() {
let tex = format!("{BIBER_TRIGGER_TEX}{BIBER_VALIDATE_TEX}");
let output = run_with_biber_exe(
Some(""),
"", // no args passed
&tex,
&["subdirectory/empty.bib", "tectonic-biber"],
);
success_or_panic(&output);
}

/// #844: biber input with absolute path blows away the file
///
/// We need to create a separate temporary directory to see if the abspath input
Expand Down
8 changes: 8 additions & 0 deletions tests/executable/tectonic-biber
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#! /bin/sh
# Copyright 2021 the Tetonic Project
# Licensed under the MIT License.

# A stand-in for biber for our testing framework.

echo "tectonic-biber says success and makes a file"
echo 456 >biberout.qqq

0 comments on commit 307d676

Please sign in to comment.