From 1cb93b5094dc0a7f9f5b7730984f80053a2017b0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?I=C3=B1aki=20=C3=9Acar?= Date: Wed, 4 Sep 2024 17:35:41 +0200 Subject: [PATCH] add tests to check that void functions return invisibly --- inst/tinytest/test_module.R | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/inst/tinytest/test_module.R b/inst/tinytest/test_module.R index 361a801f0..960a33e96 100644 --- a/inst/tinytest/test_module.R +++ b/inst/tinytest/test_module.R @@ -22,11 +22,25 @@ if( ! Rcpp:::capabilities()[["Rcpp modules"]] ) exit_file("Skipping as no Module Rcpp::sourceCpp("cpp/Module.cpp") +# checks the presence of "invisible", added when the function returns void +is_void <- function(call) { + if (length(grep("invisible", deparse(call))) == 0) + return(FALSE) + return(TRUE) +} + # test.Module <- function(){ expect_equal( bar( 2L ), 4L ) expect_equal( foo( 2L, 10.0 ), 20.0 ) expect_equal( hello(), "hello" ) +expect_false(is_void(bar@.Data)) +expect_false(is_void(foo@.Data)) +expect_false(is_void(hello@.Data)) +expect_true(is_void(bla@.Data)) +expect_true(is_void(bla1@.Data)) +expect_true(is_void(bla2@.Data)) + w <- new( ModuleWorld ) expect_equal( w$greet(), "hello" ) w$set( "hello world" ) @@ -38,6 +52,12 @@ expect_equal( w$greet(), "hello world const ref" ) w$clear( ) expect_equal( w$greet(), "" ) +expect_false(is_void(w$greet)) +expect_true(is_void(w$set)) +expect_true(is_void(w$set_ref)) +expect_true(is_void(w$set_const_ref)) +expect_true(is_void(w$clear)) + # test.Module.exposed.class <- function(){ test <- new( ModuleTest, 3.0 ) expect_equal( Test_get_x_const_ref(test), 3.0 ) @@ -45,6 +65,11 @@ expect_equal( Test_get_x_const_pointer(test), 3.0 ) expect_equal( Test_get_x_ref(test), 3.0 ) expect_equal( Test_get_x_pointer(test), 3.0 ) +expect_false(is_void(Test_get_x_const_ref@.Data)) +expect_false(is_void(Test_get_x_const_pointer@.Data)) +expect_false(is_void(Test_get_x_ref@.Data)) +expect_false(is_void(Test_get_x_pointer@.Data)) + expect_equal( attr_Test_get_x_const_ref(test), 3.0 ) expect_equal( attr_Test_get_x_const_pointer(test), 3.0 ) expect_equal( attr_Test_get_x_ref(test), 3.0 )