From ca7cbb8e14745165160db1826da84a303202cf06 Mon Sep 17 00:00:00 2001 From: Hugo Gruson Date: Wed, 29 Nov 2023 15:59:54 +0100 Subject: [PATCH] Add test on R version to state inspector --- tests/testthat/helper-state.R | 38 +++++++++++++++++++---------------- 1 file changed, 21 insertions(+), 17 deletions(-) diff --git a/tests/testthat/helper-state.R b/tests/testthat/helper-state.R index 515417a..4910faa 100644 --- a/tests/testthat/helper-state.R +++ b/tests/testthat/helper-state.R @@ -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 + ) + }) +}