expect_equal_to_reference {tinytest} | R Documentation |
Compare object with object stored in a file
Description
Compares the current value with a value stored to file with
saveRDS
. If the file does not exist, the current value is
stored into file, and the test returns expect_null(NULL)
.
Usage
expect_equal_to_reference(current, file, ...)
expect_equivalent_to_reference(current, file, ...)
Arguments
current |
|
file |
|
... |
passed to |
Note
Be aware that on CRAN it is not allowed to write data to user space. So make
sure that the file is either stored with your tests, or generated with
tempfile
, or the test is skipped on CRAN, using
at_home
.
build_install_test
clones the package and
builds and tests it in a separate R session in the background. This means
that if you create a file located at tempfile()
during the run, this
file is destroyed when the separate R session is closed.
See Also
Other test-functions:
expect_equal()
,
expect_length()
,
expect_match()
,
ignore()
Examples
filename <- tempfile()
# this gives TRUE: the file does not exist, but is created now.
expect_equal_to_reference(1, file=filename)
# this gives TRUE: the file now exists, and its contents is equal
# to the current value
expect_equal_to_reference(1, file=filename)
# this gives FALSE: the file exists, but is contents is not equal
# to the current value
expect_equal_to_reference(2, file=filename)