21
21
22
22
if (.runThisTest ) {
23
23
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
+
24
43
test.interface.unwind <- function () {
25
44
exporter_name <- " testRcppInterfaceExporter"
26
45
user_name <- " testRcppInterfaceUser"
@@ -33,37 +52,12 @@ if (.runThisTest) {
33
52
unlink(tempdir , recursive = TRUE )
34
53
})
35
54
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
-
49
55
lib_path <- file.path(tempdir , " templib" )
50
56
dir.create(lib_path )
51
57
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
-
64
58
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 ) )
67
61
68
62
# Without this testInstalledPackage() won't find installed
69
63
# packages even though we've passed `lib.loc`
@@ -73,12 +67,31 @@ if (.runThisTest) {
73
67
sys_sep <- if (.Platform $ OS.type == " windows" ) " ;" else " :"
74
68
Sys.setenv(R_LIBS = paste(c(lib_path , old_lib_paths ), collapse = sys_sep ))
75
69
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
+
76
74
result <- tools :: testInstalledPackage(user_name , lib.loc = lib_path , types = " test" )
77
75
78
76
# Be verbose if tests were not successful
79
77
if (result ) {
80
78
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())
82
95
}
83
96
84
97
checkEquals(result , 0L )
0 commit comments