Skip to content

Commit

Permalink
Perform tests in different operative systems (#125)
Browse files Browse the repository at this point in the history
* Skip plotting tests if not in Linux
  • Loading branch information
PabRod authored Nov 5, 2024
1 parent bea2e2d commit 443fdcb
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 4 deletions.
6 changes: 2 additions & 4 deletions .github/workflows/R-CMD-check.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
Expand Down
19 changes: 19 additions & 0 deletions tests/testthat/test-plots.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)

Expand All @@ -57,3 +75,4 @@ test_that("Plot quality", {

on.exit(file.remove(path)) # Clean afterwards
})

0 comments on commit 443fdcb

Please sign in to comment.