@@ -15,12 +15,7 @@ fn main() {
1515 . chain ( find_source_files ( "tests" ) . map ( extract_term_test) )
1616 . collect ( ) ;
1717
18- libtest_mimic:: run_tests ( & args, tests, run_test) . exit ( ) ;
19- }
20-
21- pub struct TestData {
22- input_file : PathBuf ,
23- mode : TestMode ,
18+ libtest_mimic:: run ( & args, tests) . exit ( ) ;
2419}
2520
2621#[ derive( Deserialize , Debug , Copy , Clone ) ]
@@ -138,73 +133,63 @@ pub fn find_source_files(root: impl AsRef<Path>) -> impl Iterator<Item = PathBuf
138133 . map ( |entry| entry. into_path ( ) )
139134}
140135
141- fn extract_module_test ( path : PathBuf ) -> libtest_mimic:: Test < TestData > {
142- libtest_mimic:: Test {
143- name : path. display ( ) . to_string ( ) ,
144- kind : String :: new ( ) ,
145- is_ignored : false ,
146- is_bench : false ,
147- data : TestData {
148- input_file : path,
149- mode : TestMode :: Module ,
150- } ,
151- }
136+ fn extract_module_test ( path : PathBuf ) -> libtest_mimic:: Trial {
137+ extract_test ( path, TestMode :: Module )
152138}
153139
154- fn extract_term_test ( path : PathBuf ) -> libtest_mimic:: Test < TestData > {
155- libtest_mimic:: Test {
156- name : path. display ( ) . to_string ( ) ,
157- kind : String :: new ( ) ,
158- is_ignored : false ,
159- is_bench : false ,
160- data : TestData {
161- input_file : path,
162- mode : TestMode :: Term ,
163- } ,
164- }
140+ fn extract_term_test ( path : PathBuf ) -> libtest_mimic:: Trial {
141+ extract_test ( path, TestMode :: Term )
165142}
166143
167- fn run_test ( test : & libtest_mimic :: Test < TestData > ) -> libtest_mimic:: Outcome {
168- let mut failures = Vec :: new ( ) ;
144+ fn extract_test ( input_file : PathBuf , default_mode : TestMode ) -> libtest_mimic:: Trial {
145+ use itertools :: Itertools ;
169146
170- let config: Config = {
171- use itertools:: Itertools ;
147+ let test_name = input_file. display ( ) . to_string ( ) ;
172148
173- const CONFIG_COMMENT_START : & str = "//~" ;
149+ const CONFIG_COMMENT_START : & str = "//~" ;
174150
175- let input_source = std:: fs:: read_to_string ( & test . data . input_file ) . unwrap ( ) ;
176- // Collect the lines with CONFIG_COMMENT_START prefix, stripping the prefix in the process
177- let config_source = input_source
178- . lines ( )
179- . filter_map ( |line| line. split ( CONFIG_COMMENT_START ) . nth ( 1 ) )
180- . join ( "\n " ) ;
151+ let input_source = std:: fs:: read_to_string ( & input_file) . unwrap ( ) ;
152+ // Collect the lines with CONFIG_COMMENT_START prefix, stripping the prefix in the process
153+ let config_source = input_source
154+ . lines ( )
155+ . filter_map ( |line| line. split ( CONFIG_COMMENT_START ) . nth ( 1 ) )
156+ . join ( "\n " ) ;
181157
182- // Parse those lines as TOML
183- match toml:: from_str :: < Config > ( & config_source) {
184- Ok ( mut config) => {
185- config. update_snapshots = env:: var_os ( "FATHOM_UPDATE_SNAP" ) . is_some ( ) ;
186- config
187- }
188- Err ( error) => {
189- failures. push ( TestFailure {
190- name : "config parse error" ,
191- details : vec ! [ ( "toml::de::Error" , error. to_string( ) ) ] ,
192- } ) ;
158+ // Parse those lines as TOML
159+ match toml:: from_str :: < Config > ( & config_source) {
160+ Ok ( mut config) => {
161+ config. update_snapshots = env:: var_os ( "FATHOM_UPDATE_SNAP" ) . is_some ( ) ;
193162
194- return failures_to_outcome ( & failures) ;
163+ if config. ignore {
164+ libtest_mimic:: Trial :: test ( test_name, || Ok ( ( ) ) ) . with_ignored_flag ( true )
165+ } else {
166+ libtest_mimic:: Trial :: test ( test_name, move || {
167+ run_test ( input_file, default_mode, config)
168+ } )
195169 }
196170 }
197- } ;
198-
199- if config. ignore {
200- return libtest_mimic:: Outcome :: Ignored ;
171+ Err ( error) => libtest_mimic:: Trial :: test ( test_name, move || {
172+ failures_to_outcome ( & [ TestFailure {
173+ name : "config parse error" ,
174+ details : vec ! [ ( "toml::de::Error" , error. to_string( ) ) ] ,
175+ } ] )
176+ } ) ,
201177 }
178+ }
179+
180+ fn run_test (
181+ input_file : PathBuf ,
182+ default_mode : TestMode ,
183+ config : Config ,
184+ ) -> Result < ( ) , libtest_mimic:: Failed > {
185+ let mut failures = Vec :: new ( ) ;
202186
203187 let command = match config. mode {
204188 Some ( mode) => mode. to_command ( ) ,
205- None => test . data . mode . to_command ( ) ,
189+ None => default_mode . to_command ( ) ,
206190 } ;
207- let test_command = TestCommand :: new ( command, & config, & test. data . input_file ) ;
191+
192+ let test_command = TestCommand :: new ( command, & config, & input_file) ;
208193 match test_command. run ( ) {
209194 Ok ( mut test_failures) => failures. append ( & mut test_failures) ,
210195 Err ( error) => {
@@ -216,7 +201,7 @@ fn run_test(test: &libtest_mimic::Test<TestData>) -> libtest_mimic::Outcome {
216201 }
217202
218203 if config. test_normalisation {
219- let test_command = TestCommand :: new ( Command :: Normalise , & config, & test . data . input_file ) ;
204+ let test_command = TestCommand :: new ( Command :: Normalise , & config, & input_file) ;
220205 match test_command. run ( ) {
221206 Ok ( mut test_failures) => failures. append ( & mut test_failures) ,
222207 Err ( error) => {
@@ -228,13 +213,13 @@ fn run_test(test: &libtest_mimic::Test<TestData>) -> libtest_mimic::Outcome {
228213 }
229214 }
230215
231- let base_dir = test . data . input_file . with_file_name ( "" ) ;
216+ let base_dir = input_file. with_file_name ( "" ) ;
232217 let example_data = globwalk:: GlobWalkerBuilder :: from_patterns ( & base_dir, & config. example_data )
233218 . build ( )
234219 . unwrap ( ) ;
235220
236221 for example_file in example_data. filter_map ( Result :: ok) {
237- let command = Command :: ParseData ( & test . data . input_file , ExpectedOutcome :: Success ) ;
222+ let command = Command :: ParseData ( & input_file, ExpectedOutcome :: Success ) ;
238223 let test_command = TestCommand :: new ( command, & config, example_file. path ( ) ) ;
239224 match test_command. run ( ) {
240225 Ok ( mut test_failures) => failures. append ( & mut test_failures) ,
@@ -253,7 +238,7 @@ fn run_test(test: &libtest_mimic::Test<TestData>) -> libtest_mimic::Outcome {
253238 . unwrap ( ) ;
254239
255240 for example_file in invalid_example_data. filter_map ( Result :: ok) {
256- let command = Command :: ParseData ( & test . data . input_file , ExpectedOutcome :: Failure ) ;
241+ let command = Command :: ParseData ( & input_file, ExpectedOutcome :: Failure ) ;
257242 let test_command = TestCommand :: new ( command, & config, example_file. path ( ) ) ;
258243 match test_command. run ( ) {
259244 Ok ( mut test_failures) => failures. append ( & mut test_failures) ,
@@ -269,9 +254,9 @@ fn run_test(test: &libtest_mimic::Test<TestData>) -> libtest_mimic::Outcome {
269254 failures_to_outcome ( & failures)
270255}
271256
272- fn failures_to_outcome ( failures : & [ TestFailure ] ) -> libtest_mimic:: Outcome {
257+ fn failures_to_outcome ( failures : & [ TestFailure ] ) -> Result < ( ) , libtest_mimic:: Failed > {
273258 if failures. is_empty ( ) {
274- libtest_mimic :: Outcome :: Passed
259+ Ok ( ( ) )
275260 } else {
276261 let mut msg = String :: new ( ) ;
277262
@@ -292,7 +277,7 @@ fn failures_to_outcome(failures: &[TestFailure]) -> libtest_mimic::Outcome {
292277 writeln ! ( msg, " {}" , failure. name) . unwrap ( ) ;
293278 }
294279
295- libtest_mimic :: Outcome :: Failed { msg : Some ( msg) }
280+ Err ( msg. into ( ) )
296281 }
297282}
298283
0 commit comments