File tree Expand file tree Collapse file tree 2 files changed +27
-1
lines changed Expand file tree Collapse file tree 2 files changed +27
-1
lines changed Original file line number Diff line number Diff line change
1
+ # This helper ensures the package does not modify the session global state. As
2
+ # per CRAN policy, packages should not interfere with the user's session state.
3
+ # If global settings need to be modified, they should be restored to their
4
+ # original values on exit. This can be achieved with the `on.exit()` base
5
+ # function, or more conveniently with the `withr` package.
6
+ testthat :: set_state_inspector(function () {
7
+ list (
8
+ attached = search(),
9
+ connections = getAllConnections(),
10
+ cwd = getwd(),
11
+ envvars = Sys.getenv(),
12
+ handlers = globalCallingHandlers(),
13
+ libpaths = .libPaths(),
14
+ locale = Sys.getlocale(),
15
+ options = options(),
16
+ par = par(),
17
+ packages = .packages(all.available = TRUE ),
18
+ sink = sink.number(),
19
+ timezone = Sys.timezone(),
20
+ NULL
21
+ )
22
+ })
Original file line number Diff line number Diff line change 1
1
test_that(" tests for [ operator" , {
2
2
x <- make_linelist(cars , id = " speed" , age = " dist" )
3
-
3
+ on.exit(lost_tags_action())
4
+
4
5
# errors
5
6
lost_tags_action(" warning" , quiet = TRUE )
6
7
msg <- " The following tags have lost their variable:\n age:dist"
@@ -52,6 +53,7 @@ test_that("tests for [ operator", {
52
53
})
53
54
54
55
test_that(" tests for [<- operator" , {
56
+ on.exit(lost_tags_action())
55
57
56
58
# errors
57
59
lost_tags_action(" warning" , quiet = TRUE )
@@ -75,6 +77,7 @@ test_that("tests for [<- operator", {
75
77
})
76
78
77
79
test_that(" tests for [[<- operator" , {
80
+ on.exit(lost_tags_action())
78
81
79
82
# errors
80
83
lost_tags_action(" warning" , quiet = TRUE )
@@ -99,6 +102,7 @@ test_that("tests for [[<- operator", {
99
102
})
100
103
101
104
test_that(" $<- operator detects tag loss" , {
105
+ on.exit(lost_tags_action())
102
106
103
107
# errors
104
108
lost_tags_action(" warning" , quiet = TRUE )
You can’t perform that action at this time.
0 commit comments