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

expect_snapshot_value() with style = "deparse" - fail on integer(0) #2042

Open
tentacles-from-outer-space opened this issue Dec 12, 2024 · 0 comments

Comments

@tentacles-from-outer-space

I came across another case where the function does not work:

x <- dplyr::group_by(head(iris, 1), Species)
expect_snapshot_value(x, "deparse")
# Error in integer(0) : could not find function "integer"

Problem could be solved by adding another functions to https://github.com/r-lib/testthat/blob/main/R/snapshot-value.R#L71. But I think it's better to use baseenv() instead of emptyenv():

reparse <- function(x) {
  env <- env(baseenv(),
    new = methods::new,
    getClass = methods::getClass
  )

  eval(parse(text = x), env)
}

This should help with #1678

Side note: there is repeated definition of reparse: https://github.com/r-lib/testthat/blob/main/R/snapshot-value.R#L92

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

No branches or pull requests

1 participant