Debian Codegraph @

tests/testthat/helper.R

raw
1 with_dir_tree <- function(files, code, base = tempfile()) {
2 if (is.null(names(files))) {
3 names(files) <- rep("", length(files))
4 }
5 dirs <- dirname(names(files))
6 unnamed <- dirs == ""
7 dirs[unnamed] <- files[unnamed]
8 files[unnamed] <- list(NULL)
9
10 dir_create(path(base, dirs))
11 old_wd <- setwd(base)
12 on.exit({
13 unlink(base, recursive = TRUE, force = TRUE)
14 setwd(old_wd)
15 })
16
17 for (i in seq_along(files)) {
18 if (!is.null(files[[i]])) {
19 writeLines(files[[i]], con = names(files)[[i]])
20 }
21 }
22 force(code)
23 }
24
25 expect_error_free <- function(...) {
26 expect_error(..., regexp = NA)
27 }
28
29 skip_if_not_utf8 <- function() {
30 skip_if_not(l10n_info()$`UTF-8`)
31 }
32
33 named_fs_path <- function(x) {
34 new_fs_path(stats::setNames(x, x))
35 }
36
37 transform_error <- function(x) {
38 sub("Error in `.*[(][)]`:", "Error:", x)
39 }
40
41 transform_path_max <- function(x) {
42 sub("PATH_MAX: [0-9]+", "PATH_MAX: <path-max>", x)
43 }