Skip to content

Commit

Permalink
simplify interface to test.data.table (#3392)
Browse files Browse the repository at this point in the history
  • Loading branch information
jangorecki authored and mattdowle committed Apr 15, 2019
1 parent 7a570bb commit 6f53b27
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 17 deletions.
28 changes: 19 additions & 9 deletions R/test.data.table.R
@@ -1,4 +1,4 @@
test.data.table <- function(verbose=FALSE, pkg="pkg", silent=FALSE, with.other.packages=FALSE, benchmark=FALSE, script=NULL) {
test.data.table <- function(verbose=FALSE, pkg="pkg", silent=FALSE, with.other.packages=FALSE, benchmark=FALSE, script="tests.Rraw") {
if (exists("test.data.table", .GlobalEnv,inherits=FALSE)) {
# package developer
# nocov start
Expand All @@ -12,24 +12,34 @@ test.data.table <- function(verbose=FALSE, pkg="pkg", silent=FALSE, with.other.p
subdir = "tests"
}
fulldir = file.path(rootdir, subdir)

# nocov start
if (isTRUE(benchmark)) {
warning("'benchmark' argument is deprecated, use script='benchmark.Rraw' instead")
script = "benchmark.Rraw"
}
if (isTRUE(with.other.packages)) {
warning("'with.other.packages' argument is deprecated, use script='other.Rraw' instead")
script = "other.Rraw"
}
# nocov end

if (!is.null(script)) {
stopifnot(is.character(script), length(script)==1L, !is.na(script), nzchar(script))
if (!identical(basename(script), script)) {
# nocov start
subdir = dirname(script)
fulldir = normalizePath(subdir, mustWork=FALSE)
fn = basename(script)
# nocov end
} else {
fn = script
}
} else {
stopifnot( !(with.other.packages && benchmark) )
fn = if (with.other.packages) "other.Rraw"
else if (benchmark) "benchmark.Rraw"
else "tests.Rraw"
stop("'script' argument should not be NULL") # nocov
}
fn = setNames(file.path(fulldir, fn), file.path(subdir, fn))
if (!file.exists(fn)) stop(fn," does not exist") # nocov
if (!file.exists(fn)) stop(fn," does not exist") # nocov

# From R 3.6.0 onwards, we can check that && and || are using only length-1 logicals (in the test suite)
# rather than relying on x && y being equivalent to x[[1L]] && y[[1L]] silently.
Expand Down Expand Up @@ -73,7 +83,7 @@ test.data.table <- function(verbose=FALSE, pkg="pkg", silent=FALSE, with.other.p
if (is.na(orig__R_CHECK_LENGTH_1_LOGIC2_)) {
Sys.unsetenv("_R_CHECK_LENGTH_1_LOGIC2_")
} else {
Sys.setenv("_R_CHECK_LENGTH_1_LOGIC2_" = orig__R_CHECK_LENGTH_1_LOGIC2_) # nocov
Sys.setenv("_R_CHECK_LENGTH_1_LOGIC2_" = orig__R_CHECK_LENGTH_1_LOGIC2_) # nocov
}

suppressWarnings(do.call("RNGkind",as.list(oldRNG)))
Expand Down Expand Up @@ -126,15 +136,15 @@ test.data.table <- function(verbose=FALSE, pkg="pkg", silent=FALSE, with.other.p
#}
#if (memtest<-get("memtest", envir=env)) memtest.plot(get("inittime", envir=env))

# nocov start
if (nfail > 0) {
# nocov start
if (nfail>1) {s1="s";s2="s: "} else {s1="";s2=" "}
cat("\r")
stop(nfail," error",s1," out of ",ntest," in ",timetaken(started.at)," on ",date(),". [",plat,"].",
" Search ",names(fn)," for test number",s2,paste(whichfail,collapse=", "),".")
# important to stop() here, so that 'R CMD check' fails
# nocov end
}
# nocov end
cat(plat,"\n\nAll ",ntest," tests in ",names(fn)," completed ok in ",timetaken(started.at)," on ",date(),"\n",sep="")
# date() is included so we can tell exactly when these tests ran on CRAN. Sometimes a CRAN log can show error but that can be just
# stale due to not updating yet since a fix in R-devel, for example.
Expand Down
6 changes: 3 additions & 3 deletions man/test.data.table.Rd
Expand Up @@ -7,14 +7,14 @@
\usage{
test.data.table(verbose=FALSE, pkg="pkg", silent=FALSE,
with.other.packages=FALSE, benchmark=FALSE,
script=NULL)
script="tests.Rraw")
}
\arguments{
\item{verbose}{ If \code{TRUE} sets datatable.verbose to \code{TRUE} for the duration of the tests. }
\item{pkg}{Root directory name under which all package content (ex: DESCRIPTION, src/, R/, inst/ etc..) resides.}
\item{silent}{Logical, default \code{FALSE}, when \code{TRUE} it will not raise error on in case of test fails.}
\item{with.other.packages}{ Run compatibility tests with other packages. }
\item{benchmark}{ Run the benchmark script. }
\item{with.other.packages}{ Deprecated. Run compatibility tests with other packages. Use \code{script='other.Rraw'} instead. }
\item{benchmark}{ Deprecated. Run the benchmark script. Use \code{script='benchmark.Rraw'} instead. }
\item{script}{ Run arbitrary R test script. }
}
\details{
Expand Down
5 changes: 0 additions & 5 deletions tests/main.R
Expand Up @@ -2,11 +2,6 @@ require(data.table)

test.data.table() # runs the main test suite of 5,000+ tests in /inst/tests/tests.Rraw

# integration tests for packages excluded from Suggests in 1.10.5
# for list of used packages see inst/tests/tests-DESCRIPTION
with.other.packages = as.logical(Sys.getenv("TEST_DATA_TABLE_WITH_OTHER_PACKAGES","FALSE"))
if (with.other.packages) test.data.table(with.other.packages=with.other.packages)

# Turn off verbose repeat to save time (particularly Travis, but also CRAN) :
# test.data.table(verbose=TRUE)
# Calling it again in the past revealed some memory bugs but also verbose mode checks the verbose messages run ok
Expand Down
4 changes: 4 additions & 0 deletions tests/other.R
@@ -0,0 +1,4 @@
require(data.table)
# integration tests for packages excluded from Suggests in 1.10.5
# for list of used packages see inst/tests/tests-DESCRIPTION
if (as.logical(Sys.getenv("TEST_DATA_TABLE_WITH_OTHER_PACKAGES","FALSE"))) test.data.table(script="other.Rraw")

0 comments on commit 6f53b27

Please sign in to comment.