Skip to content

Commit

Permalink
chore: update tests after removing config from DESCRIPTION
Browse files Browse the repository at this point in the history
  • Loading branch information
dgkf committed Apr 15, 2024
1 parent 2b311c7 commit 7417fc8
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 10 deletions.
2 changes: 1 addition & 1 deletion inst/pkg.example/DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@ Roxygen: list(markdown = TRUE, packages = "testex")
RoxygenNote: 7.3.1
License: MIT + file LICENSE
Config/testthat/edition: 3
Config/testex/options: list(check = TRUE, version = "0.2.0")
Config/testex/options: list(check = TRUE, version = "0.2.0.9000")
2 changes: 1 addition & 1 deletion inst/pkg.example/man/fn_roxygen_multiple.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions tests/testthat/setup.R
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
pkg_example_dir <- if (length(find.package(packageName(), quiet = TRUE)) > 0) {
system.file("pkg.example", package = packageName())
} else {
file.path(testthat::test_path(), "..", "..", "inst", "pkg.example")
}

as_r_cmd_check <- function(expr, pkg = "pkg") {
withr::with_envvar(
list("_R_CHECK_PACKAGE_NAME_" = pkg),
Expand Down
8 changes: 4 additions & 4 deletions tests/testthat/test-testex.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ test_that("testex code blocks evaluate expectations against target symbol", {
# style = I("standalone") used to avoid converting test style to accommodate
# running testthat suite.

expect_silent({
expect_silent(withr::with_dir(pkg_example_dir, {
..Last.value <- 3
testex(style = I("standalone"), identical(., 3), value = ..Last.value)
})
}))

expect_error({
expect_error(withr::with_dir(pkg_example_dir, {
..Last.value <- 3
testex(style = I("standalone"), identical(., 4), value = ..Last.value)
})
}))
})
8 changes: 4 additions & 4 deletions tests/testthat/test-testthat.R
Original file line number Diff line number Diff line change
Expand Up @@ -44,24 +44,24 @@ test_that("expect_no_error reports when testthat errors occurs while evaluating
})

test_that("testthat_block returns last value from previous expression", {
expect_silent({
expect_silent(withr::with_dir(pkg_example_dir, {
..Last.value <- 3
out <- testex(style = "testthat", expect_equal(., 3), value = ..Last.value)
})
}))

expect_equal(out, 3)
})

test_that("testthat_block skips if example throws error", {
expect_silent({
expect_silent(withr::with_dir(pkg_example_dir, {
cond <- tryCatch(
{
..Last.value <- errorCondition("whoops!")
testex(style = "testthat", expect_equal(., 3), value = ..Last.value)
},
condition = identity
)
})
}))

expect_s3_class(cond, "skip")
})

0 comments on commit 7417fc8

Please sign in to comment.