Skip to content

Commit d03f3fe

Browse files
authored
Merge pull request #1037 from CraftSpider/bibtex-tests
Add more bibtex tests
2 parents ec275c6 + 84ec77c commit d03f3fe

17 files changed

Lines changed: 100 additions & 12 deletions

File tree

crates/engine_bibtex/bibtex/bibtex.c

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -529,8 +529,17 @@ input_ln(peekable_input_t *peekable)
529529
buffer[last] = peekable_getc(peekable);
530530
last++;
531531
}
532+
533+
// For side effects - consume the eoln we saw
534+
int eoln = peekable_getc(peekable);
532535

533-
peekable_getc(peekable);
536+
if (eoln == '\r') {
537+
// Handle \r\n newlines on Windows by trying to consume a \n after a \r, unget if it's not that exact pair
538+
int next = peekable_getc(peekable);
539+
if (next != '\n') {
540+
peekable_ungetc(peekable, next);
541+
}
542+
}
534543

535544
while (last > 0) {
536545
if (lex_class[buffer[last - 1]] == 1 /*white_space */ )

tests/bibtex.rs

Lines changed: 49 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,43 @@ 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(stem: &str, subdir: Option<&str>) -> Self {
2326
TestCase {
2427
stem: stem.to_owned(),
28+
subdir: subdir.map(String::from),
29+
test_bbl: true,
2530
}
2631
}
2732

28-
fn go(&mut self) {
29-
util::set_test_root();
33+
fn test_bbl(mut self, test: bool) -> Self {
34+
self.test_bbl = test;
35+
self
36+
}
3037

38+
fn test_dir(&self) -> PathBuf {
3139
let mut p = test_path(&["bibtex"]);
40+
if let Some(subdir) = &self.subdir {
41+
p.push(subdir);
42+
}
43+
p
44+
}
3245

33-
p.push(&self.stem);
46+
fn go(&mut self) {
47+
util::set_test_root();
48+
49+
let mut p = self.test_dir();
3450

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

3853
// MemoryIo layer that will accept the outputs.
3954
let mut mem = MemoryIo::new(true);
4055

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

4358
let mut genio = GenuineStdoutIo::new();
4459

@@ -55,17 +70,40 @@ impl TestCase {
5570

5671
// Check that outputs match expectations.
5772

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

6175
let files = mem.files.borrow();
6276

63-
expected_bbl.test_from_collection(&files);
77+
if self.test_bbl {
78+
let expected_bbl = ExpectedInfo::read_with_extension(&mut p, "bbl");
79+
expected_bbl.test_from_collection(&files);
80+
}
81+
82+
let expected_blg = ExpectedInfo::read_with_extension(&mut p, "blg");
6483
expected_blg.test_from_collection(&files);
6584
}
6685
}
6786

6887
#[test]
6988
fn single_entry() {
70-
TestCase::new("single_entry").go()
89+
TestCase::new("single_entry", None).go()
90+
}
91+
92+
#[test]
93+
fn test_empty_files() {
94+
TestCase::new("empty", Some("empty")).test_bbl(false).go()
95+
}
96+
97+
#[test]
98+
fn test_mismatched_function() {
99+
TestCase::new("function", Some("mismatched_braces"))
100+
.test_bbl(false)
101+
.go();
102+
}
103+
104+
#[test]
105+
fn test_mismatched_expr() {
106+
TestCase::new("expr", Some("mismatched_braces"))
107+
.test_bbl(false)
108+
.go();
71109
}

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.

0 commit comments

Comments
 (0)