|
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 |
3 | 3 | #
|
4 | 4 | # This file is part of Rcpp.
|
5 | 5 | #
|
|
16 | 16 | # You should have received a copy of the GNU General Public License
|
17 | 17 | # along with Rcpp. If not, see <http://www.gnu.org/licenses/>.
|
18 | 18 |
|
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 |
| - |
26 | 19 | ## 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 |
31 | 20 | ##
|
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 |
35 | 28 | ##
|
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 |
39 | 30 |
|
40 |
| -if (require("RUnit", quietly = TRUE)) { |
| 31 | +stopifnot(require(RUnit, quietly=TRUE)) |
| 32 | +stopifnot(require(Rcpp, quietly=TRUE)) |
41 | 33 |
|
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) |
46 | 36 |
|
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.+") |
49 | 41 |
|
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") |
57 | 51 | }
|
| 52 | +} |
58 | 53 |
|
59 |
| - Rcpp.unit.test.output.dir <- getwd() |
| 54 | +## Run tests |
| 55 | +tests <- runTestSuite(testSuite) |
60 | 56 |
|
61 |
| - source(file.path(pathRcppTests, "runTests.R"), echo = TRUE) |
| 57 | +## Print results |
| 58 | +printTextProtocol(tests) |
62 | 59 |
|
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!") |
65 | 63 | }
|
| 64 | + |
0 commit comments