Skip to content

Commit dbcb656

Browse files
Add options= to test() (#5996)
* Add options= to test() document in Rd * Add options= to test() document in Rd * missed staged chunk
1 parent 40afa84 commit dbcb656

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

R/test.data.table.R

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,11 @@ gc_mem = function() {
249249
# nocov end
250250
}
251251

252-
test = function(num,x,y=TRUE,error=NULL,warning=NULL,message=NULL,output=NULL,notOutput=NULL,ignore.warning=NULL) {
252+
test = function(num,x,y=TRUE,error=NULL,warning=NULL,message=NULL,output=NULL,notOutput=NULL,ignore.warning=NULL,options=NULL) {
253+
if (!is.null(options)) {
254+
old_options <- do.call('options', as.list(options)) # as.list(): allow passing named character vector for convenience
255+
on.exit(options(old_options), add=TRUE)
256+
}
253257
# Usage:
254258
# i) tests that x equals y when both x and y are supplied, the most common usage
255259
# ii) tests that x is TRUE when y isn't supplied
@@ -280,7 +284,7 @@ test = function(num,x,y=TRUE,error=NULL,warning=NULL,message=NULL,output=NULL,no
280284
foreign = get("foreign", parent.frame())
281285
showProgress = get("showProgress", parent.frame())
282286
time = nTest = RSS = NULL # to avoid 'no visible binding' note
283-
if (num>0) on.exit( {
287+
if (num>0) on.exit( add=TRUE, {
284288
took = proc.time()[3L]-lasttime # so that prep time between tests is attributed to the following test
285289
timings[as.integer(num), `:=`(time=time+took, nTest=nTest+1L), verbose=FALSE]
286290
if (memtest) {

man/test.Rd

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@
77
\usage{
88
test(num, x, y = TRUE,
99
error = NULL, warning = NULL, message = NULL,
10-
output = NULL, notOutput = NULL, ignore.warning = NULL)
10+
output = NULL, notOutput = NULL, ignore.warning = NULL,
11+
options = NULL)
1112
}
1213
\arguments{
1314
\item{num}{ A unique identifier for a test, helpful in identifying the source of failure when testing is not working. Currently, we use a manually-incremented system with tests formatted as \code{n.m}, where essentially \code{n} indexes an issue and \code{m} indexes aspects of that issue. For the most part, your new PR should only have one value of \code{n} (scroll to the end of \code{inst/tests/tests.Rraw} to see the next available ID) and then index the tests within your PR by increasing \code{m}. Note -- \code{n.m} is interpreted as a number, so \code{123.4} and \code{123.40} are actually the same -- please \code{0}-pad as appropriate. Test identifiers are checked to be in increasing order at runtime to prevent duplicates being possible. }
@@ -19,6 +20,7 @@ test(num, x, y = TRUE,
1920
\item{output}{ If you are testing the printing/console output behaviour; e.g. with \code{verbose=TRUE} or \code{options(datatable.verbose=TRUE)}. Again, regex-compatible and case sensitive. }
2021
\item{notOutput}{ Or if you are testing that a feature does \emph{not} print particular console output. Case insensitive (unlike output) so that the test does not incorrectly pass just because the string is not found due to case. }
2122
\item{ignore.warning}{ A single character string. Any warnings emitted by \code{x} that contain this string are dropped. Remaining warnings are compared to the expected \code{warning} as normal. }
23+
\item{options}{ A named list of options to set for the duration of the test. Any code evaluated during this call to `test()` (usually, `x`, or maybe `y`) will run with the named options set, and the original options will be restored on return. This is a named list since different options can have different types in general, but in typical usage, only one option is set at a time, in which case a named vector is also accepted. }
2224
}
2325
\note{
2426
\code{NA_real_} and \code{NaN} are treated as equal, use \code{identical} if distinction is needed. See examples below.

0 commit comments

Comments
 (0)