Skip to content

Commit e350bbf

Browse files
authored
Merge pull request #17 from pachadotdev/testthat3e
Testthat3e
2 parents e62c914 + bd5d79b commit e350bbf

File tree

12 files changed

+733
-686
lines changed

12 files changed

+733
-686
lines changed

DESCRIPTION

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ Suggests:
3131
glue,
3232
knitr,
3333
lobstr,
34-
mockery,
3534
progress,
3635
rmarkdown,
3736
scales,

NEWS.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,12 @@
44

55
* Fixed an issue related to `-Wdeprecated-literal-operator` (#447, @andrjohns).
66

7+
# cpp11 0.5.1.9000
8+
9+
* Uses testthat 3e style tests (#402).
10+
* Removes the mockery dependence.
11+
* The vendoring function accepts a custom path (i.e., to use the GitHub version of the package)
12+
713
# cpp11 0.5.1
814

915
* cpp11 now requires R >=4.0.0, in line with the

R/source.R

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -170,12 +170,15 @@ generate_cpp_name <- function(name, loaded_dlls = c("cpp11", names(getLoadedDLLs
170170
sprintf("%s.%s", new_name, ext)
171171
}
172172

173-
174-
175-
generate_include_paths <- function(packages) {
173+
generate_include_paths <- function(packages, custom_path = NULL) {
176174
out <- character(length(packages))
177175
for (i in seq_along(packages)) {
178-
path <- system.file(package = packages[[i]], "include")
176+
if (!is.null(custom_path)) {
177+
path <- custom_path
178+
} else {
179+
path <- system.file(package = packages[[i]], "include")
180+
}
181+
179182
if (is_windows()) {
180183
path <- utils::shortPathName(path)
181184
}

R/vendor.R

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@
1616
#' code until you run `cpp_vendor()` again.
1717
#'
1818
#' @inheritParams cpp_register
19+
#' @param headers The path to the cpp11 headers to vendor. By default this is
20+
#' the path where R installed the cpp11 package. You can change this to
21+
#' use a different version of cpp11, such as as the development version
22+
#' from GitHub.
1923
#' @return The file path to the vendored code (invisibly).
2024
#' @export
2125
#' @examples
@@ -30,7 +34,7 @@
3034
#'
3135
#' # cleanup
3236
#' unlink(dir, recursive = TRUE)
33-
cpp_vendor <- function(path = ".") {
37+
cpp_vendor <- function(path = ".", headers = system.file("include", "cpp11", package = "cpp11")) {
3438
new <- file.path(path, "inst", "include", "cpp11")
3539

3640
if (dir.exists(new)) {
@@ -40,16 +44,15 @@ cpp_vendor <- function(path = ".") {
4044

4145
dir.create(new , recursive = TRUE, showWarnings = FALSE)
4246

43-
current <- system.file("include", "cpp11", package = "cpp11")
44-
if (!nzchar(current)) {
47+
if (!nzchar(headers)) {
4548
stop("cpp11 is not installed", call. = FALSE)
4649
}
4750

4851
cpp11_version <- utils::packageVersion("cpp11")
4952

5053
cpp11_header <- sprintf("// cpp11 version: %s\n// vendored on: %s", cpp11_version, Sys.Date())
5154

52-
files <- list.files(current, full.names = TRUE)
55+
files <- list.files(headers, full.names = TRUE)
5356

5457
writeLines(
5558
c(cpp11_header, readLines(system.file("include", "cpp11.hpp", package = "cpp11"))),

man/cpp_vendor.Rd

Lines changed: 9 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/testthat.R

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
# This file is part of the standard setup for testthat.
2+
# It is recommended that you do not modify it.
3+
#
4+
# Where should you do additional test configuration?
5+
# Learn more about the roles of various files in:
6+
# * https://r-pkgs.org/testing-design.html#sec-tests-files-overview
7+
# * https://testthat.r-lib.org/articles/special-files.html
8+
19
library(testthat)
210
library(cpp11)
311

tests/testthat/_snaps/register.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# get_call_entries: returns an empty string for packages with .Call entries and NAMESPACE files
1+
# get_call_entries returns an empty string for packages with .Call entries and NAMESPACE files
22

33
Code
44
call_entries
@@ -11,7 +11,7 @@
1111
[6] " {NULL, NULL, 0}"
1212
[7] "};"
1313

14-
# get_call_entries: works with multiple register functions.
14+
# get_call_entries works with multiple register functions
1515

1616
Code
1717
cat(read_file(cpp_bindings))
@@ -60,7 +60,7 @@
6060
R_forceSymbols(dll, TRUE);
6161
}
6262

63-
# cpp_register: works with a package that registers a single c++ function
63+
# cpp_register works with a package that registers a single C++ function
6464

6565
Code
6666
cat(read_file(r_bindings))
@@ -104,7 +104,7 @@
104104
R_forceSymbols(dll, TRUE);
105105
}
106106

107-
# cpp_register: can be run with messages
107+
# cpp_register can be run with messages
108108

109109
Code
110110
cpp_register(p, quiet = FALSE)

tests/testthat/test-knitr.R

Lines changed: 18 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,22 @@
1-
describe("eng_cpp11", {
2-
it("works when code is not evaluated", {
3-
skip_on_os("solaris")
4-
opts <- knitr::opts_chunk$get()
5-
opts <- utils::modifyList(opts, list(eval = FALSE, engine = "cpp11", code = "1 + 1"))
1+
test_that("eng_cpp11 works when code is not evaluated", {
2+
skip_on_os("solaris")
3+
opts <- knitr::opts_chunk$get()
4+
opts <- utils::modifyList(opts, list(eval = FALSE, engine = "cpp11", code = "1 + 1"))
65

7-
expect_equal(
8-
eng_cpp11(opts),
9-
"1 + 1"
10-
)
11-
})
6+
expect_equal(
7+
eng_cpp11(opts),
8+
"1 + 1"
9+
)
10+
})
1211

13-
it("works when code is evaluated", {
14-
skip_on_os("solaris")
15-
opts <- knitr::opts_chunk$get()
16-
code <- "[[cpp11::register]] int foo() { return 0; }"
17-
opts <- utils::modifyList(opts, list(eval = TRUE, engine = "cpp11", code = code, quiet = TRUE))
12+
test_that("eng_cpp11 works when code is evaluated", {
13+
skip_on_os("solaris")
14+
opts <- knitr::opts_chunk$get()
15+
code <- "[[cpp11::register]] int foo() { return 0; }"
16+
opts <- utils::modifyList(opts, list(eval = TRUE, engine = "cpp11", code = code, quiet = TRUE))
1817

19-
expect_equal(
20-
eng_cpp11(opts),
21-
code
22-
)
23-
})
18+
expect_equal(
19+
eng_cpp11(opts),
20+
code
21+
)
2422
})

0 commit comments

Comments
 (0)