2121
2222if (.runThisTest ) {
2323
24+ build_package <- function (name , lib_path , tempdir = getwd(),
25+ config = character ()) {
26+ file.copy(system.file(" unitTests" , name , package = " Rcpp" ),
27+ getwd(),
28+ recursive = TRUE )
29+
30+ src_path <- file.path(tempdir , name )
31+ Rcpp :: compileAttributes(src_path )
32+ writeLines(config , file.path(src_path , " src" , " config.h" ))
33+
34+ install.packages(
35+ src_path ,
36+ lib_path ,
37+ repos = NULL ,
38+ type = " source" ,
39+ INSTALL_opts = " --install-tests"
40+ )
41+ }
42+
2443 test.interface.unwind <- function () {
2544 exporter_name <- " testRcppInterfaceExporter"
2645 user_name <- " testRcppInterfaceUser"
@@ -33,37 +52,12 @@ if (.runThisTest) {
3352 unlink(tempdir , recursive = TRUE )
3453 })
3554
36- file.copy(system.file(" unitTests" , exporter_name , package = " Rcpp" ),
37- tempdir ,
38- recursive = TRUE )
39- file.copy(system.file(" unitTests" , user_name , package = " Rcpp" ),
40- tempdir ,
41- recursive = TRUE )
42-
43- exporter_path <- file.path(tempdir , exporter_name )
44- user_path <- file.path(tempdir , user_name )
45-
46- Rcpp :: compileAttributes(exporter_path )
47- Rcpp :: compileAttributes(user_path )
48-
4955 lib_path <- file.path(tempdir , " templib" )
5056 dir.create(lib_path )
5157
52- install <- function (path , lib_path ) {
53- install.packages(
54- path ,
55- lib_path ,
56- repos = NULL ,
57- type = " source" ,
58- INSTALL_opts = " --install-tests"
59- )
60- }
61- install(exporter_path , lib_path )
62- install(user_path , lib_path )
63-
6458 old_lib_paths <- .libPaths()
65- on.exit(.libPaths(old_lib_paths ))
66- .libPaths(lib_path )
59+ on.exit(.libPaths(old_lib_paths ), add = TRUE )
60+ .libPaths(c( lib_path , old_lib_paths ) )
6761
6862 # Without this testInstalledPackage() won't find installed
6963 # packages even though we've passed `lib.loc`
@@ -73,12 +67,31 @@ if (.runThisTest) {
7367 sys_sep <- if (.Platform $ OS.type == " windows" ) " ;" else " :"
7468 Sys.setenv(R_LIBS = paste(c(lib_path , old_lib_paths ), collapse = sys_sep ))
7569
70+ cfg <- " #define RCPP_PROTECTED_EVAL"
71+ build_package(exporter_name , lib_path , config = cfg )
72+ build_package(user_name , lib_path , config = cfg )
73+
7674 result <- tools :: testInstalledPackage(user_name , lib.loc = lib_path , types = " test" )
7775
7876 # Be verbose if tests were not successful
7977 if (result ) {
8078 log <- file.path(paste0(user_name , " -tests" ), " tests.Rout.fail" )
81- cat(" >> tests.Rout.fail" , readLines(log ), sep = " \n " , file = stderr())
79+ cat(" >> PROTECTED tests.Rout.fail" , readLines(log ), sep = " \n " , file = stderr())
80+ }
81+
82+ checkEquals(result , 0L )
83+
84+
85+ # Now test client package without protected evaluation
86+ unlink(user_name , recursive = TRUE )
87+ unlink(paste0(user_name , " -tests" ), recursive = TRUE )
88+ build_package(user_name , lib_path , config = character ())
89+
90+ result <- tools :: testInstalledPackage(user_name , lib.loc = lib_path , types = " test" )
91+
92+ if (result ) {
93+ log <- file.path(paste0(user_name , " -tests" ), " tests.Rout.fail" )
94+ cat(" >> UNPROTECTED tests.Rout.fail" , readLines(log ), sep = " \n " , file = stderr())
8295 }
8396
8497 checkEquals(result , 0L )
0 commit comments