Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

calling skip() outside of test_that() causes esoteric error #2038

Closed
kevinushey opened this issue Dec 11, 2024 · 1 comment · Fixed by #2039
Closed

calling skip() outside of test_that() causes esoteric error #2038

kevinushey opened this issue Dec 11, 2024 · 1 comment · Fixed by #2039

Comments

@kevinushey
Copy link
Collaborator

Suppose a test file has the contents:

skip("I don't want to run these")
test_that("multiplication works", {
  expect_equal(2 * 2, 4)
})

devtools::test() gives:

Testing example.test
Starting 1 test process| F W  S  OK | Context
⠼ [ FAIL 0 | WARN 0 | SKIP 0 | PASS 0 ] Starting up...                                                                                       
Error in self$snaps[[variant]][[test]] : 
  attempt to select less than one element in get1index

This occurs within here:

reset = function(test, old) {
for (variant in names(self$snaps)) {
cur_test <- self$snaps[[variant]][[test]]
old_test <- old$snaps[[variant]][[test]]
if (length(cur_test) == 0) {
self$snaps[[variant]][[test]] <- old_test
} else if (length(old_test) > length(cur_test)) {
self$snaps[[variant]][[test]] <- c(cur_test, old_test[-seq_along(cur_test)])
}
}
invisible()
},

because test is not set, and so is just an empty character vector. It looks like we are checking for NULL here:

https://github.com/r-lib/testthat/blob/main/R/snapshot-reporter.R#L119-L121

but this change coerces NULL to character(0):

dd39c65

so that change probably needs to be updated to handle any kind zero-length vector.

@hadley
Copy link
Member

hadley commented Dec 12, 2024

Hmmmm, might be better to instead fix the gsub() to only occur if test is a string?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants