-
Notifications
You must be signed in to change notification settings - Fork 339
Description
@update2
I suspect that at this stage when using test_dir you always need to use test_that, not single expect_that calls. The problem is that single test_that calls do not have a 'tests' object, which, according to the example below, returns NULL when trying to extract it and causes the error in str_c
Paul
@update1
I just found out that when I use the setup:
test_that("It is not equal", expect_that(1, equals(2))))
That the function runs fine. The following code fails when using test_dir:
expect_that(1, equals(2)))
regards,
Paul
@FIRST message
Hi Hadley,
I've looking into unit testing and found your package. However, I ran
into some issues. I had the following testfile:
context("context 1")
expect_that(1, equals(2))
expect_that(5, equals(2))
context("context2")
expect_that(3, equals(1))
located in the subdirectory "tests". When running:
test_dir("tests")
I got the error:
test_dir("tests")
context 1 : 12
context2 : 3Error: Input to str_c should be atomic vectors
traceback()
5: stop("Input to str_c should be atomic vectors", call. = FALSE)
4: str_c(label, ". ", type, ": ", tests, " ")
3: reporter$end_reporter()
2: with_reporter(reporter, {
source_dir(path, "^test.*.[rR]$", env = env)
})
1: test_dir("tests")
I traced the problem down to the summary reporter (reporter-summary.r).
In line 65:
tests <- sapply(self$failures, "[[", "test")
the function tries to extract the "test" attribute from self$failures.
The problem is that there is no "test" attribute and returns NULL and
the line after that fails with the above mentioned error:
header <- str_c(label, ". ", type, ": ", tests, " \n")
In other reporters, failure$test is assigned the value 'desc' (e.g. in
self$start_test of reporter-stop.r), we could this in self$start_context
for reporter-summary. But I'm not really sure what the best solution is
right here. Would it be possible to fix this?
regards,
Paul
sessionInfo()
R version 2.12.0 (2010-10-15)
Platform: i686-pc-linux-gnu (32-bit)
locale:
[1] LC_CTYPE=en_US.UTF-8 LC_NUMERIC=C
[3] LC_TIME=en_US.UTF-8 LC_COLLATE=en_US.UTF-8
[5] LC_MONETARY=C LC_MESSAGES=en_US.UTF-8
[7] LC_PAPER=en_US.UTF-8 LC_NAME=C
[9] LC_ADDRESS=C LC_TELEPHONE=C
[11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] testthat_0.3
loaded via a namespace (and not attached):
[1] evaluate_0.3 mutatr_0.1.2 plyr_1.2.1 stringr_0.4 tools_2.12.0