diff --git a/tests/testthat.R b/tests/testthat.R index 7be6139..ccda5a5 100644 --- a/tests/testthat.R +++ b/tests/testthat.R @@ -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 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") diff --git a/tests/testthat/test-read-fs-surface.R b/tests/testthat/test-read-fs-surface.R index 3cbb241..41e0842 100644 --- a/tests/testthat/test-read-fs-surface.R +++ b/tests/testthat/test-read-fs-surface.R @@ -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"); @@ -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"); @@ -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"); diff --git a/tests/testthat/test-write-fs-surface.R b/tests/testthat/test-write-fs-surface.R index d9b3407..ba6201d 100644 --- a/tests/testthat/test-write-fs-surface.R +++ b/tests/testthat/test-write-fs-surface.R @@ -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");