@@ -51,6 +51,7 @@ impl BuildMetrics {
5151 duration_excluding_children_sec : Duration :: ZERO ,
5252
5353 children : Vec :: new ( ) ,
54+ tests : Vec :: new ( ) ,
5455 } ) ;
5556 }
5657
@@ -72,6 +73,16 @@ impl BuildMetrics {
7273 }
7374 }
7475
76+ pub ( crate ) fn record_test ( & self , name : & str , outcome : TestOutcome ) {
77+ let mut state = self . state . borrow_mut ( ) ;
78+ state
79+ . running_steps
80+ . last_mut ( )
81+ . unwrap ( )
82+ . tests
83+ . push ( Test { name : name. to_string ( ) , outcome } ) ;
84+ }
85+
7586 fn collect_stats ( & self , state : & mut MetricsState ) {
7687 let step = state. running_steps . last_mut ( ) . unwrap ( ) ;
7788
@@ -125,6 +136,14 @@ impl BuildMetrics {
125136 }
126137
127138 fn prepare_json_step ( & self , step : StepMetrics ) -> JsonNode {
139+ let mut children = Vec :: new ( ) ;
140+ children. extend ( step. children . into_iter ( ) . map ( |child| self . prepare_json_step ( child) ) ) ;
141+ children. extend (
142+ step. tests
143+ . into_iter ( )
144+ . map ( |test| JsonNode :: Test { name : test. name , outcome : test. outcome } ) ,
145+ ) ;
146+
128147 JsonNode :: RustbuildStep {
129148 type_ : step. type_ ,
130149 debug_repr : step. debug_repr ,
@@ -135,11 +154,7 @@ impl BuildMetrics {
135154 / step. duration_excluding_children_sec . as_secs_f64 ( ) ,
136155 } ,
137156
138- children : step
139- . children
140- . into_iter ( )
141- . map ( |child| self . prepare_json_step ( child) )
142- . collect ( ) ,
157+ children,
143158 }
144159 }
145160}
@@ -161,6 +176,12 @@ struct StepMetrics {
161176 duration_excluding_children_sec : Duration ,
162177
163178 children : Vec < StepMetrics > ,
179+ tests : Vec < Test > ,
180+ }
181+
182+ struct Test {
183+ name : String ,
184+ outcome : TestOutcome ,
164185}
165186
166187#[ derive( Serialize , Deserialize ) ]
@@ -190,6 +211,19 @@ enum JsonNode {
190211
191212 children : Vec < JsonNode > ,
192213 } ,
214+ Test {
215+ name : String ,
216+ #[ serde( flatten) ]
217+ outcome : TestOutcome ,
218+ } ,
219+ }
220+
221+ #[ derive( Serialize , Deserialize ) ]
222+ #[ serde( tag = "outcome" , rename_all = "snake_case" ) ]
223+ pub ( crate ) enum TestOutcome {
224+ Passed ,
225+ Failed ,
226+ Ignored { ignore_reason : Option < String > } ,
193227}
194228
195229#[ derive( Serialize , Deserialize ) ]
0 commit comments