Skip to content

Commit 35cdbe0

Browse files
committed
new test for version number consistency (fixes #1021)
1 parent f42aa4e commit 35cdbe0

File tree

4 files changed

+91
-1
lines changed

4 files changed

+91
-1
lines changed

ChangeLog

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
2019-11-11 Dirk Eddelbuettel <edd@debian.org>
2+
3+
* inst/unitTests/runit.packageversion.R: New test
4+
* inst/unitTests/cpp/rcppversion.cpp: Cpp portion of test
5+
16
2019-11-10 Dirk Eddelbuettel <edd@debian.org>
27

38
* .github/: Add files CONTRIBUTING.md, FUNDING.yml, ISSUE_TEMPLATE.md
@@ -12,7 +17,7 @@
1217

1318
2019-11-09 TJ McKinley <t.mckinley@exeter.ac.uk>
1419

15-
* R/Attributes.R: Correct how cppFunction() deal with multiple
20+
* R/Attributes.R: Correct how cppFunction() deals with multiple
1621
depends arguments
1722

1823
2019-11-08 Romain Francois <romain@rstudio.com>

inst/NEWS.Rd

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,11 @@
2121
\item The \code{.github/} directory now has more explicit guidance on
2222
contributinh, issues, and pull requests (Dirk).
2323
}
24+
\item Changes in Rcpp Deployment:
25+
\itemize{
26+
\item Added unit test to check if C++ version remains remains aligned
27+
with the package number (Dirk in \ghpr{1022} fixing \ghit{1021}).
28+
}
2429
}
2530
}
2631

inst/unitTests/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+
}
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
#!/usr/bin/env r
2+
#
3+
# Copyright (C) 2019 Dirk Eddelbuettel
4+
#
5+
# This file is part of Rcpp.
6+
#
7+
# Rcpp is free software: you can redistribute it and/or modify it
8+
# under the terms of the GNU General Public License as published by
9+
# the Free Software Foundation, either version 2 of the License, or
10+
# (at your option) any later version.
11+
#
12+
# Rcpp is distributed in the hope that it will be useful, but
13+
# WITHOUT ANY WARRANTY; without even the implied warranty of
14+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15+
# GNU General Public License for more details.
16+
#
17+
# You should have received a copy of the GNU General Public License
18+
# along with Rcpp. If not, see <http://www.gnu.org/licenses/>.
19+
20+
.runThisTest <- Sys.getenv("RunAllRcppTests") == "yes"
21+
22+
if (.runThisTest) {
23+
24+
.setUp <- Rcpp:::unitTestSetup("rcppversion.cpp")
25+
26+
test.PackageVersion <- function() {
27+
28+
## we take packageVersion, make it a character variable, split
29+
## it by dots and turn it to ints
30+
##
31+
## note that v could now be a three or four element vector
32+
## depending on what the package version is
33+
pv <- packageVersion("Rcpp")
34+
pvstr <- as.character(pv)
35+
v <- as.integer(unlist(strsplit(pvstr, "\\.")))
36+
37+
## construct a release string from the first three elements, ie "1.0.3" from 1.0.3.1
38+
relstr <- as.character(as.package_version(paste(v[1:3], collapse=".")))
39+
40+
## call C++ function returning list of six values, three each for 'release' and 'dev' version
41+
res <- checkVersion(v)
42+
43+
## basic check: is the #defined version equal to the computed version (issue #1014)
44+
checkEquals(res$cur_ver, res$def_ver, msg="current computed version equal defined version")
45+
46+
## basic check: is #defined string version equal to computed string version (adjusting for rel)
47+
checkEquals(relstr, res$def_str, msg="current computed version equal defined dev string")
48+
49+
## additional checks if we are a dev version
50+
if (length(v) == 4) {
51+
checkEquals(res$cur_dev_ver, res$def_dev_ver,
52+
msg="current computed dev version greater equal defined dev version")
53+
54+
## basic check: is #defined string version equal to computed string
55+
checkEquals(pvstr, res$def_dev_str,
56+
msg="current computed version equal defined dev string")
57+
}
58+
}
59+
}

0 commit comments

Comments
 (0)