11use std:: collections:: BTreeMap ;
2+ use std:: fs:: File ;
23use std:: io:: Write ;
34use std:: path:: Path ;
45
@@ -7,25 +8,29 @@ use build_helper::metrics::{JsonNode, JsonRoot, TestOutcome, TestSuite, TestSuit
78
89pub fn postprocess_metrics ( metrics_path : & Path , summary_path : & Path ) -> anyhow:: Result < ( ) > {
910 let metrics = load_metrics ( metrics_path) ?;
10- let suites = get_test_suites ( & metrics) ;
11-
12- if suites. is_empty ( ) {
13- eprintln ! ( "No test suites found in {}" , metrics_path. display( ) ) ;
14- return Ok ( ( ) ) ;
15- }
1611
17- let aggregated = aggregate_test_suites ( & suites) ;
18- let table = render_table ( aggregated) ;
19-
20- let mut file = std:: fs:: File :: options ( )
12+ let mut file = File :: options ( )
2113 . append ( true )
2214 . create ( true )
2315 . open ( summary_path)
2416 . with_context ( || format ! ( "Cannot open summary file at {summary_path:?}" ) ) ?;
25- writeln ! ( file, "\n # Test results\n " ) ?;
26- writeln ! ( file, "{table}" ) ?;
2717
28- eprintln ! ( "Written test suite summary into {}" , summary_path. display( ) ) ;
18+ record_test_suites ( & metrics, & mut file) ?;
19+
20+ Ok ( ( ) )
21+ }
22+
23+ fn record_test_suites ( metrics : & JsonRoot , file : & mut File ) -> anyhow:: Result < ( ) > {
24+ let suites = get_test_suites ( & metrics) ;
25+
26+ if !suites. is_empty ( ) {
27+ let aggregated = aggregate_test_suites ( & suites) ;
28+ let table = render_table ( aggregated) ;
29+ writeln ! ( file, "\n # Test results\n " ) ?;
30+ writeln ! ( file, "{table}" ) ?;
31+ } else {
32+ eprintln ! ( "No test suites found in metrics" ) ;
33+ }
2934
3035 Ok ( ( ) )
3136}
0 commit comments