Skip to content

Commit

Permalink
fixing tests
Browse files Browse the repository at this point in the history
  • Loading branch information
dgkf committed Apr 14, 2024
1 parent 0449029 commit 0f2ca2e
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 10 deletions.
2 changes: 1 addition & 1 deletion R/opts.R
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ testex_options <- function(path = package_desc(), ...) {
)))
}

if (file.exists(path)) {
if (!is.null(path) && file.exists(path)) {
fingerprint <- list(
desc = TRUE,
path = path,
Expand Down
2 changes: 1 addition & 1 deletion R/testex.R
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ testex_testthat <- function(exprs, srcref, value) {
}

testex_standalone <- function(exprs, srcref, value) {
bquote({
expr <- bquote({
. <- .(value)
.(as.call(append(list(as.name("stopifnot")), exprs)))
invisible(.)
Expand Down
16 changes: 10 additions & 6 deletions tests/testthat/test-options.R
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
test_that("update_testex_desc reads and caches options set in Config/testex/options", {
test_that(paste0(
"update_testex_desc reads and caches options set in Config/testex/options",
"warning when version is mismatched and disabling checks"
), {
desc <- "
Package: example
Config/testex/options: list(a = 1)
Expand All @@ -9,15 +12,16 @@ Config/testex/options: list(a = 1)
withr::defer(unlink(test_dir, recursive = TRUE))

writeLines(trimws(desc), desc_path)
expect_silent(testex_options(desc_path))
expect_warning(testex_options(desc_path), "version")
expect_silent(orig <- testex_options(""))
expect_length(orig, 1)
expect_length(orig, 2)
expect_identical(orig$a, 1)
expect_identical(orig$check, FALSE)
orig_mtime <- .testex_options$.fingerprint$mtime

# during R CMD check, process ID is used for fingerprint instead of mtime
skip_if(is_r_cmd_check(), "on R CMD check")
Sys.sleep(1) # give time for mtime to update
Sys.sleep(1) # give time for mtime to update

# without updating file, cache fingerprint unchanged
expect_silent(testex_options(desc_path))
Expand All @@ -30,10 +34,10 @@ Config/testex/options: list(a = 1, b = 2)

# expect invalidation of cached value and new values stored
writeLines(trimws(desc), desc_path)
expect_silent(testex_options(desc_path))
expect_warning(testex_options(desc_path))
expect_silent(updated <- testex_options(""))
expect_true(.testex_options$.fingerprint$mtime != orig_mtime)
expect_length(updated, 2)
expect_length(updated, 3)
expect_identical(updated$a, 1)
expect_identical(updated$b, 2)
})
4 changes: 2 additions & 2 deletions tests/testthat/test-testex.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ test_that("testex code blocks evaluate expectations against target symbol", {

expect_silent({
..Last.value <- 3
testex(style = I("standalone"), identical(., 3), value = quote(..Last.value))
testex(style = I("standalone"), identical(., 3), value = ..Last.value)
})

expect_error({
..Last.value <- 3
testex(style = I("standalone"), identical(., 4), value = quote(..Last.value))
testex(style = I("standalone"), identical(., 4), value = ..Last.value)
})
})

0 comments on commit 0f2ca2e

Please sign in to comment.