Skip to content

Commit

Permalink
Make macOS platform detection more robust
Browse files Browse the repository at this point in the history
If we don't know the platform, then take the last row.
  • Loading branch information
gaborcsardi committed Apr 2, 2024
1 parent c002f93 commit 8833f0d
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 1 deletion.
6 changes: 5 additions & 1 deletion R/platform.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
45 changes: 45 additions & 0 deletions tests/testthat/_snaps/macos-platforms.md
Original file line number Diff line number Diff line change
@@ -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

25 changes: 25 additions & 0 deletions tests/testthat/test-macos-platforms.R
Original file line number Diff line number Diff line change
@@ -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))
}
})

0 comments on commit 8833f0d

Please sign in to comment.