Skip to content

Commit dd3dcb2

Browse files
committed
Test both Rcpp_eval() and Rcpp_fast_eval()
1 parent 088c5c6 commit dd3dcb2

File tree

4 files changed

+37
-13
lines changed

4 files changed

+37
-13
lines changed

ChangeLog

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@
77
functions are still caught and dealt with properly by the client
88
package.
99

10+
* inst/unitTests/runit.interface.R: Test both Rcpp_eval() and
11+
Rcpp_fast_eval().
12+
1013
2018-06-01 Lionel Henry <[email protected]>
1114

1215
* inst/unitTests/runit.interface.R: New tests for interfaces and unwind.

inst/unitTests/testRcppInterfaceExporter/src/exporter.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,11 @@
77

88
//' @export
99
// [[Rcpp::export]]
10-
SEXP test_cpp_interface(SEXP x) {
10+
SEXP test_cpp_interface(SEXP x, bool fast = false) {
1111
unwound_t stack_obj("cpp_interface_upstream");
12-
return Rcpp::Rcpp_fast_eval(x, R_GlobalEnv);
12+
if (fast) {
13+
return Rcpp::Rcpp_fast_eval(x, R_GlobalEnv);
14+
} else {
15+
return Rcpp::Rcpp_eval(x, R_GlobalEnv);
16+
}
1317
}

inst/unitTests/testRcppInterfaceUser/src/user.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@
88

99
//' @export
1010
// [[Rcpp::export]]
11-
SEXP use_cpp_interface(SEXP x) {
11+
SEXP use_cpp_interface(SEXP x, bool fast = false) {
1212
unwound_t stack_obj("cpp_interface_downstream");
13-
Rcpp::RObject out = testRcppInterfaceExporter::test_cpp_interface(x);
13+
Rcpp::RObject out = testRcppInterfaceExporter::test_cpp_interface(x, fast);
1414
Rcpp::Rcout << "Wrapping up" << std::endl;
1515
return out;
1616
}

inst/unitTests/testRcppInterfaceUser/tests/tests.R

Lines changed: 26 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,39 @@
11

2+
reset <- function() {
3+
testRcppInterfaceUser::reset_flags()
4+
testRcppInterfaceExporter::reset_flags()
5+
}
6+
7+
28
# This tests errors converted to exceptions by Rcpp_eval()
39
x <- tryCatch(
410
error = identity,
511
testRcppInterfaceUser::use_cpp_interface(quote(stop("jump!")))
612
)
713

8-
stopifnot(grepl("jump!", x$message))
14+
stopifnot(
15+
grepl("jump!", x$message),
16+
testRcppInterfaceUser::peek_flag("cpp_interface_downstream"),
17+
testRcppInterfaceExporter::peek_flag("cpp_interface_upstream")
18+
)
919

10-
if (getRversion() >= "3.5.0") {
11-
stopifnot(
12-
testRcppInterfaceUser::peek_flag("cpp_interface_downstream"),
13-
testRcppInterfaceExporter::peek_flag("cpp_interface_upstream")
14-
)
15-
}
20+
21+
reset()
22+
23+
# This tests errors converted to resumable longjumps by Rcpp_fast_eval()
24+
x <- tryCatch(
25+
error = identity,
26+
testRcppInterfaceUser::use_cpp_interface(quote(stop("jump!")), fast = TRUE)
27+
)
28+
29+
stopifnot(
30+
grepl("jump!", x$message),
31+
testRcppInterfaceUser::peek_flag("cpp_interface_downstream"),
32+
testRcppInterfaceExporter::peek_flag("cpp_interface_upstream")
33+
)
1634

1735

18-
testRcppInterfaceUser::reset_flags()
19-
testRcppInterfaceExporter::reset_flags()
36+
reset()
2037

2138
# This tests longjumps not caught by Rcpp_eval()
2239
x <- withRestarts(

0 commit comments

Comments
 (0)