From 443fdcba5de829c8290e3a3027736243b71f9bb6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pablo=20Rodr=C3=ADguez-S=C3=A1nchez?= Date: Tue, 5 Nov 2024 10:41:09 +0100 Subject: [PATCH] Perform tests in different operative systems (#125) * Skip plotting tests if not in Linux --- .github/workflows/R-CMD-check.yaml | 6 ++---- tests/testthat/test-plots.R | 19 +++++++++++++++++++ 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/.github/workflows/R-CMD-check.yaml b/.github/workflows/R-CMD-check.yaml index f4748d2..b13ac60 100644 --- a/.github/workflows/R-CMD-check.yaml +++ b/.github/workflows/R-CMD-check.yaml @@ -20,11 +20,9 @@ jobs: fail-fast: false matrix: config: - # - {os: macos-latest, r: 'release'} - # - {os: windows-latest, r: 'release'} - # - {os: ubuntu-latest, r: 'devel', http-user-agent: 'release'} + - {os: macos-latest, r: 'release'} + - {os: windows-latest, r: 'release'} - {os: ubuntu-latest, r: 'release'} - # - {os: ubuntu-latest, r: 'oldrel-1'} env: GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }} diff --git a/tests/testthat/test-plots.R b/tests/testthat/test-plots.R index f918ac6..a2f53c4 100644 --- a/tests/testthat/test-plots.R +++ b/tests/testthat/test-plots.R @@ -36,6 +36,7 @@ testdata <- get_ifadv() with_save <- function(plot_function, path, width=800, height=350) { decorated <- function(...) { + png(path, width, height) # Create a file placeholder for the plot, p <- plot_function(...) # generate the plot... dev.off() # ... export it as png and close connection @@ -46,7 +47,24 @@ with_save <- function(plot_function, path, width=800, height=350) { return(decorated) } +#' Skip if not linux +#' +#' Plot saving is OS dependent. For the sake of sanity, we'll test the plot +#' snapshots only in Linux +#' +#' @return Nothing +#' +skip_if_not_linux <- function() { + if(Sys.info()["sysname"] == "Linux") { + # Do nothing + } else { + skip("This test is designed to run on Linux machines only") + } +} + test_that("Plot quality", { + skip_if_not_linux() + path <- "plot_quality.png" plot_quality_with_save <- with_save(plot_quality, path) @@ -57,3 +75,4 @@ test_that("Plot quality", { on.exit(file.remove(path)) # Clean afterwards }) +