|
| 1 | + |
| 2 | +## Copyright (C) 2013 - 2019 Dirk Eddelbuettel and Romain Francois |
| 3 | +## |
| 4 | +## This file is part of Rcpp. |
| 5 | +## |
| 6 | +## Rcpp is free software: you can redistribute it and/or modify it |
| 7 | +## under the terms of the GNU General Public License as published by |
| 8 | +## the Free Software Foundation, either version 2 of the License, or |
| 9 | +## (at your option) any later version. |
| 10 | +## |
| 11 | +## Rcpp is distributed in the hope that it will be useful, but |
| 12 | +## WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | +## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | +## GNU General Public License for more details. |
| 15 | +## |
| 16 | +## You should have received a copy of the GNU General Public License |
| 17 | +## along with Rcpp. If not, see <http://www.gnu.org/licenses/>. |
| 18 | + |
| 19 | +.runThisTest <- Sys.getenv("RunAllRcppTests") == "yes" |
| 20 | + |
| 21 | +## override -- skipping test for now (need to rebuild binary) |
| 22 | +.runThisTest <- FALSE |
| 23 | + |
| 24 | +if (!.runThisTest) exit_file("Skipping, set 'RunAllRcppTests=yes' to run.") |
| 25 | + |
| 26 | +library(Rcpp) |
| 27 | + |
| 28 | +# test.Rcpp.package.skeleton <- function(){ |
| 29 | + |
| 30 | +tempdir <- tempdir() |
| 31 | +path <- tempdir |
| 32 | +pkg_path <- file.path(path, "foo") |
| 33 | +R_path <- file.path(pkg_path, "R") |
| 34 | +src_path <- file.path(pkg_path, "src") |
| 35 | +env <- new.env() |
| 36 | + |
| 37 | +env$funA <- function(alpha, beta) "gamma" |
| 38 | +env$funB <- function(first, ..., last) "foo" |
| 39 | + |
| 40 | +Rcpp.package.skeleton("foo", path=path, list=c("funA", "funB"), |
| 41 | + author="Boo-Boo Bear", |
| 42 | + maintainer="Yogi Bear", |
| 43 | + license="An Opensource License", |
| 44 | + email="yogibear@yogimail.com", |
| 45 | + environment=env) |
| 46 | + |
| 47 | +checkTrue( "foo" %in% list.files(path), "pkg path generated as named" ) |
| 48 | + |
| 49 | +## check the DESCRIPTION |
| 50 | +DESCRIPTION <- as.list( read.dcf( file.path(pkg_path, "DESCRIPTION") )[1,] ) |
| 51 | +checkTrue( DESCRIPTION["Author"] == "Boo-Boo Bear", |
| 52 | + "wrote the Author field in DESCRIPTION" ) |
| 53 | +checkTrue( DESCRIPTION["Maintainer"] == "Yogi Bear <yogibear@yogimail.com>", |
| 54 | + "wrote the Maintainer field in DESCRIPTION") |
| 55 | +checkTrue( DESCRIPTION["License"] == "An Opensource License", |
| 56 | + "wrote the License field in DESCRIPTION" ) |
| 57 | +checkTrue( DESCRIPTION["LinkingTo"] == "Rcpp", |
| 58 | + "we make sure that we 'link' to Rcpp (use its headers)" ) |
| 59 | + |
| 60 | +## make sure we have useDynLib in the namespace |
| 61 | +NAMESPACE <- readLines( file.path(pkg_path, "NAMESPACE") ) |
| 62 | + |
| 63 | +## note: we use regular expressions anticipating a possible future |
| 64 | +## usage of e.g. '.registration=TRUE' in Rcpp.package.skeleton |
| 65 | +checkTrue( any(grepl( "useDynLib(foo", NAMESPACE, fixed=TRUE )), |
| 66 | + "NAMESPACE has useDynLib(foo)" ) |
| 67 | + |
| 68 | +R_files <- list.files(R_path, full.names=TRUE) |
| 69 | +checkTrue( all( c("funA.R", "funB.R") %in% list.files(R_path)), |
| 70 | + "created R files from functions" ) |
| 71 | +for (file in grep("RcppExports.R", R_files, invert=TRUE, value=TRUE)) { |
| 72 | + code <- readLines(file) |
| 73 | + fn <- eval(parse(text=paste(code, collapse="\n"))) |
| 74 | + fn_name <- gsub(".*/(.*)\\.R$", "\\1", file) |
| 75 | + checkIdentical(fn, get(fn_name), |
| 76 | + sprintf("we parsed the function '%s' correctly", fn_name) |
| 77 | + ) |
| 78 | +} |
| 79 | + |
| 80 | +## make sure we can build the package as generated |
| 81 | +## note: the generated .Rd placeholders are insufficient to be able |
| 82 | +## to successfully install the pkg; e.g. I see |
| 83 | + |
| 84 | +## Error in Rd_info(db[[i]]) : |
| 85 | +## missing/empty \title field in '<path>/funA.Rd' |
| 86 | +invisible(sapply( list.files( file.path(pkg_path, "man"), full.names=TRUE), unlink )) |
| 87 | + |
| 88 | +owd <- getwd() |
| 89 | +setwd(path) |
| 90 | +R <- shQuote( file.path( R.home( component = "bin" ), "R" )) |
| 91 | +system( paste(R, "CMD build", pkg_path) ) |
| 92 | +checkTrue( file.exists("foo_1.0.tar.gz"), "can successfully R CMD build the pkg") |
| 93 | +dir.create("templib") |
| 94 | +install.packages("foo_1.0.tar.gz", file.path(path, "templib"), repos=NULL, type="source") |
| 95 | +require("foo", file.path(path, "templib"), character.only=TRUE) |
| 96 | + |
| 97 | + |
| 98 | +# test.Rcpp.package.skeleton.Attributes <- function() { |
| 99 | +tempdir <- tempdir() |
| 100 | +path <- tempdir |
| 101 | +if (dir.exists(file.path(path, "foo"))) unlink(file.path(path, "foo"), recursive=TRUE) |
| 102 | +pkg_path <- file.path(path, "foo") |
| 103 | +R_path <- file.path(pkg_path, "R") |
| 104 | +src_path <- file.path(pkg_path, "src") |
| 105 | + |
| 106 | +Rcpp.package.skeleton("foo", path=path, attributes=TRUE, example_code=TRUE, |
| 107 | + environment=environment()) |
| 108 | +checkTrue(file.exists( file.path(src_path, "RcppExports.cpp")), |
| 109 | + "RcppExports.cpp was created") |
| 110 | +checkTrue(file.exists( file.path(src_path, "rcpp_hello_world.cpp")), |
| 111 | + "rcpp_hello_world.cpp was created" ) |
| 112 | +checkTrue(file.exists( file.path(R_path, "RcppExports.R")), |
| 113 | + "RcppExports.R was created") |
| 114 | +#on.exit( unlink(pkg_path, recursive=TRUE), add=TRUE ) |
| 115 | +unlink(pkg_path, recursive=TRUE) |
| 116 | + |
| 117 | +# test.Rcpp.package.skeleton.NoAttributes <- function() { |
| 118 | +tempdir <- tempdir() |
| 119 | +path <- tempdir |
| 120 | +pkg_path <- file.path(path, "foo") |
| 121 | +R_path <- file.path(pkg_path, "R") |
| 122 | +src_path <- file.path(pkg_path, "src") |
| 123 | + |
| 124 | +Rcpp.package.skeleton("foo", path=path, attributes=FALSE, example_code=TRUE, |
| 125 | + environment=environment()) |
| 126 | +checkTrue(file.exists( file.path(src_path, "rcpp_hello_world.cpp")), |
| 127 | + "rcpp_hello_world.cpp was created") |
| 128 | +checkTrue(file.exists( file.path(src_path, "rcpp_hello_world.h")), |
| 129 | + "rcpp_hello_world.h was created") |
| 130 | +checkTrue(file.exists( file.path(R_path, "rcpp_hello_world.R")), |
| 131 | + "rcpp_hello_world.R was created" ) |
| 132 | +on.exit( unlink(pkg_path, recursive=TRUE) ) |
| 133 | + |
| 134 | +# test.Rcpp.package.skeleton.Module <- function() { |
| 135 | +tempdir <- tempdir() |
| 136 | +path <- tempdir |
| 137 | +pkg_path <- file.path(path, "foo") |
| 138 | +R_path <- file.path(pkg_path, "R") |
| 139 | +src_path <- file.path(pkg_path, "src") |
| 140 | + |
| 141 | +Rcpp.package.skeleton("foo", path=path, module=TRUE, environment=environment()) |
| 142 | +checkTrue(file.exists( file.path(src_path, "rcpp_module.cpp")), |
| 143 | + "rcpp_module.cpp was created") |
| 144 | + |
| 145 | +on.exit(unlink(pkg_path, recursive=TRUE)) |
| 146 | +on.exit( setwd(owd), add=TRUE ) |
| 147 | +on.exit( unlink( file.path(path, "foo_1.0.tar.gz") ), add=TRUE) |
| 148 | +on.exit( unlink( file.path(path, "templib"), recursive=TRUE), add=TRUE ) |
| 149 | +on.exit( unlink(pkg_path, recursive=TRUE), add=TRUE ) |
| 150 | +on.exit(unlink(pkg_path, recursive=TRUE), add=TRUE) |
0 commit comments