Skip to content

use_testthat(3) #176

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

Merged
merged 4 commits into from
Sep 8, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ Suggests:
methods,
rmarkdown,
RSQLite,
testthat (>= 2.1.0)
testthat (>= 3.0.0)
VignetteBuilder:
knitr
Encoding: UTF-8
Expand Down Expand Up @@ -86,3 +86,4 @@ Collate:
'torture.R'
'utils.R'
'with.R'
Config/testthat/edition: 3
4 changes: 2 additions & 2 deletions R/db.R
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
#' unlink(db)
#' @export
with_db_connection <- function(con, code) {
requireNamespace("DBI")
requireNamespace("DBI", quietly = TRUE)

stopifnot(all(is.named(con)))
stopifnot(all(vlapply(con, methods::is, "DBIConnection")))
Expand All @@ -42,7 +42,7 @@ with_db_connection <- function(con, code) {
#' @rdname with_db_connection
#' @export
local_db_connection <- function(con, .local_envir = parent.frame()) {
requireNamespace("DBI")
requireNamespace("DBI", quietly = TRUE)
stopifnot(methods::is(con, "DBIConnection"))

defer(DBI::dbDisconnect(con), envir = .local_envir)
Expand Down
9 changes: 9 additions & 0 deletions tests/testthat/_snaps/defer.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# defer()'s global env facilities work

Code
defer(print("howdy"), envir = globalenv())
Message <simpleMessage>
Setting deferred event(s) on global environment.
* Execute (and clear) with `withr::deferred_run()`.
* Clear (without executing) with `withr::deferred_clear()`.

2 changes: 0 additions & 2 deletions tests/testthat/test-connection.R
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
context("connection")

describe("with_connection", {
it("errors if connection is not named", {
expect_error({
Expand Down
2 changes: 0 additions & 2 deletions tests/testthat/test-db.R
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
context("db")

describe("with_db_connection", {
#it("errors if connection is not named", {
#expect_error({
Expand Down
9 changes: 2 additions & 7 deletions tests/testthat/test-defer.R
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
context("defer")

test_that("defer_parent works", {
local_file <- function(path) {
file.create(path)
Expand All @@ -23,10 +21,7 @@ test_that("defer()'s global env facilities work", {
expect_null(get_handlers(globalenv()))
Sys.setenv(abcdefg = "abcdefg")

expect_message(
defer(print("howdy"), envir = globalenv()),
"Setting deferred event"
)
expect_snapshot(defer(print("howdy"), envir = globalenv()))
expect_message(
local_envvar(c(abcdefg = "tuvwxyz"), .local_envir = globalenv()),
NA
Expand All @@ -39,7 +34,7 @@ test_that("defer()'s global env facilities work", {
expect_output(deferred_run(globalenv()), "howdy")
expect_equal(Sys.getenv("abcdefg"), "abcdefg")

defer(print("never going to happen"), envir = globalenv())
expect_message(defer(print("never going to happen"), envir = globalenv()))
deferred_clear(globalenv())

h <- get_handlers(globalenv())
Expand Down
2 changes: 0 additions & 2 deletions tests/testthat/test-devices.R
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
context("devices")

needs_cairo <- function(fn) fn %in% c("with_cairo_pdf", "with_cairo_ps", "with_svg", "local_cairo_pdf", "local_cairo_ps", "local_svg")
skip_if_needs_cairo <- function(fn) {
if (!capabilities("cairo") && needs_cairo(fn)) {
Expand Down
2 changes: 0 additions & 2 deletions tests/testthat/test-file.R
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
context("file")

describe("with_file", {
it("can use unnamed arguments", {
with_file("file1", {
Expand Down
2 changes: 0 additions & 2 deletions tests/testthat/test-local.R
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
context("local")

test_that("local_options works", {
expect_false(getOption("scipen") == 999)
local({
Expand Down
2 changes: 0 additions & 2 deletions tests/testthat/test-namespace.R
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
context("namespace")

test_that("with_package works", {

# tools package not attached to the search path
Expand Down
2 changes: 0 additions & 2 deletions tests/testthat/test-rng.R
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
context("rng")

describe("with_rng_version", {
it("changes the RNG", {
cur <- RNGkind()
Expand Down
2 changes: 0 additions & 2 deletions tests/testthat/test-sink.R
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
context("With sink")

test_that("with_output_sink works as expected", {
tmp <- tempfile()
on.exit(unlink(tmp), add = TRUE)
Expand Down
2 changes: 0 additions & 2 deletions tests/testthat/test-tempdir.R
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
context("tempdir")

test_that("clean needs to be a single logical", {
expect_error(with_tempdir(clean = "sparkling"), "TRUE or FALSE")
expect_error(with_tempdir(clean = c(TRUE, FALSE)), "TRUE or FALSE")
Expand Down
2 changes: 0 additions & 2 deletions tests/testthat/test-tempfile.R
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
context("tempfile")

test_that("with_tempfile works", {

f1 <- character()
Expand Down
2 changes: 0 additions & 2 deletions tests/testthat/test-timezone.R
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
context("timezone")

describe("with_timezone", {
it("changes the time zone", {
expect_equal(with_timezone("CET", Sys.timezone()), "CET")
Expand Down
2 changes: 0 additions & 2 deletions tests/testthat/test-with.R
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
context("With")

test_that("with_options works", {
expect_false(identical(getOption("scipen"), 999))
expect_equal(with_options(c(scipen=999), getOption("scipen")), 999)
Expand Down
3 changes: 0 additions & 3 deletions tests/testthat/test-wrap.R
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
context("wrap")


test_that("wrap works", {
v <- c(0, 0, 0)
set <- function(x) v[2] <<- x
Expand Down