Skip to content
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

cpp_register(quiet=) set to TRUE on non-interactive session (incl testthat runs) #289

Merged
merged 7 commits into from
Oct 10, 2022
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ Config/Needs/cpp11/cpp_register:
vctrs
Encoding: UTF-8
Roxygen: list(markdown = TRUE)
RoxygenNote: 7.1.2
RoxygenNote: 7.2.1
SystemRequirements: C++11
Remotes:
r-lib/testthat@ad8b726d1734c59ed08ec7d11df4a3d76d8e69df
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

* `cpp_source()` errors on non-existent file (#261).

* `cpp_register()` is quiet by default when R is non interactive.
romainfrancois marked this conversation as resolved.
Show resolved Hide resolved

# cpp11 0.4.2

* Romain François is now the maintainer.
Expand Down
4 changes: 2 additions & 2 deletions R/register.R
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
#'
#' # cleanup
#' unlink(dir, recursive = TRUE)
cpp_register <- function(path = ".", quiet = FALSE) {
cpp_register <- function(path = ".", quiet = !is_interactive()) {
stop_unless_installed(get_cpp_register_needs())

r_path <- file.path(path, "R", "cpp11.R")
Expand Down Expand Up @@ -138,7 +138,7 @@ cpp_register <- function(path = ".", quiet = FALSE) {

utils::globalVariables(c("name", "return_type", "line", "decoration", "context", ".", "functions", "res"))

get_registered_functions <- function(decorations, tag, quiet = FALSE) {
get_registered_functions <- function(decorations, tag, quiet = !is_interactive()) {
if (NROW(decorations) == 0) {
return(tibble::tibble(file = character(), line = integer(), decoration = character(), params = list(), context = list(), name = character(), return_type = character(), args = list()))
}
Expand Down
2 changes: 1 addition & 1 deletion R/source.R
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ cpp_source <- function(file, code = NULL, env = parent.frame(), clean = TRUE, qu
check_valid_attributes(all_decorations, file = orig_file_path)

cli_suppress(
funs <- get_registered_functions(all_decorations, "cpp11::register")
funs <- get_registered_functions(all_decorations, "cpp11::register", quiet = quiet)
)
romainfrancois marked this conversation as resolved.
Show resolved Hide resolved
cpp_functions_definitions <- generate_cpp_functions(funs, package = package)

Expand Down
2 changes: 1 addition & 1 deletion man/cpp_register.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion tests/testthat/helper.R
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ pkg_path <- function(pkg) {

get_funs <- function(path) {
all_decorations <- decor::cpp_decorations(path, is_attribute = TRUE)
get_registered_functions(all_decorations, "cpp11::register", quiet = FALSE)
get_registered_functions(all_decorations, "cpp11::register", quiet = TRUE)
}

get_package_name <- function(path) {
Expand Down
10 changes: 8 additions & 2 deletions tests/testthat/test-register.R
Original file line number Diff line number Diff line change
Expand Up @@ -614,12 +614,18 @@ extern \"C\" attribute_visible void R_init_testPkg(DllInfo* dll){
})


it("can be run with messages, by default", {
it("can be run with messages", {
pkg <- local_package()
p <- pkg_path(pkg)
dir.create(file.path(p, "src"))
file.copy(test_path("single.cpp"), file.path(p, "src", "single.cpp"))
expect_message(cpp_register(p), "1 functions decorated with [[cpp11::register]]", fixed = TRUE)
suppressMessages(
# cpp_register() sends 3 messages, but expect_message() only checks
# for one, so suppress the other ones, so that they don't appear in the
# testthat output
expect_message(
cpp_register(p, quiet = FALSE), "1 functions decorated with [[cpp11::register]]", fixed = TRUE)
)
romainfrancois marked this conversation as resolved.
Show resolved Hide resolved
})

it("includes pkg_types.h if included in src", {
Expand Down