Skip to content

Commit

Permalink
Merge pull request #1037 from CraftSpider/bibtex-tests
Browse files Browse the repository at this point in the history
Add more bibtex tests
  • Loading branch information
pkgw authored May 16, 2023
2 parents ec275c6 + 84ec77c commit d03f3fe
Show file tree
Hide file tree
Showing 17 changed files with 100 additions and 12 deletions.
11 changes: 10 additions & 1 deletion crates/engine_bibtex/bibtex/bibtex.c
Original file line number Diff line number Diff line change
Expand Up @@ -529,8 +529,17 @@ input_ln(peekable_input_t *peekable)
buffer[last] = peekable_getc(peekable);
last++;
}

// For side effects - consume the eoln we saw
int eoln = peekable_getc(peekable);

peekable_getc(peekable);
if (eoln == '\r') {
// Handle \r\n newlines on Windows by trying to consume a \n after a \r, unget if it's not that exact pair
int next = peekable_getc(peekable);
if (next != '\n') {
peekable_ungetc(peekable, next);
}
}

while (last > 0) {
if (lex_class[buffer[last - 1]] == 1 /*white_space */ )
Expand Down
60 changes: 49 additions & 11 deletions tests/bibtex.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

use std::collections::HashSet;
use std::default::Default;
use std::path::PathBuf;

use tectonic::io::{FilesystemIo, IoProvider, IoStack, MemoryIo};
use tectonic::BibtexEngine;
Expand All @@ -16,29 +17,43 @@ use crate::util::{test_path, ExpectedInfo};

struct TestCase {
stem: String,
subdir: Option<String>,
test_bbl: bool,
}

impl TestCase {
fn new(stem: &str) -> Self {
fn new(stem: &str, subdir: Option<&str>) -> Self {
TestCase {
stem: stem.to_owned(),
subdir: subdir.map(String::from),
test_bbl: true,
}
}

fn go(&mut self) {
util::set_test_root();
fn test_bbl(mut self, test: bool) -> Self {
self.test_bbl = test;
self
}

fn test_dir(&self) -> PathBuf {
let mut p = test_path(&["bibtex"]);
if let Some(subdir) = &self.subdir {
p.push(subdir);
}
p
}

p.push(&self.stem);
fn go(&mut self) {
util::set_test_root();

let mut p = self.test_dir();

p.set_extension("aux");
let auxname = p.file_name().unwrap().to_str().unwrap().to_owned();
let auxname = format!("{}.aux", self.stem);

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

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

let mut genio = GenuineStdoutIo::new();

Expand All @@ -55,17 +70,40 @@ impl TestCase {

// Check that outputs match expectations.

let expected_bbl = ExpectedInfo::read_with_extension(&mut p, "bbl");
let expected_blg = ExpectedInfo::read_with_extension(&mut p, "blg");
p.push(&self.stem);

let files = mem.files.borrow();

expected_bbl.test_from_collection(&files);
if self.test_bbl {
let expected_bbl = ExpectedInfo::read_with_extension(&mut p, "bbl");
expected_bbl.test_from_collection(&files);
}

let expected_blg = ExpectedInfo::read_with_extension(&mut p, "blg");
expected_blg.test_from_collection(&files);
}
}

#[test]
fn single_entry() {
TestCase::new("single_entry").go()
TestCase::new("single_entry", None).go()
}

#[test]
fn test_empty_files() {
TestCase::new("empty", Some("empty")).test_bbl(false).go()
}

#[test]
fn test_mismatched_function() {
TestCase::new("function", Some("mismatched_braces"))
.test_bbl(false)
.go();
}

#[test]
fn test_mismatched_expr() {
TestCase::new("expr", Some("mismatched_braces"))
.test_bbl(false)
.go();
}
Empty file added tests/bibtex/empty/empty.aux
Empty file.
Empty file added tests/bibtex/empty/empty.bbl
Empty file.
Empty file added tests/bibtex/empty/empty.bib
Empty file.
7 changes: 7 additions & 0 deletions tests/bibtex/empty/empty.blg
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
This is BibTeX, Version 0.99d
Capacity: max_strings=35307, hash_size=35307, hash_prime=30011
The top-level auxiliary file: empty.aux
I found no \citation commands---while reading file empty.aux
I found no \bibdata command---while reading file empty.aux
I found no \bibstyle command---while reading file empty.aux
(There were 3 error messages)
Empty file added tests/bibtex/empty/empty.bst
Empty file.
5 changes: 5 additions & 0 deletions tests/bibtex/mismatched_braces/expr.aux
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
\relax
\citation{Mismatched01}
\bibdata{expr}
\bibcite{Mismatched01}{1}
\bibstyle{expr}
Empty file.
Empty file.
9 changes: 9 additions & 0 deletions tests/bibtex/mismatched_braces/expr.blg
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
This is BibTeX, Version 0.99d
Capacity: max_strings=35307, hash_size=35307, hash_prime=30011
The top-level auxiliary file: expr.aux
The style file: expr.bst
"}" can't start a style-file command---line 5 of file expr.bst
:
: }
(Error may have been on previous line)
(There was 1 error message)
5 changes: 5 additions & 0 deletions tests/bibtex/mismatched_braces/expr.bst
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@

FUNCTION {missing_expr_brace}
{
pop$ "" }
}
5 changes: 5 additions & 0 deletions tests/bibtex/mismatched_braces/function.aux
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
\relax
\citation{Mismatched01}
\bibdata{function}
\bibcite{Mismatched01}{1}
\bibstyle{function}
Empty file.
Empty file.
8 changes: 8 additions & 0 deletions tests/bibtex/mismatched_braces/function.blg
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
This is BibTeX, Version 0.99d
Capacity: max_strings=35307, hash_size=35307, hash_prime=30011
The top-level auxiliary file: function.aux
The style file: function.bst
Illegal end of style file in command: function---line 2 of file function.bst
: function { missing_end_brace
:
(There was 1 error message)
2 changes: 2 additions & 0 deletions tests/bibtex/mismatched_braces/function.bst
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@

FUNCTION { missing_end_brace

0 comments on commit d03f3fe

Please sign in to comment.