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" throws error due to : #1678

Open
kjytay opened this issue Sep 12, 2022 · 1 comment
Open

expect_snapshot_value() with style = "deparse" throws error due to : #1678

kjytay opened this issue Sep 12, 2022 · 1 comment
Labels
bug an unexpected problem or unintended behavior snapshot 📷

Comments

@kjytay
Copy link
Contributor

kjytay commented Sep 12, 2022

reprex:

f <- function() {
  3:5
}

test_that("test", {
  expect_snapshot_value(f(), style = "deparse")
})

Saved the above in a test file in a package. Running the test with testthat::test_file() throws the following error:

── Error (test-temp.R:6:3): test ───────────────────────────────────────────────
Error in `3:5`: could not find function ":"
Backtrace:
  1. testthat::expect_snapshot_value(f(), style = "deparse")
       at test-temp.R:6:2
  2. testthat:::expect_snapshot_helper(...)
  3. snapshotter$take_snapshot(...)
  9. testthat (local) load(value_enc)
 10. testthat:::reparse(x)
 11. base::eval(parse(text = x), env)
 12. base::eval(parse(text = x), env)

[ FAIL 1 | WARN 0 | SKIP 0 | PASS 0 ]

This error seems similar in spirit to #1342 and #1294.

Session info:

R version 4.2.0 (2022-04-22)
Platform: x86_64-apple-darwin17.0 (64-bit)
Running under: macOS Monterey 12.5.1

Matrix products: default
LAPACK: /Library/Frameworks/R.framework/Versions/4.2/Resources/lib/libRlapack.dylib

locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] testthat_3.1.4

loaded via a namespace (and not attached):
 [1] compiler_4.2.0  magrittr_2.0.3  R6_2.5.1        rprojroot_2.0.3 cli_3.3.0       tools_4.2.0     withr_2.5.0     glue_1.6.2     
 [9] rstudioapi_0.13 waldo_0.4.0     crayon_1.5.1    desc_1.4.1      pkgload_1.3.0   brio_1.1.3      rlang_1.0.4    
@hadley hadley added bug an unexpected problem or unintended behavior snapshot 📷 labels Sep 19, 2022
@pdbailey0
Copy link

This is important because it means that testthat can't expect_snapshot_value on style="deparse" when the value is a matrix that is nearly square.

expect_snapshot_value(matrix(0, nrow=4,ncol=5), style="deparse")
# Error in 4:5 : could not find function ":"

This comes up when an object has a matrix in it as well as another object in it that other styles cannot handle.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug an unexpected problem or unintended behavior snapshot 📷
Projects
None yet
Development

No branches or pull requests

3 participants