From bbaf81528c179bcd9c02932ef63844506ca29ad8 Mon Sep 17 00:00:00 2001 From: Colin Rofls Date: Sun, 27 Oct 2024 13:43:21 -0400 Subject: [PATCH] [crater] Don't serialize nans This would happen in certain cases where some error caused every target to fail. This hasn't happened in production but it has happened various times in my local testing, and it's annoying. --- fontc_crater/src/ttx_diff_runner.rs | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/fontc_crater/src/ttx_diff_runner.rs b/fontc_crater/src/ttx_diff_runner.rs index 3c6fdf7c..6dbfbf9a 100644 --- a/fontc_crater/src/ttx_diff_runner.rs +++ b/fontc_crater/src/ttx_diff_runner.rs @@ -107,8 +107,9 @@ impl Summary { }) .sum::(); let total_diff = total_diff + (identical as f32); - let diff_perc_including_failures = total_diff / (n_failed + success.len()) as f32 * 100.; - let diff_perc_excluding_failures = total_diff / success.len() as f32 * 100.; + let diff_perc_including_failures = + non_nan(total_diff / (n_failed + success.len()) as f32) * 100.; + let diff_perc_excluding_failures = non_nan(total_diff / success.len() as f32) * 100.; let (mut fontc_failed, mut fontmake_failed, mut both_failed, mut other_failure) = (0, 0, 0, 0); for fail in failure.values() { @@ -146,6 +147,15 @@ fn assert_has_timeout_coreutil() { std::process::exit(1); } +// replace nan with 0 +fn non_nan(val: f32) -> f32 { + if val.is_nan() { + 0.0 + } else { + val + } +} + /// make sure we can find and execute ttx_diff script pub(super) fn assert_can_run_script() { // first check that we can find timeout(1) (not present on macOS by default,