Skip to content

Commit a944046

Browse files
committed
the tests/doRUnit.R wrapper was rewritten
1 parent b5ce6e6 commit a944046

File tree

3 files changed

+44
-37
lines changed

3 files changed

+44
-37
lines changed

ChangeLog

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
2014-02-01 Dirk Eddelbuettel <[email protected]>
2+
3+
* tests/doRUnit.R: Simplified following pattern in RProtoBuf
4+
15
2014-02-01 JJ Allaire <[email protected]>
26

37
* R/Attributes.R: Embedded R code chunks in sourceCpp can

inst/NEWS.Rd

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,10 @@
4040
\item The Rcpp-FAQ and Rcpp-package vignettes have been updated and expanded.
4141
\item Vignettes are now typeset with grey background for code boxes.
4242
}
43+
\item Changes in Rcpp unit tests:
44+
\itemize{
45+
\item The file \code{tests/doRUnit.R} was rewritten following the
46+
pattern deployed in \cpkg{RProtoBuf} which is due to Murray Stokely
4347
}
4448
}
4549

tests/doRUnit.R

Lines changed: 36 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
# Copyright (C) 2009 - 2012 Dirk Eddelbuettel and Romain Francois
2-
# Earlier copyrights Gregor Gorjanc and Martin Maechler as detailed below
1+
# Copyright (C) 2009 - 2014 Dirk Eddelbuettel and Romain Francois
2+
# Earlier copyrights Gregor Gorjanc, Martin Maechler and Murray Stokely as detailed below
33
#
44
# This file is part of Rcpp.
55
#
@@ -16,50 +16,49 @@
1616
# You should have received a copy of the GNU General Public License
1717
# along with Rcpp. If not, see <http://www.gnu.org/licenses/>.
1818

19-
## Unit test wrapper invoked from tests/
20-
21-
##
22-
## Based on a file written by Martin Maechler for the Rmetrics
23-
## packages which itself was based on earlier work by Gregor Gorjanc
24-
## and documented on the R Wiki.
25-
2619
## doRUnit.R --- Run RUnit tests
27-
## ------------------------------------------------------------------------
28-
##
29-
## borrowed from package fUtilities in RMetrics
30-
## http://r-forge.r-project.org/plugins/scmsvn/viewcvs.php/pkg/fUtilities/tests/doRUnit.R?rev=1958&root=rmetrics&view=markup
3120
##
32-
## Originally follows Gregor Gorjanc's example in CRAN package 'gdata'
33-
## and the corresponding section in the R Wiki:
34-
## http://wiki.r-project.org/rwiki/doku.php?id=developers:runit
21+
## with credits to package fUtilities in RMetrics
22+
## which credits Gregor Gojanc's example in CRAN package 'gdata'
23+
## as per the R Wiki http://wiki.r-project.org/rwiki/doku.php?id=developers:runit
24+
## and changed further by Martin Maechler
25+
## and more changes by Murray Stokely in HistogramTools
26+
## and then used adapted in RProtoBuf
27+
## and now used here with two additional env var setters/getters
3528
##
36-
## MM: Vastly changed: This should also be "runnable" for *installed*
37-
## package which has no ./tests/
38-
## --> put the bulk of the code e.g. in ../inst/unitTests/runTests.R :
29+
## Dirk Eddelbuettel, Feb 2014
3930

40-
if (require("RUnit", quietly = TRUE)) {
31+
stopifnot(require(RUnit, quietly=TRUE))
32+
stopifnot(require(Rcpp, quietly=TRUE))
4133

42-
pkg <- "Rcpp" # code below for Rcpp
43-
require(pkg, character.only=TRUE)
44-
pathRcppTests <<- system.file("unitTests", package = pkg)
45-
stopifnot(file.exists(pathRcppTests), file.info(path.expand(pathRcppTests))$isdir)
34+
## Set a seed to make the test deterministic
35+
set.seed(42)
4636

47-
## without this, we get unit test failures
48-
Sys.setenv( R_TESTS = "" )
37+
## Define tests
38+
testSuite <- defineTestSuite(name="Rcpp Unit Tests",
39+
dirs=system.file("unitTests", package = "Rcpp"),
40+
testFuncRegexp = "^[Tt]est.+")
4941

50-
## force tests to be executed if in dev release which we define as
51-
## having a sub-release, eg 0.9.15.5 is one whereas 0.9.16 is not
52-
if (length(strsplit(packageDescription(pkg)$Version, "\\.")[[1]]) > 3) { # dev release, and
53-
if (Sys.getenv("RunAllRcppTests") != "no") { # if env.var not yet set
54-
message("Setting \"RunAllRcppTests\"=\"yes\" for development release\n")
55-
Sys.setenv("RunAllRcppTests"="yes")
56-
}
42+
## without this, we get (or used to get) unit test failures
43+
Sys.setenv("R_TESTS"="")
44+
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")
5751
}
52+
}
5853

59-
Rcpp.unit.test.output.dir <- getwd()
54+
## Run tests
55+
tests <- runTestSuite(testSuite)
6056

61-
source(file.path(pathRcppTests, "runTests.R"), echo = TRUE)
57+
## Print results
58+
printTextProtocol(tests)
6259

63-
} else {
64-
print("package RUnit not available, cannot run unit tests")
60+
## Return success or failure to R CMD CHECK
61+
if (getErrors(tests)$nFail > 0) {
62+
stop("TEST FAILED!")
6563
}
64+

0 commit comments

Comments
 (0)