Skip to content

Commit d4ff71d

Browse files
authored
Merge branch 'main' into 188_cli_wrapper_exts
2 parents 9946e25 + 2a0cd7c commit d4ff71d

File tree

3 files changed

+61
-31
lines changed

3 files changed

+61
-31
lines changed

DESCRIPTION

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,9 @@ Imports:
2929
utils,
3030
yaml
3131
Suggests:
32+
callr,
3233
curl,
34+
dplyr,
3335
flextable,
3436
ggiraph,
3537
ggplot2,
@@ -38,6 +40,7 @@ Suggests:
3840
knitr,
3941
palmerpenguins,
4042
patchwork,
43+
pkgload,
4144
plotly,
4245
rsconnect (>= 0.8.26),
4346
testthat (>= 3.1.7),

tests/testthat/helper.R

Lines changed: 44 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,13 @@ local_quarto_project <- function(
9191
return(file.path(path_tmp, name))
9292
}
9393

94-
.render <- function(input, output_file = NULL, ..., .env = parent.frame()) {
94+
.render <- function(
95+
input,
96+
output_file = NULL,
97+
...,
98+
.quiet = TRUE,
99+
.env = parent.frame()
100+
) {
95101
skip_if_no_quarto()
96102
skip_if_not_installed("withr")
97103
# work inside input directory
@@ -102,7 +108,12 @@ local_quarto_project <- function(
102108
.local_envir = .env
103109
))
104110
}
105-
quarto_render(basename(input), output_file = output_file, quiet = TRUE, ...)
111+
expect_no_error(quarto_render(
112+
basename(input),
113+
output_file = output_file,
114+
quiet = .quiet,
115+
...
116+
))
106117
expect_true(file.exists(output_file))
107118
normalizePath(output_file)
108119
}
@@ -240,3 +251,34 @@ local_quarto_run_echo_cmd <- function(.env = parent.frame()) {
240251
withr::local_options(quarto.echo_cmd = TRUE, .local_envir = .env)
241252
}
242253
}
254+
255+
quick_install <- function(package, lib, quiet = TRUE) {
256+
skip_if_not_installed("callr")
257+
opts <- c(
258+
"--data-compress=none",
259+
"--no-byte-compile",
260+
"--no-data",
261+
"--no-demo",
262+
"--no-docs",
263+
"--no-help",
264+
"--no-html",
265+
"--no-libs",
266+
"--use-vanilla",
267+
sprintf("--library=%s", lib),
268+
package
269+
)
270+
invisible(callr::rcmd("INSTALL", opts, show = !quiet, fail_on_status = TRUE))
271+
}
272+
273+
install_dev_package <- function(.local_envir = parent.frame()) {
274+
# if not inside of R CMD check, install dev version into temp directory
275+
if (Sys.getenv("_R_CHECK_TIMINGS_") == "") {
276+
skip_if_not_installed("pkgload")
277+
withr::local_temp_libpaths(.local_envir = .local_envir)
278+
quick_install(pkgload::pkg_path("."), lib = .libPaths()[1])
279+
withr::local_envvar(
280+
R_LIBS = paste0(.libPaths(), collapse = .Platform$path.sep),
281+
.local_envir = .local_envir
282+
)
283+
}
284+
}

tests/testthat/test-theme.R

Lines changed: 14 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,31 @@
1+
# don't run on CRAN - this require installed Quarto version with the right version of the quarto package.
2+
skip_on_cran()
3+
skip_if_no_quarto()
4+
skip_if_not_installed("withr")
5+
6+
# We need to install the package in a temporary library when we are in dev mode
7+
install_dev_package()
8+
19
test_that("render flextable", {
2-
skip_if_no_quarto()
3-
quarto_render("theme/flextable.qmd", quiet = TRUE)
4-
expect_true(file.exists("theme/flextable.html"))
5-
unlink("theme/flextable.html")
10+
.render(test_path("theme/flextable.qmd"))
611
})
712

8-
913
test_that("render ggiraph", {
10-
skip_if_no_quarto()
11-
quarto_render("theme/ggiraph.qmd", quiet = TRUE)
12-
expect_true(file.exists("theme/ggiraph.html"))
13-
unlink("theme/ggiraph.html")
14+
.render(test_path("theme/ggiraph.qmd"))
1415
})
1516

16-
1717
test_that("render ggplot", {
18-
skip_if_no_quarto()
19-
quarto_render("theme/ggplot.qmd", quiet = TRUE)
20-
expect_true(file.exists("theme/ggplot.html"))
21-
unlink("theme/ggplot.html")
18+
.render(test_path("theme/ggplot.qmd"))
2219
})
2320

24-
2521
test_that("render gt", {
26-
skip_if_no_quarto()
27-
quarto_render("theme/gt.qmd", quiet = TRUE)
28-
expect_true(file.exists("theme/gt.html"))
29-
unlink("theme/gt.html")
22+
.render(test_path("theme/gt.qmd"))
3023
})
3124

32-
3325
test_that("render plotly-r", {
34-
skip_if_no_quarto()
35-
quarto_render("theme/plotly-r.qmd", quiet = TRUE)
36-
expect_true(file.exists("theme/plotly-r.html"))
37-
unlink("theme/plotly-r.html")
26+
.render(test_path("theme/plotly-r.qmd"))
3827
})
3928

40-
4129
test_that("render thematic", {
42-
skip_if_no_quarto()
43-
quarto_render("theme/thematic.qmd", quiet = TRUE)
44-
expect_true(file.exists("theme/thematic.html"))
45-
unlink("theme/thematic.html")
30+
.render(test_path("theme/thematic.qmd"))
4631
})

0 commit comments

Comments
 (0)