Skip to content

Commit

Permalink
Add test on R version to state inspector
Browse files Browse the repository at this point in the history
  • Loading branch information
Bisaloo committed Nov 30, 2023
1 parent e1215d5 commit ca7cbb8
Showing 1 changed file with 21 additions and 17 deletions.
38 changes: 21 additions & 17 deletions tests/testthat/helper-state.R
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,24 @@
# If global settings need to be modified, they should be restored to their
# original values on exit. This can be achieved with the `on.exit()` base
# function, or more conveniently with the `withr` package.
testthat::set_state_inspector(function() {
list(
attached = search(),
connections = getAllConnections(),
cwd = getwd(),
envvars = Sys.getenv(),
handlers = globalCallingHandlers(),
libpaths = .libPaths(),
locale = Sys.getlocale(),
options = options(),
par = par(),
packages = .packages(all.available = TRUE),
sink = sink.number(),
timezone = Sys.timezone(),
NULL
)
})
# We add a test on R >= 4.0.0 because some functions such as
# `globalCallingHandlers()` did not exist before.
if (getRversion() >= "4.0.0") {
testthat::set_state_inspector(function() {
list(
attached = search(),
connections = getAllConnections(),
cwd = getwd(),
envvars = Sys.getenv(),
handlers = globalCallingHandlers(),
libpaths = .libPaths(),
locale = Sys.getlocale(),
options = options(),
par = par(),
packages = .packages(all.available = TRUE),
sink = sink.number(),
timezone = Sys.timezone(),
NULL
)
})
}

0 comments on commit ca7cbb8

Please sign in to comment.