From 8d2a7d8281af91ae85dca358e9f716340895c1a0 Mon Sep 17 00:00:00 2001 From: Daniel Sabanes Bove Date: Fri, 26 Jan 2024 15:24:42 +0100 Subject: [PATCH] 419: make skipping code more general to also run on old R versions (#420) --- DESCRIPTION | 4 +- NEWS.md | 12 ++++++ R/skipping.R | 70 +++++----------------------------- src/.gitignore | 3 ++ tests/testthat/test-skipping.R | 52 +++++-------------------- 5 files changed, 37 insertions(+), 104 deletions(-) create mode 100644 src/.gitignore diff --git a/DESCRIPTION b/DESCRIPTION index 1c1433e2c..5477a8636 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,7 +1,7 @@ Type: Package Package: mmrm Title: Mixed Models for Repeated Measures -Version: 0.3.8 +Version: 0.3.10 Authors@R: c( person("Daniel", "Sabanes Bove", , "daniel.sabanes_bove@roche.com", role = c("aut", "cre")), person("Julia", "Dedic", , "julia.dedic@roche.com", role = "aut"), @@ -97,7 +97,7 @@ Language: en-US LazyData: true NeedsCompilation: yes Roxygen: list(markdown = TRUE) -RoxygenNote: 7.3.0 +RoxygenNote: 7.3.1 Collate: 'between-within.R' 'catch-routine-registration.R' diff --git a/NEWS.md b/NEWS.md index de101a0a4..074ca1b52 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,3 +1,15 @@ +# mmrm 0.3.10 + +### Miscellaneous + +- Fix internal test skipping functions for MacOS R. + +# mmrm 0.3.9 + +### Miscellaneous + +- Fix internal test skipping functions for R versions older than 4.3. + # mmrm 0.3.8 ### New Features diff --git a/R/skipping.R b/R/skipping.R index 1977238db..73c632f73 100644 --- a/R/skipping.R +++ b/R/skipping.R @@ -10,72 +10,22 @@ is_linux <- function() { tolower(Sys.info()[["sysname"]]) == "linux" } -# Predicate whether currently running on R compiled with clang. -is_using_clang <- function() { - grepl("clang", R_compiled_by()["C"]) -} - -# A `data.frame` giving default clang versions for each OS version of the -# Fedora Linux distribution. -# Source: https://packages.fedoraproject.org/pkgs/clang/clang/ -# See Updates section for older Fedora versions. -fedora_clang_defaults <- data.frame( - os = as.integer(c(36, 37, 38, 39, 40)), - clang = as.integer(c(14, 15, 16, 17, 17)) -) - -# A `data.frame` giving default clang versions for each OS version of the -# Debian Linux distribution. -# Source: https://packages.debian.org/search?keywords=clang -debian_clang_defaults <- data.frame( - os = c("bullseye", "bookworm", "trixie"), - clang = as.integer(c(11, 14, 16)) -) - -# Parse the major clang version as integer (e.g. 17) from -# the full clang string (e.g. "Debian clang version 17.0.6 (3)") -parse_clang_major <- function(clang_string) { - assert_string(clang_string, pattern = "clang") - clang_version <- gsub(pattern = "[^0-9.]", replacement = "", x = clang_string) - as.integer(gsub(pattern = "([0-9]+).+", replacement = "\\1", x = clang_version)) +# Get the compiler information. Workaround for older R versions +# where R_compiled_by() is not available. +get_compiler <- function() { + r_cmd <- file.path(R.home("bin"), "R") + system2(r_cmd, args = "CMD config CC", stdout = TRUE) } -# Predicate whether a non-standard clang version is used, specifically -# a higher than default clang version. Assumes that clang is used, otherwise fails. -# If not Fedora or Debian of the known versions are used, always returns `FALSE`. -is_non_standard_clang <- function(os_string, - clang_major_version) { - assert_string(os_string) - assert_int(clang_major_version) - if (grepl("Fedora", os_string)) { - os_version <- as.integer(gsub(pattern = "[^0-9]", replacement = "", x = os_string)) - assert_int(os_version) - which_os <- match(os_version, fedora_clang_defaults$os) - if (is.na(which_os)) { - return(FALSE) - } - clang_major_version > fedora_clang_defaults$clang[which_os] - } else if (grepl("Debian", os_string)) { - os_codename <- gsub(pattern = "Debian GNU/Linux ([a-z]+)/*[a-z]*", replacement = "\\1", x = os_string) - assert_string(os_codename) - which_os <- match(os_codename, debian_clang_defaults$os) - if (is.na(which_os)) { - return(FALSE) - } - clang_major_version > debian_clang_defaults$clang[which_os] - } else { - FALSE - } +# Predicate whether currently using a clang compiler. +is_using_clang <- function() { + grepl("clang", get_compiler()) } # Predicate whether an R-devel version is running on Linux Fedora or -# Debian with a non-standard clang compiler. +# Debian with a clang compiler. is_r_devel_linux_clang <- function() { is_r_devel() && is_linux() && - is_using_clang() && - is_non_standard_clang( - os_string = utils::osVersion, - clang_major_version = parse_clang_major(R_compiled_by()["C"]) - ) + is_using_clang() } diff --git a/src/.gitignore b/src/.gitignore new file mode 100644 index 000000000..22034c461 --- /dev/null +++ b/src/.gitignore @@ -0,0 +1,3 @@ +*.o +*.so +*.dll diff --git a/tests/testthat/test-skipping.R b/tests/testthat/test-skipping.R index 6259142a3..8a63d63b7 100644 --- a/tests/testthat/test-skipping.R +++ b/tests/testthat/test-skipping.R @@ -10,57 +10,25 @@ test_that("is_linux works as expected", { expect_flag(is_linux()) }) +# get_compiler ---- + +test_that("get_compiler works as expected", { + expect_string(get_compiler()) +}) + # is_using_clang ---- test_that("is_using_clang works as expected", { expect_flag(is_using_clang()) }) -# parse_clang_major ---- - -test_that("parse_clang_major works as expected", { - result <- parse_clang_major("Debian clang version 17.0.6 (3)") - expected <- 17L +test_that("is_using_clang gives the same information as R_compiled_by in recent R versions", { + skip_if(getRversion() < "4.3") + result <- is_using_clang() + expected <- grepl("clang", R_compiled_by()["C"]) # Only available from R 4.3 onward. expect_identical(result, expected) }) -# is_non_standard_clang ---- - -test_that("is_non_standard_clang works as expected for Fedora", { - os_string <- "Fedora Linux 36 (Workstation Edition)" - expect_false(is_non_standard_clang(os_string, clang_major_version = 14L)) - expect_false(is_non_standard_clang(os_string, clang_major_version = 13L)) - expect_true(is_non_standard_clang(os_string, clang_major_version = 15L)) -}) - -test_that("is_non_standard_clang returns FALSE for non-listed Fedora versions", { - os_string <- "Fedora Linux 12" - expect_false(is_non_standard_clang(os_string, clang_major_version = 14L)) - expect_false(is_non_standard_clang(os_string, clang_major_version = 13L)) - expect_false(is_non_standard_clang(os_string, clang_major_version = 15L)) -}) - -test_that("is_non_standard_clang works as expected for Debian", { - os_string <- "Debian GNU/Linux trixie/sid" - expect_false(is_non_standard_clang(os_string, clang_major_version = 16L)) - expect_false(is_non_standard_clang(os_string, clang_major_version = 15L)) - expect_true(is_non_standard_clang(os_string, clang_major_version = 17L)) -}) - -test_that("is_non_standard_clang returns FALSE for non-listed Debian versions", { - os_string <- "Debian GNU/Linux bla" - expect_false(is_non_standard_clang(os_string, clang_major_version = 14L)) - expect_false(is_non_standard_clang(os_string, clang_major_version = 13L)) - expect_false(is_non_standard_clang(os_string, clang_major_version = 15L)) -}) - -test_that("is_non_standard_clang returns FALSE for other Linux distributions", { - os_string <- "Solaris" - expect_false(is_non_standard_clang(os_string, clang_major_version = 14L)) - expect_false(is_non_standard_clang(os_string, clang_major_version = 13L)) - expect_false(is_non_standard_clang(os_string, clang_major_version = 15L)) -}) - # is_r_devel_linux_clang ---- test_that("is_r_devel_linux_clang works as expected", {