Skip to content

Conversation

@eddelbuettel
Copy link
Member

This pull request is a bit of an experiment in that I asked Claude Sonnet 4.5 (via the Google Antigravity IDE, another Code clone) to examine existing #nocov tags and fill in some tests. And so it did which we can now look at in more detail.

It is all fairly reasonable if pedestrian (i.e. checking on Windows for permitted filenames etc) but does exactly what it was asked: increase coverage of tests across the codebase by a bit. If we like this we can repeat as this touched only one C++ and one R file so far (for attributes, in this case).

I did one minimal round of postprocessing so far. In one case we still need the #nocov: the windows-specific code will never run under Linux coverage analysis. And one expected error does not materialize as the compilation fails (cannot have two functions in cppFunction() call).

Checklist

  • Code compiles correctly
  • R CMD check still passes all tests
  • Preferably, new tests were added which fail without the change
  • Document the changes by file in ChangeLog

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This pull request adds comprehensive test coverage for the Rcpp attributes system to increase code coverage and remove #nocov tags from previously untested code paths. The tests target specific error conditions and parameter variations in the attributes functionality.

Changes:

  • Added four new test files covering error conditions and attribute parameter variations
  • Removed #nocov tags from src/attributes.cpp and R/Attributes.R where new tests now provide coverage
  • Retained #nocov tags for platform-specific code that cannot be tested under Linux coverage analysis

Reviewed changes

Copilot reviewed 8 out of 8 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
src/attributes.cpp Removed #nocov tags from exportedName, exportedCppName, rng, and invisible methods now covered by tests
R/Attributes.R Removed #nocov tags from error paths and parameter validation, kept tags for Windows-specific code
inst/tinytest/test_sourcecpp_errors.R New tests for sourceCpp error conditions (invalid extensions, filenames with spaces, windowsDebugDLL)
inst/tinytest/test_cppfunction_errors.R New tests for cppFunction error conditions (no function, multiple functions)
inst/tinytest/test_compile_attributes_errors.R New tests for compileAttributes error conditions (missing DESCRIPTION/NAMESPACE)
inst/tinytest/test_attributes_extended.R New tests for attribute parameter variations (named exports, RNG, invisible)
inst/tinytest/cpp/attributes_extended.cpp C++ test code with various Rcpp export attribute configurations
ChangeLog Documents the addition of new test files and removal of #nocov tags

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +34 to +35
## compilation dies sooner so we never actually see the messages
expect_error(cppFunction(code)) #, "More than one function definition")
Copy link

Copilot AI Jan 16, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The test for multiple function definitions (line 328 in R/Attributes.R) does not actually verify the intended error message. The comment on line 34 indicates compilation fails before reaching this check, so the #nocov tag should remain on line 328 of R/Attributes.R. Either enhance the test to properly trigger the error condition or revert the #nocov removal.

Copilot uses AI. Check for mistakes.
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this has already been done

if (grepl(' ', basename(file), fixed=TRUE)) { # #nocov start
stop("The filename '", basename(file), "' contains spaces. This ",
"is not permitted.")
"is not permitted.") # #nocov end
Copy link

Copilot AI Jan 16, 2026

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).

Suggested change
"is not permitted.") # #nocov end
"is not permitted.") # #nocov end

Copilot uses AI. Check for mistakes.
## 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")
Copy link

Copilot AI Jan 16, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The error message pattern uses '.cc' which should be '\.cc' to properly escape the dot in regex matching. The same applies to '.cpp'. While this may work due to partial matching, it's technically incorrect as '.' matches any character in regex.

Suggested change
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")

Copilot uses AI. Check for mistakes.
Comment on lines +30 to +32
expect_equal(test_rng_lowercase_true(), 789)
expect_equal(test_rng_uppercase_true(), 101)
expect_equal(test_rng_lowercase_false(), 202)
Copy link

Copilot AI Jan 16, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These tests verify that functions with different RNG parameter values execute successfully, but they don't actually verify that the RNG behavior differs. The tests only check return values, not whether RNG state management is correctly applied based on the parameter.

Copilot uses AI. Check for mistakes.
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

Successfully merging this pull request may close these issues.

2 participants