-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use a test helper to define the expected C++ error class (fixes #15)
* This works around the fact that, in certain circumstances, we cannot rely on errors propagating with proper `std::invalid_argument` class / error message. See also RcppCore/Rcpp#972
- Loading branch information
1 parent
6a0e4d2
commit b292e3a
Showing
3 changed files
with
38 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
# Work around the fact that, in certain circumstances (architectures / | ||
# compilers), we cannot rely on errors propagating with proper | ||
# `std::invalid_argument` class / error message. | ||
# | ||
# See https://github.com/miraisolutions/rTRNG/issues/15, | ||
# https://github.com/RcppCore/Rcpp/issues/972 | ||
# | ||
# Approach: Use a minimal example to test whether "std::invalid_argument" is | ||
# correctly detected, otherwise just fall-back on "error" (the "c++ exception | ||
# (unknown reason)" error inherits from it). | ||
|
||
invalid_argument_thrower <- cppFunction(' | ||
void invalid_argument_thrower() { | ||
throw std::invalid_argument("Invalid argument test"); | ||
} | ||
') | ||
|
||
invalid_argument_error_class <- function() { | ||
error_class <- tryCatch( | ||
invalid_argument_thrower(), | ||
error = function(e) class(e) | ||
) | ||
error_class | ||
} | ||
|
||
supported_invalid_argument_class <- function() { | ||
if ("std::invalid_argument" %in% invalid_argument_error_class()) { | ||
"std::invalid_argument" | ||
} else { | ||
"error" | ||
} | ||
} | ||
|
||
expected_invalid_argument_class <- supported_invalid_argument_class() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters