From 85a1e2b55baf0fb59187b9eb47a8fc6e8089eaff Mon Sep 17 00:00:00 2001 From: Rune Tynan Date: Tue, 27 Feb 2024 21:44:06 -0800 Subject: [PATCH] Fix multi-file logging, add test --- crates/engine_bibtex/src/bibs.rs | 6 +++--- crates/engine_bibtex/src/bst.rs | 11 ++++++----- crates/engine_bibtex/src/log.rs | 6 +++--- tests/bibtex.rs | 5 +++++ tests/bibtex/cites/multi_file.aux | 7 +++++++ tests/bibtex/cites/multi_file.bbl | 13 +++++++++++++ tests/bibtex/cites/multi_file.blg | 6 ++++++ tests/bibtex/cites/multi_file_1.bib | 6 ++++++ tests/bibtex/cites/multi_file_2.bib | 6 ++++++ 9 files changed, 55 insertions(+), 11 deletions(-) create mode 100644 tests/bibtex/cites/multi_file.aux create mode 100644 tests/bibtex/cites/multi_file.bbl create mode 100644 tests/bibtex/cites/multi_file.blg create mode 100644 tests/bibtex/cites/multi_file_1.bib create mode 100644 tests/bibtex/cites/multi_file_2.bib diff --git a/crates/engine_bibtex/src/bibs.rs b/crates/engine_bibtex/src/bibs.rs index 4696e2bae..953b49d9a 100644 --- a/crates/engine_bibtex/src/bibs.rs +++ b/crates/engine_bibtex/src/bibs.rs @@ -35,11 +35,11 @@ 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) { @@ -47,7 +47,7 @@ impl BibData { } pub fn pop_file(&mut self) -> File { - self.bibs.pop().unwrap() + self.bibs.remove(0) } pub fn add_preamble(&mut self, s: StrNumber) { diff --git a/crates/engine_bibtex/src/bst.rs b/crates/engine_bibtex/src/bst.rs index 5733133c0..daa8ed046 100644 --- a/crates/engine_bibtex/src/bst.rs +++ b/crates/engine_bibtex/src/bst.rs @@ -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 diff --git a/crates/engine_bibtex/src/log.rs b/crates/engine_bibtex/src/log.rs index 383a7848f..223cefb29 100644 --- a/crates/engine_bibtex/src/log.rs +++ b/crates/engine_bibtex/src/log.rs @@ -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 { diff --git a/tests/bibtex.rs b/tests/bibtex.rs index cf1a9dfb1..36d90c2c1 100644 --- a/tests/bibtex.rs +++ b/tests/bibtex.rs @@ -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() diff --git a/tests/bibtex/cites/multi_file.aux b/tests/bibtex/cites/multi_file.aux new file mode 100644 index 000000000..fa40a30cc --- /dev/null +++ b/tests/bibtex/cites/multi_file.aux @@ -0,0 +1,7 @@ +\relax +\citation{Nobody01} +\citation{Nobody02} +\bibdata{multi_file_1,multi_file_2} +\bibcite{Nobody01}{1} +\bibcite{Nobody02}{1} +\bibstyle{../plain} \ No newline at end of file diff --git a/tests/bibtex/cites/multi_file.bbl b/tests/bibtex/cites/multi_file.bbl new file mode 100644 index 000000000..621f3dfef --- /dev/null +++ b/tests/bibtex/cites/multi_file.bbl @@ -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} diff --git a/tests/bibtex/cites/multi_file.blg b/tests/bibtex/cites/multi_file.blg new file mode 100644 index 000000000..730024c1e --- /dev/null +++ b/tests/bibtex/cites/multi_file.blg @@ -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 diff --git a/tests/bibtex/cites/multi_file_1.bib b/tests/bibtex/cites/multi_file_1.bib new file mode 100644 index 000000000..5e60c166b --- /dev/null +++ b/tests/bibtex/cites/multi_file_1.bib @@ -0,0 +1,6 @@ +@book{Nobody02, + title = "A book", + author = "Nobody Sr.", + publisher = "Nobody", + year = 2024, +} diff --git a/tests/bibtex/cites/multi_file_2.bib b/tests/bibtex/cites/multi_file_2.bib new file mode 100644 index 000000000..66c1c003d --- /dev/null +++ b/tests/bibtex/cites/multi_file_2.bib @@ -0,0 +1,6 @@ +@book{Nobody01, + title = "A book", + author = "Nobody Sr.", + publisher = "Nobody", + year = 2024, +}