Skip to content

Commit 679d958

Browse files
committed
tinytest step one: enable, add runner and initial test
1 parent 64f5f1a commit 679d958

File tree

4 files changed

+69
-1
lines changed

4 files changed

+69
-1
lines changed

DESCRIPTION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ Description: The 'Rcpp' package provides R functions as well as C++ classes whic
1616
<doi:10.1080/00031305.2017.1375990>); see 'citation("Rcpp")' for details.
1717
Depends: R (>= 3.0.0)
1818
Imports: methods, utils
19-
Suggests: RUnit, inline, rbenchmark, knitr, rmarkdown, pinp, pkgKitten (>= 0.1.2)
19+
Suggests: RUnit, tinytest, inline, rbenchmark, knitr, rmarkdown, pinp, pkgKitten (>= 0.1.2)
2020
VignetteBuilder: knitr
2121
URL: http://www.rcpp.org, http://dirk.eddelbuettel.com/code/rcpp.html, https://github.com/RcppCore/Rcpp
2222
License: GPL (>= 2)

inst/tinytest/cpp/rcppversion.cpp

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#include <Rcpp.h>
2+
3+
// [[Rcpp::export]]
4+
Rcpp::List checkVersion(Rcpp::IntegerVector v) {
5+
6+
// incoming, we expect v to have been made by
7+
// as.integer(unlist(strsplit(as.character(packageVersion("Rcpp")), "\\.")))
8+
// yielding eg
9+
// c(1L, 0L, 3L, 1L)
10+
11+
// ensure that length is four, after possibly appending 0
12+
if (v.size() == 3) v.push_back(0);
13+
if (v.size() != 4) Rcpp::stop("Expect vector with four elements.");
14+
15+
return Rcpp::List::create(Rcpp::Named("def_ver") = RCPP_VERSION,
16+
Rcpp::Named("def_str") = RCPP_VERSION_STRING,
17+
Rcpp::Named("cur_ver") = Rcpp_Version(v[0], v[1], v[2]),
18+
Rcpp::Named("def_dev_ver") = RCPP_DEV_VERSION,
19+
Rcpp::Named("def_dev_str") = RCPP_DEV_VERSION_STRING,
20+
Rcpp::Named("cur_dev_ver") = RcppDevVersion(v[0], v[1], v[2], v[3]));
21+
}

inst/tinytest/test_version.R

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
2+
library(Rcpp)
3+
4+
Rcpp::sourceCpp("cpp/rcppversion.cpp")
5+
6+
## we take packageVersion, make it a character variable, split it by dots and turn it to ints
7+
## note that v could now be a three or four element vector depending on what the package version is
8+
pv <- packageVersion("Rcpp")
9+
pvstr <- as.character(pv)
10+
v <- as.integer(unlist(strsplit(pvstr, "\\.")))
11+
12+
## construct a release string from the first three elements, ie "1.0.3" from 1.0.3.1
13+
relstr <- as.character(as.package_version(paste(v[1:3], collapse=".")))
14+
15+
16+
## call C++ function returning list of six values, three each for 'release' and 'dev' version
17+
res <- checkVersion(v)
18+
19+
20+
## basic check: is the #defined version equal to the computed version (issue #1014)
21+
expect_equal(res$cur_ver, res$def_ver, info="current computed version equal defined version")
22+
23+
## basic check: is the #defined string version equal to the computed string version (adjusting for rel)
24+
expect_equal(relstr, res$def_str, info="current computed version equal defined dev string")
25+
26+
## additional checks if we are a dev version
27+
if (length(v) == 4) {
28+
expect_equal(res$cur_dev_ver, res$def_dev_ver, info="current computed dev version greater equal defined dev version")
29+
30+
## basic check: is #defined string version equal to computed string
31+
expect_equal(pvstr, res$def_dev_str, info="current computed version equal defined dev string")
32+
}

tests/tinytest.R

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
2+
if (requireNamespace("tinytest", quietly=TRUE) &&
3+
utils::packageVersion("tinytest") >= "1.0.0") {
4+
5+
## Set a seed to make the test deterministic
6+
set.seed(42)
7+
8+
## R makes us to this
9+
Sys.setenv("R_TESTS"="")
10+
11+
## there are several more granular ways to test files in a tinytest directory,
12+
## see its package vignette; tests can also run once the package is installed
13+
## using the same command `test_package(pkgName)`, or by director or file
14+
tinytest::test_package("Rcpp", ncpu=getOption("Ncpus", 1))
15+
}

0 commit comments

Comments
 (0)