Skip to content

Commit

Permalink
Unload packages loaded in tests (#1542)
Browse files Browse the repository at this point in the history
Prevents issues with looking for dev docs
  • Loading branch information
hadley authored Nov 21, 2023
1 parent 912778b commit cbe7201
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 1 deletion.
3 changes: 3 additions & 0 deletions tests/testthat/test-namespace.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ test_that("end-to-end NAMESPACE generation works", {
path <- local_package_copy(test_path("testNamespace"))

suppressMessages(roxygenise(path))
withr::defer(pkgload::unload("testNamespace"))

ns <- read_lines(file.path(path, "NAMESPACE"))
expect_equal(ns, c(
Expand Down Expand Up @@ -262,6 +263,8 @@ test_that("empty NAMESPACE generates zero-length vector", {
base_path <- test_path("empty")

env <- pkgload::load_all(base_path, quiet = TRUE)$env
withr::defer(pkgload::unload("empty"))

blocks <- parse_package(base_path, env = env)

results <- roclet_process(namespace_roclet(), blocks, env = env, base_path)
Expand Down
2 changes: 2 additions & 0 deletions tests/testthat/test-object-from-call.R
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,15 @@ test_that("finds datasets given by name", {
test_that("can document eager data", {
path <- local_package_copy(test_path('testEagerData'))
suppressMessages(roxygenise(path))
withr::defer(pkgload::unload("testEagerData"))

expect_true(file.exists(file.path(path, "man/a.Rd")))
})

test_that("can document lazy data", {
path <- local_package_copy(test_path('testLazyData'))
suppressMessages(roxygenise(path))
withr::defer(pkgload::unload("testLazyData"))

expect_true(file.exists(file.path(path, "man/a.Rd")))
})
Expand Down
3 changes: 3 additions & 0 deletions tests/testthat/test-rd.R
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ test_that("@details NULL", {

test_that("can generate nonASCII document", {
path <- local_package_copy(test_path('testNonASCII'))
withr::defer(pkgload::unload("testNonASCII"))

expect_snapshot({
roxygenise(path, roclets = "rd")
Expand All @@ -169,6 +170,7 @@ test_that("can generate nonASCII document", {

test_that("unicode escapes are ok", {
path <- local_package_copy(test_path('testUtf8Escape'))
withr::defer(pkgload::unload("testUtf8Escape"))

expect_snapshot({
roxygenise(path, roclets = "rd")
Expand All @@ -187,6 +189,7 @@ test_that("automatically deletes unused files", {
path <- local_package_copy(test_path("empty"))
dir.create(file.path(path, "man"))
suppressMessages(roxygenise(path))
withr::defer(pkgload::unload("empty"))

write_lines(made_by("%"), file.path(path, "man/test.Rd"))
expect_snapshot(roxygenise(path))
Expand Down
2 changes: 1 addition & 1 deletion tests/testthat/testLazyData/DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Package: testEagerData
Package: testLazyData
Title: Tools to make developing R code easier
License: GPL-2
Description:
Expand Down

0 comments on commit cbe7201

Please sign in to comment.