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