33
44use std:: collections:: HashSet ;
55use std:: default:: Default ;
6+ use std:: path:: PathBuf ;
67
78use tectonic:: io:: { FilesystemIo , IoProvider , IoStack , MemoryIo } ;
89use tectonic:: BibtexEngine ;
@@ -16,29 +17,46 @@ use crate::util::{test_path, ExpectedInfo};
1617
1718struct TestCase {
1819 stem : String ,
20+ subdir : Option < String > ,
21+ test_bbl : bool ,
1922}
2023
2124impl 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]
6991fn 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}
0 commit comments