Skip to content

Commit

Permalink
extendrtests: added null externalptr test (extendr#769)
Browse files Browse the repository at this point in the history
* extendrtests: added null externalptr test
this happens when an externalptr is deserialized from `RDS` file or similar

* Update tests/extendrtests/tests/testthat/test-classes.R

Co-authored-by: Ilia Kosenkov <[email protected]>

---------

Co-authored-by: Ilia Kosenkov <[email protected]>
  • Loading branch information
CGMossa and Ilia-Kosenkov authored May 25, 2024
1 parent e03c9b7 commit 5caf7dc
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions tests/extendrtests/tests/testthat/test-classes.R
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,13 @@ test_that("Issue 431: Restore struct as ExternalPtr", {
y <- MyClass$restore_from_robj(x)
expect_equal(x$a(), y$a())
})

test_that("Error nicely with null externalptr", {
x <- MyClass$new()
x$set_a(42L)
null_x <- new("externalptr") # no attributes, null-ptr
attributes(null_x) <- attributes(x)
expect_error(
null_x$set_a(44L)
)
})

0 comments on commit 5caf7dc

Please sign in to comment.