11//! Rust's built-in unit-test and micro-benchmarking framework.
2- #![ cfg_attr( any( unix, target_os = "cloudabi" , target_os = "fuchsia" ) , feature( libc, rustc_private) ) ]
2+ #![ cfg_attr(
3+ any( unix, target_os = "cloudabi" , target_os = "fuchsia" ) ,
4+ feature( libc, rustc_private)
5+ ) ]
36#![ feature( fnbox) ]
47#![ feature( set_stdio) ]
58#![ feature( panic_unwind) ]
@@ -56,7 +59,8 @@ mod formatters;
5659pub mod stats;
5760
5861use crate :: formatters:: {
59- JsonFormatter , OutputFormatter , PrettyFormatter , TerseFormatter ,
62+ JUnitFormatter , JsonFormatter , OutputFormatter , PrettyFormatter ,
63+ TerseFormatter ,
6064} ;
6165
6266/// Whether to execute tests concurrently or not
@@ -327,6 +331,7 @@ pub enum OutputFormat {
327331 Pretty ,
328332 Terse ,
329333 Json ,
334+ JUnit ,
330335}
331336
332337#[ derive( Copy , Clone , Debug , PartialEq , Eq ) ]
@@ -441,8 +446,9 @@ fn optgroups() -> getopts::Options {
441446 "Configure formatting of output:
442447 pretty = Print verbose output;
443448 terse = Display one character per test;
444- json = Output a json document" ,
445- "pretty|terse|json" ,
449+ json = Output a json document;
450+ junit = Output a JUnit document" ,
451+ "pretty|terse|json|junit" ,
446452 )
447453 . optopt (
448454 "Z" ,
@@ -622,10 +628,18 @@ pub fn parse_opts(args: &[String]) -> Option<OptRes> {
622628 }
623629 OutputFormat :: Json
624630 }
631+ Some ( "junit" ) => {
632+ if !allow_unstable {
633+ return Some ( Err (
634+ "The \" junit\" format is only accepted on the nightly compiler" . into ( ) ,
635+ ) ) ;
636+ }
637+ OutputFormat :: JUnit
638+ }
625639
626640 Some ( v) => {
627641 return Some ( Err ( format ! (
628- "argument for --format must be pretty, terse, or json (was \
642+ "argument for --format must be pretty, terse, json, or junit (was \
629643 {})",
630644 v
631645 ) ) ) ;
@@ -704,6 +718,7 @@ struct ConsoleTestState {
704718 failures : Vec < ( TestDesc , Vec < u8 > ) > ,
705719 not_failures : Vec < ( TestDesc , Vec < u8 > ) > ,
706720 options : Options ,
721+ start_time : Instant ,
707722}
708723
709724impl ConsoleTestState {
@@ -726,6 +741,7 @@ impl ConsoleTestState {
726741 failures : Vec :: new ( ) ,
727742 not_failures : Vec :: new ( ) ,
728743 options : opts. options ,
744+ start_time : Instant :: now ( ) ,
729745 } )
730746 }
731747
@@ -962,9 +978,9 @@ pub fn run_tests_console(
962978 is_multithreaded,
963979 ) ) ,
964980 OutputFormat :: Json => Box :: new ( JsonFormatter :: new ( output) ) ,
981+ OutputFormat :: JUnit => Box :: new ( JUnitFormatter :: new ( output) ) ,
965982 } ;
966983 let mut st = ConsoleTestState :: new ( opts) ?;
967-
968984 run_tests ( opts, tests, |x| callback ( & x, & mut st, & mut * out) ) ?;
969985
970986 assert ! ( st. current_test_count( ) == st. total) ;
@@ -1008,6 +1024,7 @@ fn should_sort_failures_before_printing_them() {
10081024 failures : vec ! [ ( test_b, Vec :: new( ) ) , ( test_a, Vec :: new( ) ) ] ,
10091025 options : Options :: new ( ) ,
10101026 not_failures : Vec :: new ( ) ,
1027+ start_time : Instant :: now ( ) ,
10111028 } ;
10121029
10131030 out. write_failures ( & st) . unwrap ( ) ;
0 commit comments