Skip to content

Commit 32c629a

Browse files
committed
Add more basic bibtex tests to help avoid regressions
1 parent 0d9169e commit 32c629a

17 files changed

Lines changed: 97 additions & 11 deletions

File tree

tests/bibtex.rs

Lines changed: 54 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
use std::collections::HashSet;
55
use std::default::Default;
6+
use std::path::PathBuf;
67

78
use tectonic::io::{FilesystemIo, IoProvider, IoStack, MemoryIo};
89
use tectonic::BibtexEngine;
@@ -16,29 +17,46 @@ use crate::util::{test_path, ExpectedInfo};
1617

1718
struct TestCase {
1819
stem: String,
20+
subdir: Option<String>,
21+
test_bbl: bool,
1922
}
2023

2124
impl TestCase {
22-
fn new(stem: &str) -> Self {
25+
fn new(
26+
stem: &str,
27+
subdir: Option<&str>,
28+
) -> Self {
2329
TestCase {
2430
stem: stem.to_owned(),
31+
subdir: subdir.map(String::from),
32+
test_bbl: true,
2533
}
2634
}
2735

28-
fn go(&mut self) {
29-
util::set_test_root();
36+
fn test_bbl(mut self, test: bool) -> Self {
37+
self.test_bbl = test;
38+
self
39+
}
3040

41+
fn test_dir(&self) -> PathBuf {
3142
let mut p = test_path(&["bibtex"]);
43+
if let Some(subdir) = &self.subdir {
44+
p.push(subdir);
45+
}
46+
p
47+
}
3248

33-
p.push(&self.stem);
49+
fn go(&mut self) {
50+
util::set_test_root();
51+
52+
let mut p = self.test_dir();
3453

35-
p.set_extension("aux");
36-
let auxname = p.file_name().unwrap().to_str().unwrap().to_owned();
54+
let auxname = format!("{}.aux", self.stem);
3755

3856
// MemoryIo layer that will accept the outputs.
3957
let mut mem = MemoryIo::new(true);
4058

41-
let mut assets = FilesystemIo::new(&test_path(&["bibtex"]), false, false, HashSet::new());
59+
let mut assets = FilesystemIo::new(&p, false, false, HashSet::new());
4260

4361
let mut genio = GenuineStdoutIo::new();
4462

@@ -55,17 +73,42 @@ impl TestCase {
5573

5674
// Check that outputs match expectations.
5775

58-
let expected_bbl = ExpectedInfo::read_with_extension(&mut p, "bbl");
59-
let expected_blg = ExpectedInfo::read_with_extension(&mut p, "blg");
76+
p.push(&self.stem);
6077

6178
let files = mem.files.borrow();
6279

63-
expected_bbl.test_from_collection(&files);
80+
if self.test_bbl {
81+
let expected_bbl = ExpectedInfo::read_with_extension(&mut p, "bbl");
82+
expected_bbl.test_from_collection(&files);
83+
}
84+
85+
let expected_blg = ExpectedInfo::read_with_extension(&mut p, "blg");
6486
expected_blg.test_from_collection(&files);
6587
}
6688
}
6789

6890
#[test]
6991
fn single_entry() {
70-
TestCase::new("single_entry").go()
92+
TestCase::new("single_entry", None).go()
93+
}
94+
95+
#[test]
96+
fn test_empty_files() {
97+
TestCase::new("empty", Some("empty"))
98+
.test_bbl(false)
99+
.go()
100+
}
101+
102+
#[test]
103+
fn test_mismatched_function() {
104+
TestCase::new("function", Some("mismatched_braces"))
105+
.test_bbl(false)
106+
.go();
107+
}
108+
109+
#[test]
110+
fn test_mismatched_expr() {
111+
TestCase::new("expr", Some("mismatched_braces"))
112+
.test_bbl(false)
113+
.go();
71114
}

tests/bibtex/empty/empty.aux

Whitespace-only changes.

tests/bibtex/empty/empty.bbl

Whitespace-only changes.

tests/bibtex/empty/empty.bib

Whitespace-only changes.

tests/bibtex/empty/empty.blg

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
This is BibTeX, Version 0.99d
2+
Capacity: max_strings=35307, hash_size=35307, hash_prime=30011
3+
The top-level auxiliary file: empty.aux
4+
I found no \citation commands---while reading file empty.aux
5+
I found no \bibdata command---while reading file empty.aux
6+
I found no \bibstyle command---while reading file empty.aux
7+
(There were 3 error messages)

tests/bibtex/empty/empty.bst

Whitespace-only changes.
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
\relax
2+
\citation{Mismatched01}
3+
\bibdata{expr}
4+
\bibcite{Mismatched01}{1}
5+
\bibstyle{expr}

tests/bibtex/mismatched_braces/expr.bbl

Whitespace-only changes.

tests/bibtex/mismatched_braces/expr.bib

Whitespace-only changes.
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
This is BibTeX, Version 0.99d
2+
Capacity: max_strings=35307, hash_size=35307, hash_prime=30011
3+
The top-level auxiliary file: expr.aux
4+
The style file: expr.bst
5+
"}" can't start a style-file command---line 5 of file expr.bst
6+
:
7+
: }
8+
(Error may have been on previous line)
9+
(There was 1 error message)

0 commit comments

Comments
 (0)