From 1d16d0c0820d63217db1c900a925eaacee36226b Mon Sep 17 00:00:00 2001 From: dgkf <18220321+dgkf@users.noreply.github.com> Date: Mon, 11 Sep 2023 13:51:18 -0400 Subject: [PATCH 1/3] adding handling for empty expression `x[i, ]` edge case --- R/helpers_covr.R | 2 ++ tests/testthat/test-helpers_covr.R | 14 ++++++++++++++ 2 files changed, 16 insertions(+) diff --git a/R/helpers_covr.R b/R/helpers_covr.R index a41bcef15..6cc9b4487 100644 --- a/R/helpers_covr.R +++ b/R/helpers_covr.R @@ -54,6 +54,8 @@ h_covr_detrace <- function(expr) { } detrace <- function(x) { + # returns "missing" expression to avoid errors with calls + if (x == bquote()) return(x) x <- h_covr_detrace_call(x) if (is.call(x)) x[-1] <- lapply(x[-1], h_covr_detrace) x diff --git a/tests/testthat/test-helpers_covr.R b/tests/testthat/test-helpers_covr.R index 7d82260f2..934cfd745 100644 --- a/tests/testthat/test-helpers_covr.R +++ b/tests/testthat/test-helpers_covr.R @@ -59,6 +59,20 @@ test_that("h_covr_detrace removes all covr traces", { expr ) + # case when an argument is missing, as in `x[i, ]` + expr <- quote(if (TRUE) { + covr:::count("file.R:1:2:3:4:5:6:7:8") + 1 + 2 + if (TRUE) { + covr:::count("file.R:11:12:13:14:15:16:17:18") + x[i, ] + } + }) + + expect_equal( + withr::with_envvar(c(R_COVR = "true"), h_covr_detrace(expr)), + quote(1 + 2 + x[i, ]) + ) + expr <- quote(function(x) { if (TRUE) { covr:::count("file.R:1:2:3:4:5:6:7:8") From ab84d7c11c1fa02bc8344f1da63372383e59de1f Mon Sep 17 00:00:00 2001 From: dgkf <18220321+dgkf@users.noreply.github.com> Date: Mon, 11 Sep 2023 13:59:47 -0400 Subject: [PATCH 2/3] fixing style? no clue why this expression is linty, but the one two lines down isnt --- R/helpers_covr.R | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/R/helpers_covr.R b/R/helpers_covr.R index 6cc9b4487..f69346b85 100644 --- a/R/helpers_covr.R +++ b/R/helpers_covr.R @@ -55,7 +55,9 @@ h_covr_detrace <- function(expr) { detrace <- function(x) { # returns "missing" expression to avoid errors with calls - if (x == bquote()) return(x) + if (x == bquote()) { + return(x) + } x <- h_covr_detrace_call(x) if (is.call(x)) x[-1] <- lapply(x[-1], h_covr_detrace) x From 578d1abf5ecad929927e9e4428fcb1e63c58c739 Mon Sep 17 00:00:00 2001 From: dgkf <18220321+dgkf@users.noreply.github.com> Date: Mon, 11 Sep 2023 14:13:56 -0400 Subject: [PATCH 3/3] using identical for expression comparisons --- R/helpers_covr.R | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/R/helpers_covr.R b/R/helpers_covr.R index f69346b85..04c7cf50b 100644 --- a/R/helpers_covr.R +++ b/R/helpers_covr.R @@ -55,9 +55,10 @@ h_covr_detrace <- function(expr) { detrace <- function(x) { # returns "missing" expression to avoid errors with calls - if (x == bquote()) { + if (identical(x, bquote())) { return(x) } + x <- h_covr_detrace_call(x) if (is.call(x)) x[-1] <- lapply(x[-1], h_covr_detrace) x