11test.data.table = function (script = " tests.Rraw" , verbose = FALSE , pkg = " ." , silent = FALSE , showProgress = interactive()&&! silent ,
2- memtest = as.logical( Sys.getenv(" TEST_DATA_TABLE_MEMTEST" , " FALSE " ) )) {
2+ memtest = Sys.getenv(" TEST_DATA_TABLE_MEMTEST" , 0 )) {
33 stopifnot(isTRUEorFALSE(verbose ), isTRUEorFALSE(silent ), isTRUEorFALSE(showProgress ))
4+ memtest = as.integer(memtest )
5+ stopifnot(length(memtest )== 1L , memtest %in% 0 : 2 )
46 if (exists(" test.data.table" , .GlobalEnv , inherits = FALSE )) {
57 # package developer
68 # nocov start
@@ -124,7 +126,7 @@ test.data.table = function(script="tests.Rraw", verbose=FALSE, pkg=".", silent=F
124126 on.exit(setwd(owd ))
125127
126128 if (memtest ) {
127- 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 " )
129+ 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 )
128130 if (is.na(ps_mem())) stopf(" memtest intended for Linux. Step through ps_mem() to see what went wrong." )
129131 }
130132
@@ -277,8 +279,9 @@ test = function(num,x,y=TRUE,error=NULL,warning=NULL,message=NULL,output=NULL,no
277279 took = proc.time()[3L ]- lasttime # so that prep time between tests is attributed to the following test
278280 timings [as.integer(num ), `:=`(time = time + took , nTest = nTest + 1L ), verbose = FALSE ]
279281 if (memtest ) {
280- gc() # force gc so we can find tests that use relatively larger amounts of RAM
282+ if ( memtest == 1L ) gc() # see #5515 for before/after
281283 timings [as.integer(num ), RSS : = max(ps_mem(),RSS ), verbose = FALSE ]
284+ if (memtest == 2L ) gc()
282285 }
283286 assign(" lasttime" , proc.time()[3L ], parent.frame(), inherits = TRUE ) # after gc() to exclude gc() time from next test when memtest
284287 } )
@@ -293,7 +296,7 @@ test = function(num,x,y=TRUE,error=NULL,warning=NULL,message=NULL,output=NULL,no
293296 # not be flushed to the output upon segfault, depending on OS).
294297 } else {
295298 # not `test.data.table` but developer running tests manually; i.e. `cc(F); test(...)`
296- memtest = FALSE # nocov
299+ memtest = 0L # nocov
297300 filename = NA_character_ # nocov
298301 foreign = FALSE # nocov ; assumes users of 'cc(F); test(...)' has LANGUAGE=en
299302 showProgress = FALSE # nocov
0 commit comments