Skip to content

Commit 467132f

Browse files
committed
cleaner tests/doRUnit.R (as eg in RcppArmadillo and others)
1 parent b7dc5f1 commit 467132f

File tree

2 files changed

+32
-33
lines changed

2 files changed

+32
-33
lines changed

ChangeLog

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
1-
2018-09-18 JJ Allaire <[email protected]>
1+
2018-10-12 Dirk Eddelbuettel <[email protected]>
2+
3+
* tests/doRUnit.R: Simplified to something similar to what
4+
RcppArmadillo (and other packages) had for a while now
5+
6+
2018-10-08 JJ Allaire <[email protected]>
27

38
* R/Attributes.R: Sort the files scanned for attributes in the C locale
49
for stable output across systems.

tests/doRUnit.R

Lines changed: 26 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright (C) 2009 - 2014 Dirk Eddelbuettel and Romain Francois
1+
# Copyright (C) 2009 - 2018 Dirk Eddelbuettel and Romain Francois
22
# Earlier copyrights Gregor Gorjanc, Martin Maechler and Murray Stokely as detailed below
33
#
44
# This file is part of Rcpp.
@@ -28,43 +28,37 @@
2828
##
2929
## Dirk Eddelbuettel, Feb 2014
3030

31-
stopifnot(require(RUnit, quietly=TRUE))
32-
stopifnot(require(Rcpp, quietly=TRUE))
31+
if (requireNamespace("RUnit", quietly=TRUE) &&
32+
requireNamespace("Rcpp", quietly=TRUE)) {
3333

34-
## Set a seed to make the test deterministic
35-
set.seed(42)
34+
library(RUnit)
35+
library(Rcpp)
3636

37-
## Define tests
38-
testSuite <- defineTestSuite(name = "Rcpp Unit Tests",
39-
dirs = system.file("unitTests", package = "Rcpp"),
40-
testFuncRegexp = "^[Tt]est.+")
37+
set.seed(42) # Set a seed to make the test deterministic
4138

42-
## without this, we get (or used to get) unit test failures
43-
Sys.setenv("R_TESTS"="")
39+
## Define tests
40+
testSuite <- defineTestSuite(name = "Rcpp Unit Tests",
41+
dirs = system.file("unitTests", package = "Rcpp"),
42+
testFuncRegexp = "^[Tt]est.+")
4443

45-
## force tests to be executed if in dev release which we define as
46-
## having a sub-release, eg 0.9.15.5 is one whereas 0.9.16 is not
47-
if (length(strsplit(packageDescription("Rcpp")$Version, "\\.")[[1]]) > 3) { # dev release, and
48-
if (Sys.getenv("RunAllRcppTests") != "no") { # if env.var not yet set
49-
message("Setting \"RunAllRcppTests\"=\"yes\" for development release\n")
50-
Sys.setenv("RunAllRcppTests"="yes")
44+
Sys.setenv("R_TESTS"="") # without this, we get (or used to get) unit test failures
45+
46+
## force tests to be executed if in dev release which we define as
47+
## having a sub-release, eg 0.9.15.5 is one whereas 0.9.16 is not
48+
if (length(strsplit(packageDescription("Rcpp")$Version, "\\.")[[1]]) > 3) { # dev release, and
49+
if (Sys.getenv("RunAllRcppTests") != "no") { # if env.var not yet set
50+
message("Setting \"RunAllRcppTests\"=\"yes\" for development release\n")
51+
Sys.setenv("RunAllRcppTests"="yes")
52+
}
5153
}
52-
}
5354

54-
## Run tests
55-
tests <- runTestSuite(testSuite)
55+
tests <- runTestSuite(testSuite) # Run tests
5656

57-
## Print results
58-
printTextProtocol(tests)
57+
printTextProtocol(tests) # Print results
5958

60-
## Return success or failure to R CMD CHECK
61-
if (getErrors(tests)$nFail > 0) {
62-
stop("TEST FAILED!")
63-
}
64-
if (getErrors(tests)$nErr > 0) {
65-
stop("TEST HAD ERRORS!")
59+
## Return success or failure to R CMD CHECK
60+
if (getErrors(tests)$nFail > 0) stop("TEST FAILED!")
61+
if (getErrors(tests)$nErr > 0) stop("TEST HAD ERRORS!")
62+
if (getErrors(tests)$nTestFunc < 1 && Sys.getenv("RunAllRcppTests")=="yes")
63+
stop("NO TEST FUNCTIONS RUN!")
6664
}
67-
if (getErrors(tests)$nTestFunc < 1 && Sys.getenv("RunAllRcppTests")=="yes") {
68-
stop("NO TEST FUNCTIONS RUN!")
69-
}
70-

0 commit comments

Comments
 (0)