Skip to content

Commit b4ae3ef

Browse files
Use options= in test() for rarely-touched scripts (#6015)
* Add options= to test(), convert most Rraw scripts data.table spacing style document in Rd Add options= to test() document in Rd missed staged chunk convert most Rraw scripts to use test(options=) Merge branch 'master' into test-options Merge remote-tracking branch 'origin/test-options' into test-options * trailing ws
1 parent e6937f1 commit b4ae3ef

File tree

3 files changed

+23
-22
lines changed

3 files changed

+23
-22
lines changed

inst/tests/benchmark.Rraw

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -81,15 +81,17 @@ test(655, abs(tt1["user.self"] - tt2["user.self"])<2.0) # unoptimized tt2 takes
8181
# Test for optimisation of 'order' to 'forder'.
8282
set.seed(45L)
8383
DT <- data.table(x=sample(1e2, 1e6,TRUE), y=sample(1e2, 1e6,TRUE))
84-
old = options(datatable.optimize=Inf)
85-
t1 = system.time(ans1 <- DT[order(x,-y)])[['elapsed']] # optimized to forder()
86-
t2 = system.time(ans2 <- DT[base_order(x,-y)])[['elapsed']] # not optimized
87-
test(1241.1, ans1, ans2)
88-
if (.devtesting) test(1241.2, t1 < t2+0.1)
89-
# 0.2 < 3.8 on Matt's laptop seems safe enough to test.
90-
# Even so, 1241.2 has been known to fail, perhaps if system swaps and this R sessions pauses or something?
91-
# We shouldn't have timing tests here that run on CRAN for this reason. Hence wrapping with .devtesting
92-
options(old)
84+
local({
85+
old = options(datatable.optimize=Inf)
86+
on.exit(options(old))
87+
t1 = system.time(ans1 <- DT[order(x,-y)])[['elapsed']] # optimized to forder()
88+
t2 = system.time(ans2 <- DT[base_order(x,-y)])[['elapsed']] # not optimized
89+
test(1241.1, ans1, ans2)
90+
if (.devtesting) test(1241.2, t1 < t2+0.1)
91+
# 0.2 < 3.8 on Matt's laptop seems safe enough to test.
92+
# Even so, 1241.2 has been known to fail, perhaps if system swaps and this R sessions pauses or something?
93+
# We shouldn't have timing tests here that run on CRAN for this reason. Hence wrapping with .devtesting
94+
})
9395

9496

9597
# fwrite showProgress test 1735. Turned off as too long/big for CRAN.

inst/tests/programming.Rraw

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -195,37 +195,38 @@ test(5.10, list2lang(list("a", 1L, c(1L, 2L))), list(as.name("a"), 1L, c(1L,2L))
195195
test(5.11, list2lang(list("a", 1L, call("c", 1L, 2L))), list(as.name("a"), 1L, quote(c(1L, 2L))))
196196

197197
# datatable.enlist
198-
op = options(datatable.enlist=NULL)
199198
test(6.01,
199+
options = c(datatable.enlist=NULL),
200200
substitute2(list(v1 = v2, v3 = v4), list(v1 = "int", v2 = 1L, v3 = "lst", v4 = list("a", "b", list("c", "d")))),
201201
quote(list(int = 1L, lst = list(a, b, list(c, d)))))
202-
options(datatable.enlist=FALSE)
203202
test(6.02,
203+
options = c(datatable.enlist=FALSE),
204204
substitute2(list(v1 = v2, v3 = v4), list(v1 = "int", v2 = 1L, v3 = "lst", v4 = list("a", "b", list("c", "d")))),
205205
substitute(list(int = 1L, lst = lst), list(lst = list("a", "b", list("c", "d")))))
206-
options(datatable.enlist=NULL)
207206
test(6.03,
207+
options = c(datatable.enlist=NULL),
208208
enlist(list(v1 = 1L, v2 = list(v3 = "b", v4 = list(v5 = "c")))),
209209
quote(list(v1 = 1L, v2 = list(v3 = b, v4 = list(v5 = c)))))
210-
options(datatable.enlist=FALSE)
211210
test(6.04,
211+
options = c(datatable.enlist=FALSE),
212212
enlist(list(v1 = 1L, v2 = list(v3 = "b", v4 = list(v5 = "c")))),
213213
substitute(list(v1 = 1L, v2 = lst), list(lst=list(v3 = "b", v4 = list(v5 = "c")))))
214-
options(datatable.enlist=NULL)
215214
test(6.05,
215+
options = c(datatable.enlist=NULL),
216216
substitute2(list(v1, v2, v3), list(v1="V1", v2="V2", v3=enlist(list("V4","V5")))),
217217
quote(list(V1, V2, list(V4, V5))))
218-
options(datatable.enlist=FALSE)
219218
test(6.06,
219+
options = c(datatable.enlist=FALSE),
220220
substitute2(list(v1, v2, v3), list(v1="V1", v2="V2", v3=enlist(list("V4","V5")))),
221221
quote(list(V1, V2, list(V4, V5))))
222222
test(6.07,
223+
options = c(datatable.enlist=FALSE),
223224
substitute2(list(v1, v2, v3), list(v1="V1", v2="V2", v3=enlist(list("V4","V5", list("V6"))))),
224225
substitute(list(V1, V2, list(V4, V5, lst)), list(lst=list("V6"))))
225226
test(6.08,
227+
options = c(datatable.enlist=FALSE),
226228
substitute2(list(v1, v2, v3), list(v1="V1", v2="V2", v3=enlist(list("V4","V5", enlist(list("V6")))))),
227229
quote(list(V1, V2, list(V4, V5, list(V6)))))
228-
options(op)
229230

230231
# documentation examples
231232
test(7.01, substitute2(list(var1 = var2), list(var1 = "c1", var2 = 5L)), quote(list(c1 = 5L))) ## works also on names

inst/tests/types.Rraw

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,10 @@ test(2.05, testMsg(3, 2, 1), error=err)
3030
test(2.06, testMsg(23, 2, 1), warning=wrn[1L], error=err)
3131
##test(2.07, testMsg(123, 2, 1), message=msg[1L], warning=wrn[1L], error=err)
3232
# test all messages
33-
op = options(datatable.verbose=TRUE)
34-
test(3.01, testMsg(0, 2, 1), as.list(rep(0L, 2L)), output=out)
33+
test(3.01, options = c(datatable.verbose=TRUE), testMsg(0, 2, 1), as.list(rep(0L, 2L)), output=out)
3534
##test(3.02, testMsg(1, 2, 1), as.list(rep(1L, 2L)), output=out, message=msg)
36-
test(3.03, testMsg(2, 2, 1), as.list(rep(2L, 2L)), output=out, warning=wrn)
35+
test(3.03, options = c(datatable.verbose=TRUE), testMsg(2, 2, 1), as.list(rep(2L, 2L)), output=out, warning=wrn)
3736
##test(3.04, testMsg(12, 2, 1), as.list(rep(2L, 2L)), output=out, message=msg, warning=wrn)
38-
test(3.05, testMsg(3, 2, 1), output=out[1L], error=err)
39-
test(3.06, testMsg(23, 2, 1), output=out[1L], warning=wrn[1L], error=err)
37+
test(3.05, options = c(datatable.verbose=TRUE), testMsg(3, 2, 1), output=out[1L], error=err)
38+
test(3.06, options = c(datatable.verbose=TRUE), testMsg(23, 2, 1), output=out[1L], warning=wrn[1L], error=err)
4039
##test(3.07, testMsg(123, 2, 1), output=out[1L], message=msg[1L], warning=wrn[1L], error=err)
41-
options(op)

0 commit comments

Comments
 (0)