diff options
| author | Matthias Krüger <476013+matthiaskrgr@users.noreply.github.com> | 2025-03-10 15:57:12 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-03-10 15:57:12 +0100 |
| commit | 5717cc9ef7cdba1fe1a7710637688dfb20a85493 (patch) | |
| tree | fd1f3862426ff1ad2d1b89cecf18f8172efa90c9 /src | |
| parent | 739672cf165b665ad4739a431d95d55d8e25db14 (diff) | |
| parent | 1483cb67d91f493c9e8599cc969a03ae1b846435 (diff) | |
Rollup merge of #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`
Diffstat (limited to 'src')
| -rw-r--r-- | src/ci/citool/src/metrics.rs | 10 |
1 files changed, 7 insertions, 3 deletions
diff --git a/src/ci/citool/src/metrics.rs b/src/ci/citool/src/metrics.rs index 8548602b31c..83b3d5ceed0 100644 --- a/src/ci/citool/src/metrics.rs +++ b/src/ci/citool/src/metrics.rs @@ -67,6 +67,10 @@ fn render_table(suites: BTreeMap<String, TestSuiteRecord>) -> String { let mut table = "| Test suite | Passed ✅ | Ignored 🚫 | Failed ❌ |\n".to_string(); writeln!(table, "|:------|------:|------:|------:|").unwrap(); + fn compute_pct(value: f64, total: f64) -> f64 { + if total == 0.0 { 0.0 } else { value / total } + } + fn write_row( buffer: &mut String, name: &str, @@ -75,9 +79,9 @@ fn render_table(suites: BTreeMap<String, TestSuiteRecord>) -> String { ) -> std::fmt::Result { let TestSuiteRecord { passed, ignored, failed } = record; let total = (record.passed + record.ignored + record.failed) as f64; - let passed_pct = ((*passed as f64) / total) * 100.0; - let ignored_pct = ((*ignored as f64) / total) * 100.0; - let failed_pct = ((*failed as f64) / total) * 100.0; + let passed_pct = compute_pct(*passed as f64, total) * 100.0; + let ignored_pct = compute_pct(*ignored as f64, total) * 100.0; + let failed_pct = compute_pct(*failed as f64, total) * 100.0; write!(buffer, "| {surround}{name}{surround} |")?; write!(buffer, " {surround}{passed} ({passed_pct:.0}%){surround} |")?; |
