Skip to content

Commit

Permalink
test-vendor
Browse files Browse the repository at this point in the history
  • Loading branch information
pachadotdev committed Jan 30, 2024
1 parent 02fe578 commit ec46e62
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 21 deletions.
17 changes: 1 addition & 16 deletions R/vendor.R
Original file line number Diff line number Diff line change
Expand Up @@ -32,22 +32,7 @@
#' unlink(dir, recursive = TRUE)
cpp_vendor <- function(path = "./src/vendor") {
if (dir.exists(path)) {
cat(
sprintf(
"The directory '%s' already exists. Do you want to overwrite it?\n",
path
)
)
if (interactive()) {
if (utils::menu(c("Yes", "No"), graphics = FALSE) == 1L) {
unlink(path, recursive = TRUE)
} else {
return(FALSE)
}
} else {
message("Running in non-interactive mode. Exiting.")
return(FALSE)
}
stop("'", path, "' already exists\n * run unlink('", path, "', recursive = TRUE)", call. = FALSE)
}

dir.create(path, recursive = TRUE, showWarnings = FALSE)
Expand Down
9 changes: 9 additions & 0 deletions tests/testthat/_snaps/register.new.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# cpp_register: can be run with messages

Code
cpp_register(p, quiet = FALSE)
Message
i 1 functions decorated with [[cpp11::register]]
v generated file 'cpp11.R'
v generated file 'cpp11.cpp'

5 changes: 3 additions & 2 deletions tests/testthat/_snaps/source.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@

Code
cpp_source(i_do_not_exist)
Error <simpleError>
Can't find `file` at this path:
Condition
Error:
! Can't find `file` at this path:
{NON_EXISTENT_FILEPATH}

6 changes: 3 additions & 3 deletions tests/testthat/test-vendor.R
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,17 @@ describe("cpp_vendor", {
pkg <- local_package()
mockery::stub(cpp_vendor, "system.file", "")
expect_error(
cpp_vendor(pkg_path(pkg)),
cpp_vendor(paste0(pkg_path(pkg), "/src/vendor")),
"cpp11 is not installed"
)
})

it("errors if cpp11 is already vendored", {
pkg <- local_package()
cpp_vendor(pkg_path(pkg))
cpp_vendor(paste0(pkg_path(pkg), "/src/vendor"))

expect_error(
cpp_vendor(pkg_path(pkg)),
cpp_vendor(paste0(pkg_path(pkg), "/src/vendor")),
"already exists"
)
})
Expand Down

0 comments on commit ec46e62

Please sign in to comment.