Skip to content

Commit c90eea4

Browse files
committed
testthat 3e
1 parent dc93fb8 commit c90eea4

File tree

12 files changed

+731
-695
lines changed

12 files changed

+731
-695
lines changed

DESCRIPTION

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Package: cpp11
22
Title: A C++11 Interface for R's C Interface
3-
Version: 0.5.0.9000
3+
Version: 0.5.1
44
Authors@R:
55
c(
66
person("Davis", "Vaughan", email = "[email protected]", role = c("aut", "cre"), comment = c(ORCID = "0000-0003-4777-038X")),
@@ -31,7 +31,6 @@ Suggests:
3131
glue,
3232
knitr,
3333
lobstr,
34-
mockery,
3534
progress,
3635
rmarkdown,
3736
scales,
@@ -55,4 +54,4 @@ Config/Needs/cpp11/cpp_register:
5554
vctrs
5655
Encoding: UTF-8
5756
Roxygen: list(markdown = TRUE)
58-
RoxygenNote: 7.2.3
57+
RoxygenNote: 7.3.1

NEWS.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# cpp11 (development version)
22

3+
# cpp11 0.5.1
4+
5+
* Uses testthat 3e style tests (#402).
6+
* Removes the mockery dependence.
7+
* The vendoring function accepts a custom path (i.e., to use the GitHub version of the package)
8+
39
# cpp11 0.5.0
410

511
## R non-API related changes

R/source.R

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

166-
167-
168-
generate_include_paths <- function(packages) {
166+
generate_include_paths <- function(packages, custom_path = NULL) {
169167
out <- character(length(packages))
170168
for (i in seq_along(packages)) {
171-
path <- system.file(package = packages[[i]], "include")
169+
if (!is.null(custom_path)) {
170+
path <- custom_path
171+
} else {
172+
path <- system.file(package = packages[[i]], "include")
173+
}
174+
172175
if (is_windows()) {
173176
path <- utils::shortPathName(path)
174177
}

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)) {
@@ -39,16 +43,15 @@ cpp_vendor <- function(path = ".") {
3943

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

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

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

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

51-
files <- list.files(current, full.names = TRUE)
54+
files <- list.files(headers, full.names = TRUE)
5255

5356
writeLines(
5457
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)