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,43 @@ 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 ( 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]
6988fn 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}
0 commit comments