|
41 | 41 | expect_true(is_void(bla1@.Data)) |
42 | 42 | expect_true(is_void(bla2@.Data)) |
43 | 43 |
|
| 44 | +## module functions must be called with at least as many arguments as |
| 45 | +## the C++ function takes, rather than reading the missing ones from |
| 46 | +## uninitialized memory (#1521) |
| 47 | +expect_error( foo( 2L ), "expecting 2, got 1" ) |
| 48 | +expect_error( bar(), "expecting 1, got 0" ) |
| 49 | +expect_equal( foo_formals(), 20.0 ) |
| 50 | +expect_equal( foo_formals( y = 3.0 ), 6.0 ) |
| 51 | +expect_error( foo_short_formals(), "expecting 2, got 1" ) |
| 52 | + |
| 53 | +## formals<- finds the .External() call wherever it is in the body, e.g. |
| 54 | +## inside the block that coverage tools (covr) wrap each statement in |
| 55 | +wrapped <- quote({ if (TRUE) { covr:::count("key"); .External(entry, pointer, ...) } }) |
| 56 | +expect_equal( deparse( Rcpp:::.cppfunction_set_external_args( wrapped, c("x", "y") ) ), |
| 57 | + deparse( quote({ if (TRUE) { covr:::count("key"); .External(entry, pointer, x, y) } }) ) ) |
| 58 | + |
44 | 59 | w <- new( ModuleWorld ) |
45 | 60 | expect_equal( w$greet(), "hello" ) |
46 | 61 | w$set( "hello world" ) |
@@ -85,6 +100,27 @@ expect_equal( w$x, 2.0 ) |
85 | 100 |
|
86 | 101 | expect_error( { w$y <- 3 } ) |
87 | 102 |
|
| 103 | +## every class_::property() overload; the free getter + member setter one |
| 104 | +## did not return *this, which aborted loading the whole module (#1519) |
| 105 | +p <- new( ModuleProperties ) |
| 106 | +p$get_set <- 1.0 |
| 107 | +expect_equal( p$get_set, 1.0 ) |
| 108 | +p$get_const_set <- 2.0 |
| 109 | +expect_equal( p$get_const_set, 2.0 ) |
| 110 | +p$get_set_free <- 3.0 |
| 111 | +expect_equal( p$get_set_free, 3.0 ) |
| 112 | +p$get_const_set_free <- 4.0 |
| 113 | +expect_equal( p$get_const_set_free, 4.0 ) |
| 114 | +p$get_free_set <- 5.0 |
| 115 | +expect_equal( p$get_free_set, 5.0 ) |
| 116 | +p$get_free_set_free <- 6.0 |
| 117 | +expect_equal( p$get_free_set_free, 6.0 ) |
| 118 | + |
| 119 | +expect_equal( c(p$get, p$get_const, p$get_free), c(6.0, 6.0, 6.0) ) |
| 120 | +expect_error( { p$get <- 7.0 } ) |
| 121 | +expect_error( { p$get_const <- 7.0 } ) |
| 122 | +expect_error( { p$get_free <- 7.0 } ) |
| 123 | + |
88 | 124 | # test.Module.member <- function(){ |
89 | 125 | w <- new( ModuleNumber ) |
90 | 126 | expect_equal( w$x, 0.0 ) |
@@ -123,3 +159,10 @@ gctorture(TRUE) |
123 | 159 | res <- gadget$value() |
124 | 160 | gctorture(FALSE) |
125 | 161 | expect_identical( res, c(1, 2, 3) ) |
| 162 | + |
| 163 | +# test.Module.finalize.dummy <- function(){ |
| 164 | +## an object created without arguments for a class lacking a default |
| 165 | +## constructor holds the dummy pointer; finalizing it must be a no-op |
| 166 | +## rather than an error (which used to surface at garbage collection) |
| 167 | +r <- new( ModuleRandomizer ) |
| 168 | +expect_identical( r$finalize(), NULL ) |
0 commit comments