diff --git a/R/platform.R b/R/platform.R index f9682165..80827fc6 100644 --- a/R/platform.R +++ b/R/platform.R @@ -321,7 +321,11 @@ macos_cran_platforms$rversion <- get_minor_r_version( macos_cran_platforms <- unique(macos_cran_platforms) get_cran_macos_platform <- function(v) { - macos_cran_platforms[macos_cran_platforms$rversion %in% v,,drop = FALSE] + if (v %in% macos_cran_platforms$rversion) { + macos_cran_platforms[macos_cran_platforms$rversion %in% v,,drop = FALSE] + } else { + utils::tail(macos_cran_platforms, 2) + } } #' Query the default CRAN repository for this session diff --git a/tests/testthat/_snaps/macos-platforms.md b/tests/testthat/_snaps/macos-platforms.md new file mode 100644 index 00000000..ff90d075 --- /dev/null +++ b/tests/testthat/_snaps/macos-platforms.md @@ -0,0 +1,45 @@ +# macos platforms + + Code + get_cran_macos_platform("4.2") + Output + rversion platform subdir + 35 4.2 x86_64-apple-darwin17.0 + 36 4.2 aarch64-apple-darwin20 big-sur-arm64 + Code + get_cran_macos_platform("4.3") + Output + rversion platform subdir + 37 4.3 x86_64-apple-darwin20 big-sur-x86_64 + 38 4.3 aarch64-apple-darwin20 big-sur-arm64 + Code + get_cran_macos_platform("4.4") + Output + rversion platform subdir + 39 4.4 x86_64-apple-darwin20 big-sur-x86_64 + 40 4.4 aarch64-apple-darwin20 big-sur-arm64 + Code + get_cran_macos_platform("4.5") + Output + rversion platform subdir + 41 4.5 x86_64-apple-darwin20 big-sur-x86_64 + 42 4.5 aarch64-apple-darwin20 big-sur-arm64 + Code + get_cran_macos_platform("4.6") + Output + rversion platform subdir + 43 4.6 x86_64-apple-darwin20 big-sur-x86_64 + 44 4.6 aarch64-apple-darwin20 big-sur-arm64 + Code + get_cran_macos_platform("5.0") + Output + rversion platform subdir + 45 5.0 x86_64-apple-darwin20 big-sur-x86_64 + 46 5.0 aarch64-apple-darwin20 big-sur-arm64 + Code + get_cran_macos_platform("10.0") + Output + rversion platform subdir + 45 5.0 x86_64-apple-darwin20 big-sur-x86_64 + 46 5.0 aarch64-apple-darwin20 big-sur-arm64 + diff --git a/tests/testthat/test-macos-platforms.R b/tests/testthat/test-macos-platforms.R new file mode 100644 index 00000000..5c56d000 --- /dev/null +++ b/tests/testthat/test-macos-platforms.R @@ -0,0 +1,25 @@ +test_that("macos platforms", { + skip_on_cran() + expect_snapshot({ + get_cran_macos_platform("4.2") + get_cran_macos_platform("4.3") + get_cran_macos_platform("4.4") + get_cran_macos_platform("4.5") + get_cran_macos_platform("4.6") + get_cran_macos_platform("5.0") + get_cran_macos_platform("10.0") + }) + + # error if we don't know the platform + # we do this so we can detect the failure on the CI and update + # the platform + v <- paste0(getRversion()[,1:2]) + expect_true(v %in% macos_cran_platforms$rversion) + + # In case CRAN changes the platform for R-devel + if (Sys.info()[["sysname"]] == "Darwin" && .Platform$pkgType != "source") { + plt <- get_cran_macos_platform(v) + expect_true(R.Version()$platform %in% plt$platform) + expect_true(.Platform$pkgType %in% paste0("mac.binary.", plt$subdir)) + } +})