@@ -25,14 +25,16 @@ describe("pkg_links_to_rcpp", {
25
25
describe(" get_call_entries" , {
26
26
it(" returns an empty string if there are no R files" , {
27
27
pkg <- local_package()
28
- expect_equal(get_call_entries(pkg_path(pkg )), " " )
28
+ path <- pkg_path(pkg )
29
+ expect_equal(get_call_entries(path , get_funs(path )$ name , get_package_name(path )), " " )
29
30
})
30
31
31
32
it(" returns an empty string if there are no .Call calls" , {
32
33
pkg <- local_package()
33
- dir.create(file.path(pkg_path(pkg ), " R" ))
34
- writeLines(" foo <- function() 1" , file.path(pkg_path(pkg ), " R" , " foo.R" ))
35
- expect_equal(get_call_entries(pkg_path(pkg )), " " )
34
+ path <- pkg_path(pkg )
35
+ dir.create(file.path(path , " R" ))
36
+ writeLines(" foo <- function() 1" , file.path(path , " R" , " foo.R" ))
37
+ expect_equal(get_call_entries(path , get_funs(path )$ name , get_package_name(path )), " " )
36
38
})
37
39
38
40
it(" Errors for invalid packages" , {
@@ -44,7 +46,7 @@ describe("get_call_entries", {
44
46
writeLines(" Package: testPkg" , file.path(pkg , " DESCRIPTION" ))
45
47
dir.create(file.path(pkg , " R" ))
46
48
writeLines(' foo <- function() .Call("bar")' , file.path(pkg , " R" , " foo.R" ))
47
- expect_error(get_call_entries(pkg ), " has no 'NAMESPACE' file" )
49
+ expect_error(get_call_entries(pkg , get_funs( path ) $ name , get_package_name( pkg ) ), " has no 'NAMESPACE' file" )
48
50
})
49
51
50
52
it(" returns an empty string for packages with .Call entries and NAMESPACE files" , {
@@ -53,10 +55,11 @@ describe("get_call_entries", {
53
55
skip_if(getRversion() < " 3.4" )
54
56
55
57
pkg <- local_package()
56
- dir.create(file.path(pkg_path(pkg ), " R" ))
57
- writeLines(' foo <- function() .Call("bar")' , file.path(pkg_path(pkg ), " R" , " foo.R" ))
58
+ path <- pkg_path(pkg )
59
+ dir.create(file.path(path , " R" ))
60
+ writeLines(' foo <- function() .Call("bar")' , file.path(path , " R" , " foo.R" ))
58
61
expect_equal(
59
- get_call_entries(pkg_path( pkg )),
62
+ get_call_entries(path , get_funs( path ) $ name , get_package_name( path )),
60
63
c(" /* .Call calls */" ,
61
64
" extern SEXP bar();" ,
62
65
" " ,
@@ -67,6 +70,59 @@ describe("get_call_entries", {
67
70
)
68
71
)
69
72
})
73
+ it(" works with multiple register functions." , {
74
+ pkg <- local_package()
75
+ p <- pkg_path(pkg )
76
+ dir.create(file.path(p , " src" ))
77
+ file.copy(test_path(" multiple.cpp" ), file.path(p , " src" , " multiple.cpp" ))
78
+
79
+ cpp_register(p )
80
+ cpp_bindings <- file.path(p , " src" , " cpp11.cpp" )
81
+ expect_equal(read_file(cpp_bindings ),
82
+ " // Generated by cpp11: do not edit by hand
83
+ // clang-format off
84
+
85
+
86
+ #include \" cpp11/declarations.hpp\"
87
+
88
+ // multiple.cpp
89
+ int foo();
90
+ extern \" C\" SEXP _testPkg_foo() {
91
+ BEGIN_CPP11
92
+ return cpp11::as_sexp(foo());
93
+ END_CPP11
94
+ }
95
+ // multiple.cpp
96
+ double bar(bool run);
97
+ extern \" C\" SEXP _testPkg_bar(SEXP run) {
98
+ BEGIN_CPP11
99
+ return cpp11::as_sexp(bar(cpp11::as_cpp<cpp11::decay_t<bool>>(run)));
100
+ END_CPP11
101
+ }
102
+ // multiple.cpp
103
+ bool baz(bool run, int value);
104
+ extern \" C\" SEXP _testPkg_baz(SEXP run, SEXP value) {
105
+ BEGIN_CPP11
106
+ return cpp11::as_sexp(baz(cpp11::as_cpp<cpp11::decay_t<bool>>(run), cpp11::as_cpp<cpp11::decay_t<int>>(value)));
107
+ END_CPP11
108
+ }
109
+
110
+ extern \" C\" {
111
+ static const R_CallMethodDef CallEntries[] = {
112
+ {\" _testPkg_bar\" , (DL_FUNC) &_testPkg_bar, 1},
113
+ {\" _testPkg_baz\" , (DL_FUNC) &_testPkg_baz, 2},
114
+ {\" _testPkg_foo\" , (DL_FUNC) &_testPkg_foo, 0},
115
+ {NULL, NULL, 0}
116
+ };
117
+ }
118
+
119
+ extern \" C\" void R_init_testPkg(DllInfo* dll){
120
+ R_registerRoutines(dll, NULL, CallEntries, NULL, NULL);
121
+ R_useDynamicSymbols(dll, FALSE);
122
+ R_forceSymbols(dll, TRUE);
123
+ }
124
+ " )
125
+ })
70
126
})
71
127
72
128
describe(" wrap_call" , {
@@ -533,9 +589,6 @@ extern \"C\" SEXP _testPkg_foo() {
533
589
}
534
590
535
591
extern \" C\" {
536
- /* .Call calls */
537
- extern SEXP _testPkg_foo();
538
-
539
592
static const R_CallMethodDef CallEntries[] = {
540
593
{\" _testPkg_foo\" , (DL_FUNC) &_testPkg_foo, 0},
541
594
{NULL, NULL, 0}
0 commit comments