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

using vector `class` argument in `expect_is` causes errors in `test_dir` #293

Closed
goldingn opened this Issue Sep 9, 2015 · 1 comment

Comments

Projects
None yet
2 participants
@goldingn

goldingn commented Sep 9, 2015

TL;DR: When calling test_dir on a test containing an expect_is call with character vector class argument, two errors are reported, causing an error in a vapply call before ever reporting the failures.

expect_is mangles the error message slightly when the class argument is a vector:

x <- NA
class(x) <- c('a')
expect_is(x, c('b', 'c'))

Error: x inherits from a not bx inherits from a not c

which isn't so bad, but when used in test_dir (and quite possibly others) it leads to the following cryptic error:

dir <- tempdir()
write("test_that('blah',{
         x <- NA
         class(x) <- c('a')
         expect_is(x, c('b', 'c'))
       })",
      file = paste0(dir, '/test-demo.R'))
test_dir(dir)

Error in vapply(seq_len(n), function(i) { : values must be length 1, but FUN(X[[1]]) result is length 2

The error is thrown by the following line in test_dir:

current_reporter$end_reporter()

because failure_summary returns a vector of length two mangling the vapply call

[1] "1. Failure (at test-demo.R#4): blah -----------------------------------------\nx inherits from a not b"
[2] "1. Failure (at test-demo.R#4): blah -----------------------------------------\nx inherits from a not c"

Hope this is helpful!

@goldingn goldingn changed the title from test_dir errors out with vector class in expect_is to using vector `class` argument in `expect_is` causes errors in `test_dir` Sep 9, 2015

@hadley hadley modified the milestone: 0.11.0 Sep 29, 2015

@hadley hadley closed this in d6f892b Sep 29, 2015

@goldingn

This comment has been minimized.

goldingn commented Sep 29, 2015

👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment