@@ -50,25 +50,18 @@ describe("get_call_entries", {
50
50
})
51
51
52
52
it(" returns an empty string for packages with .Call entries and NAMESPACE files" , {
53
-
54
53
# tools::package_native_routine_registration_skeleton is not available before R 3.4
55
- skip_if(getRversion() < " 3.4" )
54
+ # R added `(void)` to the signature after R 4.3.0
55
+ skip_if(getRversion() < " 4.3.0" )
56
56
57
57
pkg <- local_package()
58
58
path <- pkg_path(pkg )
59
59
dir.create(file.path(path , " R" ))
60
+
60
61
writeLines(' foo <- function() .Call("bar")' , file.path(path , " R" , " foo.R" ))
61
62
call_entries <- get_call_entries(path , get_funs(path )$ name , get_package_name(path ))
62
- # R added `(void)` to the signature after R 4.2.1
63
- expect_match(call_entries [2 ], " extern SEXP bar[(](void)?[)]" )
64
- expect_equal(
65
- call_entries [4 : 7 ],
66
- c(" static const R_CallMethodDef CallEntries[] = {" ,
67
- " {\" bar\" , (DL_FUNC) &bar, 0}," ,
68
- " {NULL, NULL, 0}" ,
69
- " };"
70
- )
71
- )
63
+
64
+ expect_snapshot(call_entries )
72
65
})
73
66
it(" works with multiple register functions." , {
74
67
pkg <- local_package()
@@ -78,51 +71,7 @@ describe("get_call_entries", {
78
71
79
72
cpp_register(p )
80
73
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
- #include <R_ext/Visibility.h>
88
-
89
- // multiple.cpp
90
- int foo();
91
- extern \" C\" SEXP _testPkg_foo() {
92
- BEGIN_CPP11
93
- return cpp11::as_sexp(foo());
94
- END_CPP11
95
- }
96
- // multiple.cpp
97
- double bar(bool run);
98
- extern \" C\" SEXP _testPkg_bar(SEXP run) {
99
- BEGIN_CPP11
100
- return cpp11::as_sexp(bar(cpp11::as_cpp<cpp11::decay_t<bool>>(run)));
101
- END_CPP11
102
- }
103
- // multiple.cpp
104
- bool baz(bool run, int value);
105
- extern \" C\" SEXP _testPkg_baz(SEXP run, SEXP value) {
106
- BEGIN_CPP11
107
- return cpp11::as_sexp(baz(cpp11::as_cpp<cpp11::decay_t<bool>>(run), cpp11::as_cpp<cpp11::decay_t<int>>(value)));
108
- END_CPP11
109
- }
110
-
111
- extern \" C\" {
112
- static const R_CallMethodDef CallEntries[] = {
113
- {\" _testPkg_bar\" , (DL_FUNC) &_testPkg_bar, 1},
114
- {\" _testPkg_baz\" , (DL_FUNC) &_testPkg_baz, 2},
115
- {\" _testPkg_foo\" , (DL_FUNC) &_testPkg_foo, 0},
116
- {NULL, NULL, 0}
117
- };
118
- }
119
-
120
- extern \" C\" attribute_visible void R_init_testPkg(DllInfo* dll){
121
- R_registerRoutines(dll, NULL, CallEntries, NULL, NULL);
122
- R_useDynamicSymbols(dll, FALSE);
123
- R_forceSymbols(dll, TRUE);
124
- }
125
- " )
74
+ expect_snapshot(cat(read_file(cpp_bindings )))
126
75
})
127
76
})
128
77
@@ -569,44 +518,11 @@ describe("cpp_register", {
569
518
570
519
r_bindings <- file.path(p , " R" , " cpp11.R" )
571
520
expect_true(file.exists(r_bindings ))
572
- expect_equal(read_file(r_bindings ),
573
- " # Generated by cpp11: do not edit by hand
521
+ expect_snapshot(cat(read_file(r_bindings )))
574
522
575
- foo <- function() {
576
- .Call(`_testPkg_foo`)
577
- }
578
- " )
579
523
cpp_bindings <- file.path(p , " src" , " cpp11.cpp" )
580
524
expect_true(file.exists(cpp_bindings ))
581
- expect_equal(read_file(cpp_bindings ),
582
- " // Generated by cpp11: do not edit by hand
583
- // clang-format off
584
-
585
-
586
- #include \" cpp11/declarations.hpp\"
587
- #include <R_ext/Visibility.h>
588
-
589
- // single.cpp
590
- int foo();
591
- extern \" C\" SEXP _testPkg_foo() {
592
- BEGIN_CPP11
593
- return cpp11::as_sexp(foo());
594
- END_CPP11
595
- }
596
-
597
- extern \" C\" {
598
- static const R_CallMethodDef CallEntries[] = {
599
- {\" _testPkg_foo\" , (DL_FUNC) &_testPkg_foo, 0},
600
- {NULL, NULL, 0}
601
- };
602
- }
603
-
604
- extern \" C\" attribute_visible void R_init_testPkg(DllInfo* dll){
605
- R_registerRoutines(dll, NULL, CallEntries, NULL, NULL);
606
- R_useDynamicSymbols(dll, FALSE);
607
- R_forceSymbols(dll, TRUE);
608
- }
609
- " )
525
+ expect_snapshot(cat(read_file(cpp_bindings )))
610
526
})
611
527
612
528
it(" can be run without messages" , {
@@ -617,7 +533,6 @@ extern \"C\" attribute_visible void R_init_testPkg(DllInfo* dll){
617
533
expect_silent(cpp_register(p , quiet = TRUE ))
618
534
})
619
535
620
-
621
536
it(" can be run with messages" , {
622
537
local_reproducible_output()
623
538
pkg <- local_package()
0 commit comments