diff --git a/R/test.data.table.R b/R/test.data.table.R index 0d19a7cf1..1c212f58b 100644 --- a/R/test.data.table.R +++ b/R/test.data.table.R @@ -1,6 +1,8 @@ test.data.table = function(script="tests.Rraw", verbose=FALSE, pkg=".", silent=FALSE, showProgress=interactive()&&!silent, - memtest=as.logical(Sys.getenv("TEST_DATA_TABLE_MEMTEST", "FALSE"))) { + memtest=Sys.getenv("TEST_DATA_TABLE_MEMTEST", 0)) { stopifnot(isTRUEorFALSE(verbose), isTRUEorFALSE(silent), isTRUEorFALSE(showProgress)) + memtest = as.integer(memtest) + stopifnot(length(memtest)==1L, memtest %in% 0:2) if (exists("test.data.table", .GlobalEnv, inherits=FALSE)) { # package developer # nocov start @@ -124,7 +126,7 @@ test.data.table = function(script="tests.Rraw", verbose=FALSE, pkg=".", silent=F on.exit(setwd(owd)) if (memtest) { - catf("\n***\n*** memtest=TRUE. This should be the first task in a fresh R session for best results. Ctrl-C now if not.\n***\n\n") + catf("\n***\n*** memtest=%d. This should be the first task in a fresh R session for best results. Ctrl-C now if not.\n***\n\n", memtest) if (is.na(ps_mem())) stopf("memtest intended for Linux. Step through ps_mem() to see what went wrong.") } @@ -277,8 +279,9 @@ test = function(num,x,y=TRUE,error=NULL,warning=NULL,message=NULL,output=NULL,no took = proc.time()[3L]-lasttime # so that prep time between tests is attributed to the following test timings[as.integer(num), `:=`(time=time+took, nTest=nTest+1L), verbose=FALSE] if (memtest) { - gc() # force gc so we can find tests that use relatively larger amounts of RAM + if (memtest==1L) gc() # see #5515 for before/after timings[as.integer(num), RSS:=max(ps_mem(),RSS), verbose=FALSE] + if (memtest==2L) gc() } assign("lasttime", proc.time()[3L], parent.frame(), inherits=TRUE) # after gc() to exclude gc() time from next test when memtest } ) @@ -293,7 +296,7 @@ test = function(num,x,y=TRUE,error=NULL,warning=NULL,message=NULL,output=NULL,no # not be flushed to the output upon segfault, depending on OS). } else { # not `test.data.table` but developer running tests manually; i.e. `cc(F); test(...)` - memtest = FALSE # nocov + memtest = 0L # nocov filename = NA_character_ # nocov foreign = FALSE # nocov ; assumes users of 'cc(F); test(...)' has LANGUAGE=en showProgress = FALSE # nocov diff --git a/man/test.data.table.Rd b/man/test.data.table.Rd index 90f58593a..2df2a3284 100644 --- a/man/test.data.table.Rd +++ b/man/test.data.table.Rd @@ -8,7 +8,7 @@ test.data.table(script = "tests.Rraw", verbose = FALSE, pkg = ".", silent = FALSE, showProgress = interactive() && !silent, - memtest = as.logical(Sys.getenv("TEST_DATA_TABLE_MEMTEST", "FALSE"))) + memtest = Sys.getenv("TEST_DATA_TABLE_MEMTEST", 0)) } \arguments{ \item{script}{ Run arbitrary R test script. } @@ -16,7 +16,7 @@ test.data.table(script = "tests.Rraw", verbose = FALSE, pkg = ".", \item{pkg}{ Root directory name under which all package content (ex: DESCRIPTION, src/, R/, inst/ etc..) resides. Used only in \emph{dev-mode}. } \item{silent}{ Controls what happens if a test fails. Like \code{silent} in \code{\link{try}}, \code{TRUE} causes the error message to be suppressed and \code{FALSE} to be returned, otherwise the error is returned. } \item{showProgress}{ Output 'Running test ...\\r' at the start of each test? } -\item{memtest}{ Measure and report memory usage of tests rather than time taken. Intended for and tested on Linux. } +\item{memtest}{ Measure and report memory usage of tests (1:gc before ps, 2:gc after ps) rather than time taken (0) by default. Intended for and tested on Linux. See PR #5515 for more details. } } \details{ Runs a series of tests. These can be used to see features and examples of usage, too. Running test.data.table will tell you the full location of the test file(s) to open.