From d773ee30b3168132dc95403608609c3726d73d63 Mon Sep 17 00:00:00 2001 From: Szymon Maksymiuk <32574056+maksymiuks@users.noreply.github.com> Date: Tue, 11 Nov 2025 19:03:01 +0100 Subject: [PATCH 1/2] Fix rare count_test edge case (#2) * Fix rare count_test edge case * fix name typo --- DESCRIPTION | 2 +- NEWS.md | 3 +++ R/trace_tests.R | 3 +++ 3 files changed, 7 insertions(+), 1 deletion(-) diff --git a/DESCRIPTION b/DESCRIPTION index afe3e1c6..8767bb27 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,7 +1,7 @@ Encoding: UTF-8 Package: covr Title: Test Coverage for Packages -Version: 3.6.4.9004 +Version: 3.6.4.9005 Authors@R: c( person("Jim", "Hester", email = "james.f.hester@gmail.com", role = c("aut", "cre")), person("Willem", "Ligtenberg", role = "ctb"), diff --git a/NEWS.md b/NEWS.md index afb8a4cc..447a9b6d 100644 --- a/NEWS.md +++ b/NEWS.md @@ -8,6 +8,9 @@ * Fix R CMD check NOTE for upcoming R 4.6: non-API calls to SET_BODY, SET_CLOENV, SET_FORMALS (@t-kalinowski, #587) +* Fix a rare edge case where `count_test` was called before `.current_test` has + been initialized leading to crash. (@maksymiuks) + ## Fixes and minor improvements * Messages are now displayed using cli instead of crayon (@olivroy, #591). diff --git a/R/trace_tests.R b/R/trace_tests.R index cf9f4af0..4ede0750 100644 --- a/R/trace_tests.R +++ b/R/trace_tests.R @@ -114,6 +114,9 @@ count_test <- function(key) { tests$tally <- rbind(tests$tally, matrix(NA_integer_, ncol = 4L, nrow = n)) } + # ignore if .current_test was not initialized properly yet + if (length(.current_test$index) == 0) return() + # test number tests$.data[[1L]] <- .current_test$index From 13855cac14adcae448299c15a5a7a936bff453b3 Mon Sep 17 00:00:00 2001 From: Szymon Maksymiuk <32574056+maksymiuks@users.noreply.github.com> Date: Tue, 11 Nov 2025 19:43:58 +0100 Subject: [PATCH 2/2] Update R/trace_tests.R Co-authored-by: Jim Hester --- R/trace_tests.R | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/R/trace_tests.R b/R/trace_tests.R index 4ede0750..dcf46fbd 100644 --- a/R/trace_tests.R +++ b/R/trace_tests.R @@ -115,7 +115,9 @@ count_test <- function(key) { } # ignore if .current_test was not initialized properly yet - if (length(.current_test$index) == 0) return() + if (length(.current_test$index) == 0) { + return() + } # test number tests$.data[[1L]] <- .current_test$index