Skip to content

Commit dc69b3d

Browse files
context= parameter to test() (#7201)
* initial sweep + implementation * doc in ?test * progress in num+x tests * more progress * done * done mergelist * typos * nocov * finish merge * revert bad merge * missed one ignore.warning= * missed '.'-prefix
1 parent 2c94b8c commit dc69b3d

File tree

5 files changed

+244
-219
lines changed

5 files changed

+244
-219
lines changed

R/test.data.table.R

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -370,7 +370,10 @@ gc_mem = function() {
370370
# nocov end
371371
}
372372

373-
test = function(num,x,y=TRUE,error=NULL,warning=NULL,message=NULL,output=NULL,notOutput=NULL,ignore.warning=NULL,options=NULL,env=NULL) {
373+
test = function(num, x, y=TRUE,
374+
error=NULL, warning=NULL, message=NULL, output=NULL, notOutput=NULL, ignore.warning=NULL,
375+
options=NULL, env=NULL,
376+
context=NULL) {
374377
if (!is.null(env)) {
375378
old = Sys.getenv(names(env), names=TRUE, unset=NA)
376379
to_unset = !lengths(env)
@@ -627,6 +630,9 @@ test = function(num,x,y=TRUE,error=NULL,warning=NULL,message=NULL,output=NULL,no
627630
}
628631
# nocov end
629632
}
633+
if (fail && !is.null(context)) {
634+
catf("Test context: %s\n", context) # nocov
635+
}
630636
if (fail && .test.data.table && num>0.0) {
631637
# nocov start
632638
assign("nfail", nfail+1L, parent.frame(), inherits=TRUE)

inst/tests/frollBatch.Rraw

Lines changed: 24 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -64,21 +64,17 @@ base_compare = function(x, n, funs=c("mean","sum","max","min","prod","median","v
6464
}
6565
for (algo in algos) {
6666
num <<- num + num.step
67-
eval(substitute( # so we can have values displayed in output/log rather than variables
68-
test(.num, ignore.warning="no non-missing arguments",
69-
rollfun(x, n, FUN=.fun, fill=.fill, na.rm=.na.rm, partial=.partial),
70-
froll(.fun, x, n, fill=.fill, na.rm=.na.rm, algo=.algo, partial=.partial, has.nf=.has.nf)),
71-
list(.num=num, .fun=fun, .fill=fill, .na.rm=na.rm, .algo=algo, .partial=partial, .has.nf=has.nf)
72-
))
67+
test(num, ignore.warning="no non-missing arguments",
68+
rollfun(x, n, FUN=fun, fill=fill, na.rm=na.rm, partial=partial),
69+
froll(fun, x, n, fill=fill, na.rm=na.rm, algo=algo, partial=partial, has.nf=has.nf),
70+
context=sprintf("fun=%s\tna.rm=$s\tfill=%s\tpartial=%s\thas.nf=%s\talgo=%s", fun, na.rm, fill, partial, has.nf, algo))
7371
}
7472
}
7573
num <<- num + num.step
76-
eval(substitute( # so we can have values displayed in output/log rather than variables
77-
test(.num, ignore.warning="no non-missing arguments",
78-
frollapply(x, n, FUN=match.fun(.fun), fill=.fill, na.rm=.na.rm, partial=.partial),
79-
froll(.fun, x, n, fill=.fill, na.rm=.na.rm, partial=.partial)),
80-
list(.num=num, .fun=fun, .fill=fill, .na.rm=na.rm, .partial=partial)
81-
))
74+
test(num, ignore.warning="no non-missing arguments",
75+
frollapply(x, n, FUN=match.fun(fun), fill=fill, na.rm=na.rm, partial=partial),
76+
froll(fun, x, n, fill=fill, na.rm=na.rm, partial=partial),
77+
context=sprintf("fun=%s\tna.rm=$s\tfill=%s\tpartial=%s", fun, na.rm, fill, partial))
8278
}
8379
}
8480
}
@@ -152,21 +148,17 @@ if (requireNamespace("zoo", quietly=TRUE)) {
152148
}
153149
for (algo in algos) {
154150
num <<- num + num.step
155-
eval(substitute( # so we can have values displayed in output/log rather than variables
156-
test(.num, ignore.warning="no non-missing arguments",
157-
drollapply(x, n, FUN=.fun, fill=.fill, align=.align, na.rm=.na.rm, partial=.partial),
158-
froll(.fun, x, n, align=.align, fill=.fill, na.rm=.na.rm, algo=.algo, partial=.partial, has.nf=.has.nf)),
159-
list(.num=num, .fun=fun, .align=align, .fill=fill, .na.rm=na.rm, .algo=algo, .partial=partial, .has.nf=has.nf)
160-
))
151+
test(num, ignore.warning="no non-missing arguments",
152+
drollapply(x, n, FUN=fun, fill=fill, align=align, na.rm=na.rm, partial=partial),
153+
froll(fun, x, n, align=align, fill=fill, na.rm=na.rm, algo=algo, partial=partial, has.nf=has.nf),
154+
context=sprintf("fun=%s\talign=%s\tna.rm=$s\tfill=%s\tpartial=%s\thas.nf=%s\talgo=%s", fun, align, na.rm, fill, partial, has.nf, algo))
161155
}
162156
}
163157
num <<- num + num.step
164-
eval(substitute( # so we can have values displayed in output/log rather than variables
165-
test(.num, ignore.warning="no non-missing arguments",
166-
frollapply(x, n, FUN=.fun, fill=.fill, align=.align, na.rm=.na.rm, partial=.partial),
167-
froll(.fun, x, n, align=.align, fill=.fill, na.rm=.na.rm, partial=.partial)),
168-
list(.num=num, .fun=fun, .align=align, .fill=fill, .na.rm=na.rm, .partial=partial)
169-
))
158+
test(num, ignore.warning="no non-missing arguments",
159+
frollapply(x, n, FUN=fun, fill=fill, align=align, na.rm=na.rm, partial=partial),
160+
froll(fun, x, n, align=align, fill=fill, na.rm=na.rm, partial=partial),
161+
context=sprintf("fun=%s\talign=%s\tna.rm=$s\tfill=%s\tpartial=%s", fun, align, na.rm, fill, partial))
170162
}
171163
}
172164
}
@@ -250,24 +242,18 @@ afun_compare = function(x, n, funs=c("mean","sum","max","min","prod","median","v
250242
}
251243
for (algo in algos) {
252244
num <<- num + num.step
253-
eval(substitute(
254-
test(.num,
255-
ignore.warning = "no non-missing arguments",
256-
arollfun(.fun, x, n, fill = .fill, na.rm = .na.rm, align = .align, partial=.partial),
257-
froll(.fun, x, n, fill=.fill, na.rm=.na.rm, algo=.algo, adaptive=TRUE, align=.align, has.nf=.has.nf, partial=.partial)
258-
),
259-
list(.num = num, .fun = fun, .fill = fill, .na.rm = na.rm, .algo = algo, .align = align, .partial=partial, .has.nf = has.nf)
260-
))
245+
test(num, ignore.warning = "no non-missing arguments",
246+
arollfun(fun, x, n, fill=fill, na.rm=na.rm, align=align, partial=partial),
247+
froll(fun, x, n, fill=fill, na.rm=na.rm, algo=algo, adaptive=TRUE, align=align, has.nf=has.nf, partial=partial),
248+
context=sprintf("fun=%s\talign=%s\tna.rm=$s\tfill=%s\tpartial=%s\thas.nf=%s\talgo=%s", fun, align, na.rm, fill, partial, has.nf, algo))
261249
}
262250
}
263251
}
264252
num <<- num + num.step
265-
eval(substitute(
266-
test(.num, ignore.warning="no non-missing arguments",
267-
frollapply(x, n, FUN=match.fun(.fun), fill=.fill, na.rm=.na.rm, adaptive=TRUE, align=.align),
268-
froll(.fun, x, n, fill=.fill, na.rm=.na.rm, adaptive=TRUE, align=.align)),
269-
list(.num=num, .fun=fun, .fill=fill, .na.rm=na.rm, .align=align)
270-
))
253+
test(num, ignore.warning="no non-missing arguments",
254+
frollapply(x, n, FUN=match.fun(fun), fill=fill, na.rm=na.rm, adaptive=TRUE, align=align),
255+
froll(fun, x, n, fill=fill, na.rm=na.rm, adaptive=TRUE, align=align),
256+
context=sprintf("fun=%s\talign=%s\tna.rm=$s\tfill=%s", fun, align, na.rm, fill))
271257
}
272258
}
273259
}

0 commit comments

Comments
 (0)