1
1
use std:: collections:: BTreeMap ;
2
+ use std:: fs:: File ;
2
3
use std:: io:: Write ;
3
4
use std:: path:: Path ;
4
5
@@ -7,25 +8,29 @@ use build_helper::metrics::{JsonNode, JsonRoot, TestOutcome, TestSuite, TestSuit
7
8
8
9
pub fn postprocess_metrics ( metrics_path : & Path , summary_path : & Path ) -> anyhow:: Result < ( ) > {
9
10
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
- }
16
11
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 ( )
21
13
. append ( true )
22
14
. create ( true )
23
15
. open ( summary_path)
24
16
. with_context ( || format ! ( "Cannot open summary file at {summary_path:?}" ) ) ?;
25
- writeln ! ( file, "\n # Test results\n " ) ?;
26
- writeln ! ( file, "{table}" ) ?;
27
17
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
+ }
29
34
30
35
Ok ( ( ) )
31
36
}
0 commit comments