Skip to content

Commit

Permalink
follow @jennybc advice
Browse files Browse the repository at this point in the history
  • Loading branch information
pachadotdev committed Feb 14, 2024
1 parent 175bf64 commit 9b3cb21
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 8 deletions.
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
5 changes: 5 additions & 0 deletions R/cpp11.R
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -24,6 +25,10 @@ use_cpp11 <- function() {

check_cpp_register_deps()

roxygen_ns_append(
sprintf("@useDynLib %s, .registration = TRUE", project_name())
) && roxygen_remind()

invisible()
}

Expand Down
21 changes: 13 additions & 8 deletions tests/testthat/test-cpp11.R
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,25 @@ 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())

use_cpp11()
with_mock(
`cpp11::stop_unless_installed` = function(package) TRUE,
{
use_cpp11()

deps <- proj_deps()
expect_equal(deps$type, "LinkingTo")
expect_equal(deps$package, "cpp11")
expect_proj_dir("src")
deps <- proj_deps()
expect_equal(deps$type, "LinkingTo")
expect_equal(deps$package, "cpp11")
expect_proj_dir("src")

ignores <- read_utf8(proj_path("src", ".gitignore"))
expect_contains(ignores, c("*.o", "*.so", "*.dll"))
ignores <- read_utf8(proj_path("src", ".gitignore"))
expect_contains(ignores, c("*.o", "*.so", "*.dll"))
}
)
})

test_that("check_cpp_register_deps is silent if all installed, emits todo if not", {
Expand Down

0 comments on commit 9b3cb21

Please sign in to comment.