Skip to content

Commit

Permalink
adding handling for empty expression x[i, ] edge case
Browse files Browse the repository at this point in the history
  • Loading branch information
dgkf committed Sep 11, 2023
1 parent 3d897fc commit 1d16d0c
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
2 changes: 2 additions & 0 deletions R/helpers_covr.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
14 changes: 14 additions & 0 deletions tests/testthat/test-helpers_covr.R
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down

0 comments on commit 1d16d0c

Please sign in to comment.