Skip to content

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

@kevinushey

Description

@kevinushey

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions