@@ -36,13 +36,11 @@ use std::env;
36
36
use std:: fs:: { self , File } ;
37
37
use std:: io:: prelude:: * ;
38
38
use std:: io;
39
- use std:: iter;
40
39
use std:: path:: { Path , PathBuf } ;
41
- use std:: process:: { self , Command , Stdio } ;
40
+ use std:: process:: { Command , Stdio } ;
42
41
43
42
use cargo:: Target ;
44
43
use json:: Documentation ;
45
- use test:: TestResult ;
46
44
use ui:: Ui ;
47
45
48
46
pub use json:: create_documentation;
@@ -228,81 +226,33 @@ pub fn test(config: &Config) -> Result<()> {
228
226
. map_err ( |e| failure:: Error :: from ( e. context ( "could not find generated documentation" ) ) ) ?;
229
227
let docs: Documentation = serde_json:: from_reader ( doc_json) ?;
230
228
229
+ // TODO a better way to find crate name?
231
230
let krate = docs. data . as_ref ( ) . unwrap ( ) ;
232
- let tests: Vec < _ > = iter:: once ( krate)
233
- . chain ( docs. included . iter ( ) . flat_map ( |data| data) )
234
- . map ( |data| ( & data. id , test:: gather_tests ( & data) ) )
235
- . collect ( ) ;
236
-
237
- // Run the tests.
238
- static SUCCESS_MESSAGE : & str = "ok" ;
239
- static FAILURE_MESSAGE : & str = "FAILED" ;
240
-
241
- let num_tests: usize = tests. iter ( ) . map ( |& ( _, ref tests) | tests. len ( ) ) . sum ( ) ;
242
- println ! ( "running {} tests" , num_tests) ;
243
-
244
- let mut passed = 0 ;
245
- let mut failures = vec ! [ ] ;
246
- for ( id, tests) in tests {
247
- for ( number, test) in tests. iter ( ) . enumerate ( ) {
248
- // FIXME: Make the name based off the file and line number.
249
- let name = format ! ( "{} - {}" , id, number) ;
250
- print ! ( "test {} ... " , name) ;
251
- io:: stdout ( ) . flush ( ) ?;
252
-
253
- let message = match test:: run_test ( config, test) ? {
254
- TestResult :: Success => {
255
- passed += 1 ;
256
- SUCCESS_MESSAGE
257
- }
258
- TestResult :: Failure ( output) => {
259
- failures. push ( ( name, output) ) ;
260
- FAILURE_MESSAGE
261
- }
262
- } ;
263
-
264
- println ! ( "{}" , message) ;
265
- }
266
- }
231
+ let crate_name = krate. id . split ( "::" ) . next ( ) . unwrap ( ) ;
267
232
268
- if !failures. is_empty ( ) {
269
- // Print the output of each failure.
270
- for & ( ref name, ref output) in & failures {
271
- let stdout = String :: from_utf8_lossy ( & output. stdout ) ;
272
- let stdout = stdout. trim ( ) ;
273
-
274
- if !stdout. is_empty ( ) {
275
- println ! ( "\n ---- {} stdout ----\n {}" , name, stdout) ;
276
- }
277
-
278
- let stderr = String :: from_utf8_lossy ( & output. stderr ) ;
279
- let stderr = stderr. trim ( ) ;
280
-
281
- if !stderr. is_empty ( ) {
282
- println ! ( "\n ---- {} stderr ----\n {}" , name, stderr) ;
283
- }
284
- }
233
+ let location = config. output_path ( ) . join ( "tests" ) ;
234
+ let tests = {
235
+ let task = config. ui . start_task ( "Finding tests" ) ;
236
+ task. report ( "In Progress" ) ;
237
+ test:: find_tests ( & docs)
238
+ } ;
285
239
286
- // Print a summary of all failures at the bottom.
287
- println ! ( "\n failures:" ) ;
288
- for & ( ref name, _) in & failures {
289
- println ! ( " {}" , name) ;
290
- }
240
+ {
241
+ let task = config. ui . start_task ( "Saving tests" ) ;
242
+ task. report ( "In Progress" ) ;
243
+ test:: save_tests ( & tests, & location, & crate_name) ?;
291
244
}
292
245
293
- println ! (
294
- "\n test result: {}. {} passed; {} failed; 0 ignored; 0 measured; 0 filtered out" ,
295
- if failures. is_empty( ) {
296
- SUCCESS_MESSAGE
297
- } else {
298
- FAILURE_MESSAGE
299
- } ,
300
- passed,
301
- failures. len( )
302
- ) ;
303
-
304
- if !failures. is_empty ( ) {
305
- process:: exit ( 1 ) ;
246
+ let binary = {
247
+ let task = config. ui . start_task ( "Compiling tests" ) ;
248
+ task. report ( "In Progress" ) ;
249
+ test:: compile_tests ( & config, & location) ?
250
+ } ;
251
+
252
+ {
253
+ let task = config. ui . start_task ( "Executing tests" ) ;
254
+ task. report ( "In Progress" ) ;
255
+ test:: execute_tests ( & binary) ?;
306
256
}
307
257
308
258
Ok ( ( ) )
0 commit comments