-
-
Notifications
You must be signed in to change notification settings - Fork 221
Additional tests for attributes #1446
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,13 @@ | ||
| 2026-01-13 Dirk Eddelbuettel <[email protected]> | ||
|
|
||
| * inst/tinytest/cpp/attributes_extended.cpp: New unit tests | ||
| * inst/tinytest/test_attributes_extended.R: Idem | ||
| * inst/tinytest/test_compile_attributes_errors.R: Idem | ||
| * inst/tinytest/test_cppfunction_errors.R: Idem | ||
| * inst/tinytest/test_sourcecpp_errors.R: Idem | ||
| * R/Attributes.R: Remove #nocov tags | ||
| * src/attributes.cpp: Idem | ||
|
|
||
| 2026-01-12 Dirk Eddelbuettel <[email protected]> | ||
|
|
||
| * DESCRIPTION (Version, Date): Roll micro version and date | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,49 @@ | ||
| #include <Rcpp.h> | ||
| using namespace Rcpp; | ||
|
|
||
| // Test 4.1: Named Export Parameter | ||
| // Coverage target: src/attributes.cpp:360 | ||
|
|
||
| // [[Rcpp::export(name = "custom_exported_name")]] | ||
| int test_named_export() { return 123; } | ||
|
|
||
| // [[Rcpp::export(name = "another.custom.name")]] | ||
| std::string test_named_export_with_dots() { return "dotted name"; } | ||
|
|
||
| // Test 4.2: Unnamed Export Parameter | ||
| // Coverage target: src/attributes.cpp:365 | ||
|
|
||
| // [[Rcpp::export(my_custom_name)]] | ||
| int test_unnamed_export_param() { return 456; } | ||
|
|
||
| // Test 4.3: RNG Parameter Variations | ||
| // Coverage target: src/attributes.cpp:382-383 | ||
|
|
||
| // [[Rcpp::export(rng = true)]] | ||
| int test_rng_lowercase_true() { return 789; } | ||
|
|
||
| // [[Rcpp::export(rng = TRUE)]] | ||
| int test_rng_uppercase_true() { return 101; } | ||
|
|
||
| // [[Rcpp::export(rng = false)]] | ||
| int test_rng_lowercase_false() { return 202; } | ||
|
|
||
| // Test 4.4: Invisible Parameter Variations | ||
| // Coverage target: src/attributes.cpp:391-392 | ||
|
|
||
| // [[Rcpp::export(invisible = true)]] | ||
| void test_invisible_lowercase_true() { | ||
| // Side effect only - returns invisibly | ||
| } | ||
|
|
||
| // [[Rcpp::export(invisible = TRUE)]] | ||
| void test_invisible_uppercase_true() { | ||
| // Side effect only - returns invisibly | ||
| } | ||
|
|
||
| // Test 4.5: exportedCppName with Dots | ||
| // Coverage target: src/attributes.cpp:373-377 | ||
| // This tests the conversion of dots to underscores in C++ names | ||
|
|
||
| // [[Rcpp::export(name = "test.with.dots")]] | ||
| int test_cpp_name_conversion() { return 999; } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| ## Copyright (C) 2026 Dirk Eddelbuettel | ||
| ## | ||
| ## This file is part of Rcpp. | ||
| ## | ||
| ## Rcpp is free software: you can redistribute it and/or modify it | ||
| ## under the terms of the GNU General Public License as published by | ||
| ## the Free Software Foundation, either version 2 of the License, or | ||
| ## (at your option) any later version. | ||
| ## | ||
| ## Rcpp is distributed in the hope that it will be useful, but | ||
| ## WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| ## GNU General Public License for more details. | ||
| ## | ||
| ## You should have received a copy of the GNU General Public License | ||
| ## along with Rcpp. If not, see <http://www.gnu.org/licenses/>. | ||
|
|
||
| if (Sys.getenv("RunAllRcppTests") != "yes") exit_file("Set 'RunAllRcppTests' to 'yes' to run.") | ||
|
|
||
| Rcpp::sourceCpp("cpp/attributes_extended.cpp") | ||
|
|
||
| ## Test named exports | ||
| expect_equal(custom_exported_name(), 123) | ||
| expect_equal(another.custom.name(), "dotted name") | ||
|
|
||
| ## Test unnamed export parameter | ||
| expect_equal(my_custom_name(), 456) | ||
|
|
||
| ## Test RNG parameters | ||
| expect_equal(test_rng_lowercase_true(), 789) | ||
| expect_equal(test_rng_uppercase_true(), 101) | ||
| expect_equal(test_rng_lowercase_false(), 202) | ||
|
Comment on lines
+30
to
+32
|
||
|
|
||
| ## Test invisible parameters (should return invisibly) | ||
| result1 <- withVisible(test_invisible_lowercase_true()) | ||
| expect_false(result1$visible) | ||
|
|
||
| result2 <- withVisible(test_invisible_uppercase_true()) | ||
| expect_false(result2$visible) | ||
|
|
||
| ## Test C++ name conversion (dots to underscores) | ||
| expect_equal(test.with.dots(), 999) | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| ## Copyright (C) 2026 Dirk Eddelbuettel | ||
| ## | ||
| ## This file is part of Rcpp. | ||
| ## | ||
| ## Rcpp is free software: you can redistribute it and/or modify it | ||
| ## under the terms of the GNU General Public License as published by | ||
| ## the Free Software Foundation, either version 2 of the License, or | ||
| ## (at your option) any later version. | ||
| ## | ||
| ## Rcpp is distributed in the hope that it will be useful, but | ||
| ## WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| ## GNU General Public License for more details. | ||
| ## | ||
| ## You should have received a copy of the GNU General Public License | ||
| ## along with Rcpp. If not, see <http://www.gnu.org/licenses/>. | ||
|
|
||
| if (Sys.getenv("RunAllRcppTests") != "yes") exit_file("Set 'RunAllRcppTests' to 'yes' to run.") | ||
|
|
||
| ## Test 3.1: Missing DESCRIPTION File | ||
| ## Coverage target: R/Attributes.R:420 | ||
| tmpdir <- tempfile() | ||
| dir.create(tmpdir) | ||
| expect_error(compileAttributes(tmpdir), "must refer to the directory containing an R package") | ||
| unlink(tmpdir, recursive = TRUE) | ||
|
|
||
| ## Test 3.2: Missing NAMESPACE File | ||
| ## Coverage target: R/Attributes.R:432 | ||
| tmpdir <- tempfile() | ||
| dir.create(tmpdir) | ||
| writeLines("Package: TestPkg", file.path(tmpdir, "DESCRIPTION")) | ||
| expect_error(compileAttributes(tmpdir), "must refer to the directory containing an R package") | ||
| unlink(tmpdir, recursive = TRUE) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| ## Copyright (C) 2026 Dirk Eddelbuettel | ||
| ## | ||
| ## This file is part of Rcpp. | ||
| ## | ||
| ## Rcpp is free software: you can redistribute it and/or modify it | ||
| ## under the terms of the GNU General Public License as published by | ||
| ## the Free Software Foundation, either version 2 of the License, or | ||
| ## (at your option) any later version. | ||
| ## | ||
| ## Rcpp is distributed in the hope that it will be useful, but | ||
| ## WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| ## GNU General Public License for more details. | ||
| ## | ||
| ## You should have received a copy of the GNU General Public License | ||
| ## along with Rcpp. If not, see <http://www.gnu.org/licenses/>. | ||
|
|
||
| if (Sys.getenv("RunAllRcppTests") != "yes") exit_file("Set 'RunAllRcppTests' to 'yes' to run.") | ||
|
|
||
| ## Test 2.1: No Function Definition | ||
| ## Coverage target: R/Attributes.R:326 | ||
| code <- "int x = 5;" # No function, just a variable | ||
| expect_error(cppFunction(code), "No function definition found") | ||
|
|
||
| ## Test 2.2: Multiple Function Definitions | ||
| ## Coverage target: R/Attributes.R:328 | ||
| code <- " | ||
| // [[Rcpp::export]] | ||
| int foo() { return 1; } | ||
| // [[Rcpp::export]] | ||
| int bar() { return 2; } | ||
| " | ||
| ## compilation dies sooner so we never actually see the messages | ||
| expect_error(cppFunction(code)) #, "More than one function definition") | ||
|
Comment on lines
+34
to
+35
|
||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,42 @@ | ||||||
| ## Copyright (C) 2026 Dirk Eddelbuettel | ||||||
| ## | ||||||
| ## This file is part of Rcpp. | ||||||
| ## | ||||||
| ## Rcpp is free software: you can redistribute it and/or modify it | ||||||
| ## under the terms of the GNU General Public License as published by | ||||||
| ## the Free Software Foundation, either version 2 of the License, or | ||||||
| ## (at your option) any later version. | ||||||
| ## | ||||||
| ## Rcpp is distributed in the hope that it will be useful, but | ||||||
| ## WITHOUT ANY WARRANTY; without even the implied warranty of | ||||||
| ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||||||
| ## GNU General Public License for more details. | ||||||
| ## | ||||||
| ## You should have received a copy of the GNU General Public License | ||||||
| ## along with Rcpp. If not, see <http://www.gnu.org/licenses/>. | ||||||
|
|
||||||
| if (Sys.getenv("RunAllRcppTests") != "yes") exit_file("Set 'RunAllRcppTests' to 'yes' to run.") | ||||||
|
|
||||||
| ## Test 1.1: Invalid File Extension | ||||||
| ## Coverage target: R/Attributes.R:58-61 | ||||||
| tmpfile <- tempfile(fileext = ".c") | ||||||
| writeLines("int main() { return 0; }", tmpfile) | ||||||
| expect_error(sourceCpp(tmpfile), "does not have an extension of .cc or .cpp") | ||||||
|
||||||
| expect_error(sourceCpp(tmpfile), "does not have an extension of .cc or .cpp") | |
| expect_error(sourceCpp(tmpfile), "does not have an extension of \\.cc or \\.cpp") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The indentation uses tabs instead of spaces. The codebase appears to use spaces for indentation. Consider using consistent spacing (tabs should generally be avoided in favor of spaces).