Skip to content

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

@tentacles-from-outer-space

Description

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugan unexpected problem or unintended behaviorsnapshot πŸ“·

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions