Skip to content

Commit fa93be3

Browse files
committed
Extract FreeType version check
Makes testing easier
1 parent 751e7bf commit fa93be3

File tree

4 files changed

+22
-10
lines changed

4 files changed

+22
-10
lines changed

R/testthat-ui.R

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,18 +28,22 @@
2828
#' standard families and Symbola font for symbols.
2929
#' @export
3030
#' @examples
31-
#' disp_hist_base <- function() hist(mtcars$disp)
32-
#' expect_doppelganger("disp-histogram-base", disp_hist_base)
31+
#' ver <- gdtools::version_freetype()
3332
#'
34-
#' if (requireNamespace("ggplot2", quietly = TRUE)) {
33+
#' if (ver >= "2.6.0") {
34+
#' disp_hist_base <- function() hist(mtcars$disp)
35+
#' expect_doppelganger("disp-histogram-base", disp_hist_base)
36+
#' }
37+
#'
38+
#' if (ver >= "2.6.0" && requireNamespace("ggplot2", quietly = TRUE)) {
3539
#' library("ggplot2")
3640
#' disp_hist_ggplot <- ggplot(mtcars, aes(disp)) + geom_histogram()
3741
#' expect_doppelganger("disp-histogram-ggplot", disp_hist_ggplot)
3842
#' }
3943
expect_doppelganger <- function(title, fig, path = NULL, ...,
4044
user_fonts = NULL) {
41-
ver <- gdtools::version_freetype()
42-
if (ver < "2.6.0") {
45+
if (old_freetype()) {
46+
ver <- gdtools::version_freetype()
4347
msg <- paste("vdiffr requires FreeType >= 2.6.0. Current version:", ver)
4448
testthat::skip(msg)
4549
}

R/vdiffr.R

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,7 @@
33
#' @importFrom R6 R6Class
44
#' @useDynLib vdiffr
55
NULL
6+
7+
old_freetype <- function() {
8+
gdtools::version_freetype() < "2.6.0"
9+
}

man/expect_doppelganger.Rd

Lines changed: 7 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/testthat/helper-mock.R

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,12 @@ on_load <- function() {
1818
identical(Sys.getenv("DEVTOOLS_LOAD"), "true")
1919
}
2020
skip_old_freetype <- function() {
21-
if (gdtools::version_freetype() < "2.6.0" ) {
21+
if (old_freetype()) {
2222
skip("FreeType too old for vdiffr")
2323
}
2424
}
2525

26-
if (gdtools::version_freetype() >= "2.6.0" && !on_load()) {
26+
if (!old_freetype() && !on_load()) {
2727
mock_pkg_dir <- create_mock_pkg()
2828
mock_test_dir <- file.path(mock_pkg_dir, "tests", "testthat")
2929

0 commit comments

Comments
 (0)