diff --git a/.Rbuildignore b/.Rbuildignore index f972cfa65..17a7bd594 100644 --- a/.Rbuildignore +++ b/.Rbuildignore @@ -24,3 +24,4 @@ ^internal$ ^revdep-cloud$ ^CRAN-SUBMISSION$ +^\.vscode$ diff --git a/NEWS.md b/NEWS.md index a819c3eb8..0546860e7 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,5 +1,7 @@ # usethis (development version) +* `use_cpp11()` now automatically updates the `NAMESPACE` (@pachadotdev, #1921). + # usethis 2.2.2 * Implicit usage of `numeric_version()` via comparison now always provides diff --git a/R/cpp11.R b/R/cpp11.R index 0d93fd075..56d4de224 100644 --- a/R/cpp11.R +++ b/R/cpp11.R @@ -12,6 +12,7 @@ use_cpp11 <- function() { check_installed("cpp11") check_is_package("use_cpp11()") check_uses_roxygen("use_cpp11()") + check_has_package_doc("use_cpp11()") use_src() use_dependency("cpp11", "LinkingTo") @@ -24,6 +25,11 @@ use_cpp11 <- function() { check_cpp_register_deps() + roxygen_ns_append( + sprintf("@useDynLib %s, .registration = TRUE", project_name()) + ) + roxygen_update_ns() + invisible() } diff --git a/tests/testthat/test-cpp11.R b/tests/testthat/test-cpp11.R index 128dca1d0..b26be2060 100644 --- a/tests/testthat/test-cpp11.R +++ b/tests/testthat/test-cpp11.R @@ -7,10 +7,14 @@ test_that("use_cpp11() requires a package", { test_that("use_cpp11() creates files/dirs, edits DESCRIPTION and .gitignore", { create_local_package() use_roxygen_md() + use_package_doc() local_interactive(FALSE) local_check_installed() - local_mocked_bindings(check_cpp_register_deps = function() invisible()) + local_mocked_bindings( + check_cpp_register_deps = function() invisible() + # project_name = function() "testpkg" + ) use_cpp11() @@ -21,6 +25,9 @@ test_that("use_cpp11() creates files/dirs, edits DESCRIPTION and .gitignore", { ignores <- read_utf8(proj_path("src", ".gitignore")) expect_true(all(c("*.o", "*.so", "*.dll") %in% ignores)) + + namespace <- read_utf8(proj_path("NAMESPACE")) + expect_true(any(grepl("useDynLib", namespace))) }) test_that("check_cpp_register_deps is silent if all installed, emits todo if not", {