Skip to content

Commit

Permalink
Skip tests that use optional test data on CRAN under MacOS, where it …
Browse files Browse the repository at this point in the history
…is not available
  • Loading branch information
dfsp-spirit committed Jan 7, 2020
1 parent d1ef726 commit a52cbc2
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 0 deletions.
10 changes: 10 additions & 0 deletions tests/testthat.R
Original file line number Diff line number Diff line change
@@ -1,4 +1,14 @@
library(testthat)
library(freesurferformats)

#' @title Determine whether a test is running on CRAN under macos
#'
#' @description We are currently getting failed unit tests on CRAN under macos, while the package works under MacOS on both <https://builder.r-hub.io/> and on our MacOS machines. This is because the package file cache does not work on CRAN, as the HOME is mounted read-only on the CRAN test systems. So we have to skip the tests that require optional data under MacOS on CRAN.
#'
#' @return logical, whether a test is running on CRAN under MacOS
#' @keywords internal
tests_running_on_cran_under_macos <- function() {
return(tolower(Sys.info()[["sysname"]]) == 'darwin' && !identical(Sys.getenv("NOT_CRAN"), "true"));
}

test_check("freesurferformats")
10 changes: 10 additions & 0 deletions tests/testthat/test-read-fs-surface.R
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@




test_that("Our demo surface file can be read using read.fs.surface", {

skip_if(tests_running_on_cran_under_macos(), message = "Skipping on CRAN under MacOS, required test data cannot be downloaded.");
freesurferformats::download_optional_data();
subjects_dir = freesurferformats::get_optional_data_filepath("subjects_dir");
surface_file = file.path(subjects_dir, "subject1", "surf", "lh.white");
Expand Down Expand Up @@ -29,6 +34,9 @@ test_that("Our demo surface file can be read using read.fs.surface", {
test_that("Vertex connectivity in the demo surface file is as expected from reference implementation", {
# Checks for bug in issue #8: freesurfer surface import - row-major/column-major order
# The vertex connectivities used in this test are known from running the FreeSurfer Matlab function $FREESURFER_HOME/matlab/read_surf.m on the data

skip_if(tests_running_on_cran_under_macos(), message = "Skipping on CRAN under MacOS, required test data cannot be downloaded.");

freesurferformats::download_optional_data();
subjects_dir = freesurferformats::get_optional_data_filepath("subjects_dir");
surface_file = file.path(subjects_dir, "subject1", "surf", "lh.white");
Expand All @@ -49,6 +57,8 @@ test_that("Vertex connectivity in the demo surface file is as expected from refe
test_that("The vertices of a face are close to each other", {
# Checks for bug in issue #8: freesurfer surface import - row-major/column-major order

skip_if(tests_running_on_cran_under_macos(), message = "Skipping on CRAN under MacOS, required test data cannot be downloaded.");

freesurferformats::download_optional_data();
subjects_dir = freesurferformats::get_optional_data_filepath("subjects_dir");
surface_file = file.path(subjects_dir, "subject1", "surf", "lh.white");
Expand Down
3 changes: 3 additions & 0 deletions tests/testthat/test-write-fs-surface.R
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ test_that("One can write and re-read triangular surface data", {
})

test_that("One can read, write and re-read triangular surface data", {

skip_if(tests_running_on_cran_under_macos(), message = "Skipping on CRAN under MacOS, required test data cannot be downloaded.");

freesurferformats::download_optional_data();
subjects_dir = freesurferformats::get_optional_data_filepath("subjects_dir");
surface_file = file.path(subjects_dir, "subject1", "surf", "lh.white");
Expand Down

0 comments on commit a52cbc2

Please sign in to comment.