Skip to content

Commit 60c64a8

Browse files
authored
Unrolled build for rust-lang#138268
Rollup merge of rust-lang#138268 - Kobzol:fix-summary-nan, r=jieyouxu Handle empty test suites in GitHub job summary report Should fix [NaN](https://github.com/rust-lang-ci/rust/actions/runs/13739044506#summary-38426140405)s being printed. r? `@jieyouxu`
2 parents 2b285cd + 1483cb6 commit 60c64a8

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

src/ci/citool/src/metrics.rs

+7-3
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,10 @@ fn render_table(suites: BTreeMap<String, TestSuiteRecord>) -> String {
6767
let mut table = "| Test suite | Passed ✅ | Ignored 🚫 | Failed ❌ |\n".to_string();
6868
writeln!(table, "|:------|------:|------:|------:|").unwrap();
6969

70+
fn compute_pct(value: f64, total: f64) -> f64 {
71+
if total == 0.0 { 0.0 } else { value / total }
72+
}
73+
7074
fn write_row(
7175
buffer: &mut String,
7276
name: &str,
@@ -75,9 +79,9 @@ fn render_table(suites: BTreeMap<String, TestSuiteRecord>) -> String {
7579
) -> std::fmt::Result {
7680
let TestSuiteRecord { passed, ignored, failed } = record;
7781
let total = (record.passed + record.ignored + record.failed) as f64;
78-
let passed_pct = ((*passed as f64) / total) * 100.0;
79-
let ignored_pct = ((*ignored as f64) / total) * 100.0;
80-
let failed_pct = ((*failed as f64) / total) * 100.0;
82+
let passed_pct = compute_pct(*passed as f64, total) * 100.0;
83+
let ignored_pct = compute_pct(*ignored as f64, total) * 100.0;
84+
let failed_pct = compute_pct(*failed as f64, total) * 100.0;
8185

8286
write!(buffer, "| {surround}{name}{surround} |")?;
8387
write!(buffer, " {surround}{passed} ({passed_pct:.0}%){surround} |")?;

0 commit comments

Comments
 (0)