|
| 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