Skip to content

Commit

Permalink
Fix multi-file logging, add test
Browse files Browse the repository at this point in the history
  • Loading branch information
CraftSpider committed Feb 28, 2024
1 parent 1dbe117 commit 5715551
Show file tree
Hide file tree
Showing 9 changed files with 55 additions and 11 deletions.
6 changes: 3 additions & 3 deletions crates/engine_bibtex/src/bibs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,19 +35,19 @@ impl BibData {
}

pub fn top_file(&self) -> &File {
self.bibs.last().unwrap()
self.bibs.first().unwrap()
}

pub fn top_file_mut(&mut self) -> &mut File {
self.bibs.last_mut().unwrap()
self.bibs.first_mut().unwrap()
}

pub fn push_file(&mut self, file: File) {
self.bibs.push(file);
}

pub fn pop_file(&mut self) -> File {
self.bibs.pop().unwrap()
self.bibs.remove(0)
}

pub fn add_preamble(&mut self, s: StrNumber) {
Expand Down
11 changes: 6 additions & 5 deletions crates/engine_bibtex/src/bst.rs
Original file line number Diff line number Diff line change
Expand Up @@ -519,13 +519,14 @@ fn bst_read_command(
}

ctx.read_performed = true;
while globals.bibs.len() != 0 {
for idx in 0..globals.bibs.len() {
let file = globals.bibs.top_file();
if ctx.config.verbose {
ctx.write_logs(&format!("Database file #{}: ", globals.bibs.len()));
print_bib_name(ctx, globals.pool, globals.bibs.top_file().name)?;
ctx.write_logs(&format!("Database file #{}: ", idx + 1));
print_bib_name(ctx, globals.pool, file.name)?;
} else {
ctx.write_log_file(&format!("Database file #{}: ", globals.bibs.len()));
log_pr_bib_name(ctx, globals.bibs, globals.pool)?;
ctx.write_log_file(&format!("Database file #{}: ", idx + 1));
log_pr_bib_name(ctx, globals.pool, file.name)?;
}

globals
Expand Down
6 changes: 3 additions & 3 deletions crates/engine_bibtex/src/log.rs
Original file line number Diff line number Diff line change
Expand Up @@ -248,12 +248,12 @@ pub(crate) fn print_bib_name(

pub(crate) fn log_pr_bib_name(
ctx: &mut Bibtex<'_, '_>,
bibs: &BibData,
pool: &StringPool,
name: StrNumber,
) -> Result<(), BibtexError> {
out_pool_str(ctx, pool, bibs.top_file().name)?;
out_pool_str(ctx, pool, name)?;
let res = pool
.try_get_str(bibs.top_file().name)
.try_get_str(name)
.map(|str| str.ends_with(b".bib"))
.map_err(|_| BibtexError::Fatal)?;
if !res {
Expand Down
5 changes: 5 additions & 0 deletions tests/bibtex.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,11 @@ fn test_control_sequences() {
TestCase::new("control_seq", Some("cites")).go();
}

#[test]
fn test_multi_bib() {
TestCase::new("multi_file", Some("cites")).go();
}

#[test]
fn test_empty_files() {
TestCase::new("empty", None).test_bbl(false).go()
Expand Down
7 changes: 7 additions & 0 deletions tests/bibtex/cites/multi_file.aux
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
\relax
\citation{Nobody01}
\citation{Nobody02}
\bibdata{multi_file_1,multi_file_2}
\bibcite{Nobody01}{1}
\bibcite{Nobody02}{1}
\bibstyle{../plain}
13 changes: 13 additions & 0 deletions tests/bibtex/cites/multi_file.bbl
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
\begin{thebibliography}{1}

\bibitem{Nobody01}
Nobody Sr.
\newblock {\em A book}.
\newblock Nobody, 2024.

\bibitem{Nobody02}
Nobody Sr.
\newblock {\em A book}.
\newblock Nobody, 2024.

\end{thebibliography}
6 changes: 6 additions & 0 deletions tests/bibtex/cites/multi_file.blg
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
This is BibTeX, Version 0.99d
Capacity: max_strings=35307, hash_size=35307, hash_prime=30011
The top-level auxiliary file: multi_file.aux
The style file: ../plain.bst
Database file #1: multi_file_1.bib
Database file #2: multi_file_2.bib
6 changes: 6 additions & 0 deletions tests/bibtex/cites/multi_file_1.bib
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
@book{Nobody02,
title = "A book",
author = "Nobody Sr.",
publisher = "Nobody",
year = 2024,
}
6 changes: 6 additions & 0 deletions tests/bibtex/cites/multi_file_2.bib
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
@book{Nobody01,
title = "A book",
author = "Nobody Sr.",
publisher = "Nobody",
year = 2024,
}

0 comments on commit 5715551

Please sign in to comment.