@@ -205,7 +205,20 @@ test.data.table = function(script="tests.Rraw", verbose=FALSE, pkg=".", silent=F
205205 }
206206 # nocov end
207207
208- err = try(sys.source(fn , envir = env ), silent = silent )
208+ warnings = list ()
209+ err = try(
210+ withCallingHandlers(
211+ sys.source(fn , envir = env ),
212+ warning = function (w ) {
213+ # nocov start
214+ if (! silent && showProgress ) print(w )
215+ warnings <<- c(warnings , list (list (env $ prevtest , toString(w ))))
216+ invokeRestart(" muffleWarning" )
217+ # nocov end
218+ }
219+ ),
220+ silent = silent
221+ )
209222
210223 options(oldOptions )
211224 for (i in oldEnv ) {
@@ -262,6 +275,21 @@ test.data.table = function(script="tests.Rraw", verbose=FALSE, pkg=".", silent=F
262275 # important to stopf() here, so that 'R CMD check' fails
263276 # nocov end
264277 }
278+ if (length(warnings )) {
279+ # nocov start
280+ warnings = rbindlist(warnings )
281+ setnames(warnings , c(" after test" , " warning" ))
282+ catf(
283+ ngettext(length(warnings ),
284+ " Caught %d warning outside the test() calls:\n " ,
285+ " Caught %d warnings outside the test() calls:\n "
286+ ),
287+ length(warnings )
288+ )
289+ print(warnings )
290+ stopf(" Tests succeeded, but non-test code caused warnings. Search %s for tests shown above." , names(fn ))
291+ # nocov end
292+ }
265293
266294 # There aren't any errors, so we can use up 11 lines for the timings table
267295 time = nTest = RSS = NULL # to avoid 'no visible binding' note
0 commit comments