Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

C++ unit tests crash #16

Closed
clauswilke opened this issue Nov 26, 2020 · 6 comments
Closed

C++ unit tests crash #16

clauswilke opened this issue Nov 26, 2020 · 6 comments

Comments

@clauswilke
Copy link
Collaborator

clauswilke commented Nov 26, 2020

Since the release of testthat 3.0.0, my C++ unit tests crash. Before the crash occurs, I see some errors being generated in these lines:
https://github.com/wilkelab/isoband/blob/50da871dda8ad38c46c63f0eed0e58bb4146d57a/src/clip-lines.h#L38-L46
but that must be a symptom of the problem, not the cause. The testing code is written so that it provides valid input, and it used to run in the past.

Detailed output of devtools::test() follows below.

==> devtools::test()

Loading isoband
Testing isoband
✓ |  OK F W S | Context
✓ |  63       | clip-lines [0.2 s]                  
x |   0 1     | Catch                               
--------------------------------------------------------------------------------
FAILURE (???): 
singular transformation due to invalid box extent
--------------------------------------------------------------------------------
x |   0 2     | Catch                               
────────────────────────────────────────────────────
Failure (???): 
singular transformation due to invalid box extent

Error (test-cpp.R:3:3): Catch unit tests pass
Error: '' does not exist in current working directory ('/Users/clauswilke/github/isoband/tests/testthat').
Backtrace:
 1. testthat::run_cpp_tests("isoband") test-cpp.R:3:2
 3. xml2:::read_xml.character(paste(output, collapse = "\n"))
 4. xml2:::path_to_connection(x)
 5. xml2:::check_path(path)
────────────────────────────────────────────────────
✓ |  10       | iso-to-sfg [0.4 s]                  
✓ |  43       | isobands [0.1 s]                    
✓ |  10       | isolines-grob [0.1 s]               
✓ |  23       | isolines                            
✓ |  24       | label-placer                        

══ Results ═════════════════════════════════════════
Duration: 1.1 s

[ FAIL 2 | WARN 0 | SKIP 0 | PASS 173 ]

Frustration is a natural part of programming :)

 *** caught bus error ***
address 0x7fd8cc80d4e0, cause 'non-existent physical address'
An irrecoverable exception occurred. R is aborting now ...

Exited with status 10.
@clauswilke
Copy link
Collaborator Author

@thomasp85 Do you have time to look into this within the next few days? (The package needs to be updated on CRAN by December 10 or will be archived.) It's unclear to me what is going on, and my only current fix is to disable all C++ unit tests, which seems suboptimal.

@thomasp85
Copy link
Member

Do you know which of the C++ unit tests triggers the failure? Is it the last black that expects errors on invalid unisex transform input?

If so it appears the errors are not properly caught, but I know next to nothing about testthats functionality for compiled code

@clauswilke
Copy link
Collaborator Author

This just shows how important a second pair of eyes is. You found the issue. If I comment out the following lines everything else works:
https://github.com/wilkelab/isoband/blob/70171cf6dae6fdd55f92b946eb04db8c9a41e97b/src/test-clip-lines.cpp#L372-L387
So it's the error that isn't properly caught. I can fix the problem by skipping these particular tests, but maybe @jimhester knows whether and how it's possible to test for errors in C++ code.

@clauswilke
Copy link
Collaborator Author

Ok, seems like expect_error() catches exceptions rather than calls to Rf_error():
https://testthat.r-lib.org/reference/use_catch.html#functions
Not sure why this has ever worked in the past.

Is it possible to write some C or C++ code that catches calls to Rf_error(), so we can convert that call into a bool that we can test with expect_true()?

@clauswilke
Copy link
Collaborator Author

I've simply disabled the tests for invalid input. So I'm going to close this issue. Updated version of isoband is on CRAN.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants