Skip to content

Commit 6f45d4c

Browse files
author
Filip Schouwenaars
committed
add failing spec for #851
1 parent aefe64f commit 6f45d4c

File tree

2 files changed

+45
-9
lines changed

2 files changed

+45
-9
lines changed

inst/unitTests/cpp/embeddedR2.cpp

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
// -*- mode: C++; c-indent-level: 4; c-basic-offset: 4; tab-width: 8 -*-
2+
//
3+
// Environment.cpp: Rcpp R/C++ interface class library -- Environment unit tests
4+
//
5+
// Copyright (C) 2018 Dirk Eddelbuettel and Romain Francois
6+
//
7+
// This file is part of Rcpp.
8+
//
9+
// Rcpp is free software: you can redistribute it and/or modify it
10+
// under the terms of the GNU General Public License as published by
11+
// the Free Software Foundation, either version 2 of the License, or
12+
// (at your option) any later version.
13+
//
14+
// Rcpp is distributed in the hope that it will be useful, but
15+
// WITHOUT ANY WARRANTY; without even the implied warranty of
16+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17+
// GNU General Public License for more details.
18+
//
19+
// You should have received a copy of the GNU General Public License
20+
// along with Rcpp. If not, see <http://www.gnu.org/licenses/>.
21+
22+
#include <Rcpp.h>
23+
using namespace Rcpp ;
24+
25+
// [[Rcpp::export]]
26+
int bar(){
27+
return 42 ;
28+
}
29+
30+
/*** R
31+
x <- foo()
32+
x
33+
*/

inst/unitTests/runit.embeddedR.R

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,20 +18,23 @@
1818
# You should have received a copy of the GNU General Public License
1919
# along with Rcpp. If not, see <http://www.gnu.org/licenses/>.
2020

21-
.runThisTest <- TRUE # Sys.getenv("RunAllRcppTests") == "yes"
21+
.runThisTest <- Sys.getenv("RunAllRcppTests") == "yes"
2222

2323
if (.runThisTest) {
2424

2525
test.embeddedR <- function() {
26-
27-
path <- system.file("unitTests", package = "Rcpp")
26+
path <- file.path(system.file("unitTests", package = "Rcpp"), "cpp")
2827
expectedVars <- c("foo", "x")
28+
29+
# embeddedR.cpp exposes the function foo, R snippet calls foo
2930
newEnv <- new.env()
30-
Rcpp::sourceCpp(file.path(path, "cpp", "embeddedR.cpp"), env = newEnv)
31-
checkEquals(ls(newEnv), expectedVars, msg = " sourcing code in other env")
31+
Rcpp::sourceCpp(file.path(path, "embeddedR.cpp"),
32+
env = newEnv)
33+
checkEquals(ls(newEnv), expectedVars, msg = " sourcing code in custom env")
34+
35+
# R snippet in embeddedR2.cpp also contains a call to foo from previous cpp
36+
newEnv2 <- new.env()
37+
checkException(Rcpp::sourceCpp(file.path(path, "embeddedR2.cpp"), env = newEnv2),
38+
" not available in other env")
3239
}
33-
3440
}
35-
36-
37-

0 commit comments

Comments
 (0)