|
1 |
| -# Copyright (C) 2009 - 2014 Dirk Eddelbuettel and Romain Francois |
| 1 | +# Copyright (C) 2009 - 2018 Dirk Eddelbuettel and Romain Francois |
2 | 2 | # Earlier copyrights Gregor Gorjanc, Martin Maechler and Murray Stokely as detailed below
|
3 | 3 | #
|
4 | 4 | # This file is part of Rcpp.
|
|
28 | 28 | ##
|
29 | 29 | ## Dirk Eddelbuettel, Feb 2014
|
30 | 30 |
|
31 |
| -stopifnot(require(RUnit, quietly=TRUE)) |
32 |
| -stopifnot(require(Rcpp, quietly=TRUE)) |
| 31 | +if (requireNamespace("RUnit", quietly=TRUE) && |
| 32 | + requireNamespace("Rcpp", quietly=TRUE)) { |
33 | 33 |
|
34 |
| -## Set a seed to make the test deterministic |
35 |
| -set.seed(42) |
| 34 | + library(RUnit) |
| 35 | + library(Rcpp) |
36 | 36 |
|
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 |
41 | 38 |
|
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.+") |
44 | 43 |
|
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 | + } |
51 | 53 | }
|
52 |
| -} |
53 | 54 |
|
54 |
| -## Run tests |
55 |
| -tests <- runTestSuite(testSuite) |
| 55 | + tests <- runTestSuite(testSuite) # Run tests |
56 | 56 |
|
57 |
| -## Print results |
58 |
| -printTextProtocol(tests) |
| 57 | + printTextProtocol(tests) # Print results |
59 | 58 |
|
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!") |
66 | 64 | }
|
67 |
| -if (getErrors(tests)$nTestFunc < 1 && Sys.getenv("RunAllRcppTests")=="yes") { |
68 |
| - stop("NO TEST FUNCTIONS RUN!") |
69 |
| -} |
70 |
| - |
0 commit comments