Skip to content

Commit

Permalink
Fix CI by skipping visual tests when vdiffr is not available (#4192)
Browse files Browse the repository at this point in the history
* Skip visual tests when vdiffr is not available

* Add tweak to skip ggsave tests

* Update CMD-ckeck.yml

* Add http-user-agent

* Fix a comment

* Require vdiffr except when it's explicitly disabled
  • Loading branch information
yutannihilation committed Sep 6, 2020
1 parent 6b8dba0 commit ac2b5a7
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 14 deletions.
26 changes: 13 additions & 13 deletions .github/workflows/R-CMD-check.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,17 @@ jobs:
config:
- {os: windows-latest, r: '4.0', vdiffr: true, xref: true}
- {os: macOS-latest, r: '4.0', vdiffr: true, xref: true}
- {os: ubuntu-16.04, r: 'devel', vdiffr: false, xref: true, cran: "https://demo.rstudiopm.com/all/__linux__/xenial/latest"}
- {os: ubuntu-16.04, r: '4.0', vdiffr: true, xref: true, cran: "https://demo.rstudiopm.com/all/__linux__/xenial/latest"}
- {os: ubuntu-16.04, r: '3.6', vdiffr: false, xref: true, cran: "https://demo.rstudiopm.com/all/__linux__/xenial/latest"}
- {os: ubuntu-16.04, r: '3.5', vdiffr: false, xref: true, cran: "https://demo.rstudiopm.com/all/__linux__/xenial/latest"}
- {os: ubuntu-16.04, r: '3.4', vdiffr: false, xref: true, cran: "https://demo.rstudiopm.com/all/__linux__/xenial/latest"}
- {os: ubuntu-16.04, r: '3.3', vdiffr: false, xref: true, cran: "https://demo.rstudiopm.com/all/__linux__/xenial/latest"}
- {os: ubuntu-16.04, r: '3.2', vdiffr: false, xref: false, cran: "https://demo.rstudiopm.com/all/__linux__/xenial/latest"}
- {os: ubuntu-16.04, r: 'devel', vdiffr: false, xref: true, rspm: "https://packagemanager.rstudio.com/cran/__linux__/xenial/latest", http-user-agent: "R/4.0.0 (ubuntu-16.04) R (4.0.0 x86_64-pc-linux-gnu x86_64 linux-gnu) on GitHub Actions"}
- {os: ubuntu-16.04, r: '4.0', vdiffr: true, xref: true, rspm: "https://packagemanager.rstudio.com/cran/__linux__/xenial/latest"}
- {os: ubuntu-16.04, r: '3.6', vdiffr: false, xref: true, rspm: "https://packagemanager.rstudio.com/cran/__linux__/xenial/latest"}
- {os: ubuntu-16.04, r: '3.5', vdiffr: false, xref: true, rspm: "https://packagemanager.rstudio.com/cran/__linux__/xenial/latest"}
- {os: ubuntu-16.04, r: '3.4', vdiffr: false, xref: true, rspm: "https://packagemanager.rstudio.com/cran/__linux__/xenial/latest"}
- {os: ubuntu-16.04, r: '3.3', vdiffr: false, xref: true, rspm: "https://packagemanager.rstudio.com/cran/__linux__/xenial/latest"}
- {os: ubuntu-16.04, r: '3.2', vdiffr: false, xref: false, rspm: "https://packagemanager.rstudio.com/cran/__linux__/xenial/latest"}

env:
R_REMOTES_NO_ERRORS_FROM_WARNINGS: true
CRAN: ${{ matrix.config.cran }}
RSPM: ${{ matrix.config.rspm }}
# don't treat missing suggested packages as error
_R_CHECK_FORCE_SUGGESTS_: false
# Some packages might unavailable on the older versions, so let's ignore xref warnings
Expand All @@ -49,6 +49,7 @@ jobs:
- uses: r-lib/actions/setup-r@master
with:
r-version: ${{ matrix.config.r }}
http-user-agent: ${{ matrix.config.http-user-agent }}

- uses: r-lib/actions/setup-pandoc@master

Expand All @@ -68,12 +69,11 @@ jobs:

- name: Install system dependencies on Linux
if: runner.os == 'Linux'
env:
RHUB_PLATFORM: linux-x86_64-ubuntu-gcc
run: |
Rscript -e "remotes::install_github('r-hub/sysreqs')"
sysreqs=$(Rscript -e "cat(sysreqs::sysreq_commands('DESCRIPTION'))")
sudo -s eval "$sysreqs"
while read -r cmd
do
eval sudo $cmd
done < <(Rscript -e 'writeLines(remotes::system_requirements("ubuntu", "16.04"))')
- name: Install system dependencies on macOS
if: runner.os == 'macOS'
Expand Down
12 changes: 11 additions & 1 deletion tests/testthat/helper-vdiffr.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,14 @@
# - VDIFFR_RUN_TESTS is "false" (on Travis CI with older versions and dev version of R)
# - CI is not set (on CRAN)

expect_doppelganger <- vdiffr::expect_doppelganger
if (requireNamespace("vdiffr", quietly = TRUE)) {
expect_doppelganger <- vdiffr::expect_doppelganger
} else {
# If vdiffr is not available and visual tests are not explicitly disabled, raise error.
if (!identical(Sys.getenv("VDIFFR_RUN_TESTS"), "false")) {
abort("vdiffr is not installed")
}

# Otherwise, assign a dummy function
expect_doppelganger <- function(...) skip("vdiffr is not installed.")
}
4 changes: 4 additions & 0 deletions tests/testthat/test-ggsave.R
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ test_that("ggsave restores previous graphics device", {
})

test_that("ggsave uses theme background as image background", {
# FIXME: This should check svglite, but, at the time of writing this, there's already a binary
# package of svglite, and it can be installed even if the dependency is not available, surprisingly...
skip_if_not_installed("systemfonts")

path <- tempfile()
on.exit(unlink(path))
p <- ggplot(mtcars, aes(disp, mpg)) +
Expand Down

0 comments on commit ac2b5a7

Please sign in to comment.