source(file.path("..", "newer-r-helpers.R")) test_that("R constraints respect patch versions, bounds, and missing fields", { expect_true(r_requirement_satisfied(NA_character_, "4.4.3")) expect_true(r_requirement_satisfied( "Matrix (>= 1.4-0), R (>= 4.5.0)", "4.5.3" )) expect_false(r_requirement_satisfied("R (>= 4.5.0)", "4.4.3")) expect_false(r_requirement_satisfied("R (>= 4.5.4)", "4.5.3")) expect_true(r_requirement_satisfied("R (>= 4.5), R (< 4.6)", "4.5.3")) expect_false(r_requirement_satisfied("R (>= 4.5), R (< 4.6)", "4.6.0")) expect_true(r_requirement_satisfied("R (== 4.5.3)", "4.5.3")) expect_true(r_requirement_satisfied("R (> 4.5.2), R (<= 4.5.3)", "4.5.3")) expect_true(r_requirement_satisfied("R, Rcpp (>= 1.0)", "4.4.3")) expect_error(r_requirement_satisfied("R (~ 4.5)", "4.5.3"), "Cannot parse") }) fixture <- function() { data.frame( Package = c( "arules", "arulesSequences", "indirect", "optional", "ordinary", "future", "blocked" ), Version = rep("1.0", 7L), Depends = c( "R (>= 4.5.0)", "arules", NA, NA, "R (>= 4.0)", "R (>= 4.7)", NA ), Imports = c(NA, NA, "arulesSequences", NA, NA, NA, "arules, future"), LinkingTo = NA_character_, Suggests = c(NA, NA, NA, "arules", NA, NA, NA) ) } test_that("every compatible newer minor includes required dependents only", { db <- fixture() for (target in c("4.5.3", "4.6.0")) { expect_identical( newer_r_candidates(db, "4.4.3", target)$Package, c("arules", "arulesSequences", "indirect") ) } expect_equal(nrow(newer_r_candidates(db, "4.4.3", "4.4.3")), 0L) expect_equal(nrow(newer_r_candidates(db, "4.5.3", "4.4.3")), 0L) expect_equal(nrow(newer_r_candidates(db, "4.5.3", "4.6.0")), 0L) }) test_that("LinkingTo, dependency cycles, Windows and empty metadata are handled", { db <- fixture() db$LinkingTo[5L] <- "arules" db$Imports[1L] <- "ordinary" db$OS_type <- c(NA, "windows", rep(NA_character_, 5L)) expect_identical( newer_r_candidates(db, "4.4.3", "4.6.0")$Package, c("arules", "indirect", "ordinary") ) expect_equal(nrow(newer_r_candidates(db[FALSE, ], "4.4.3", "4.6.0")), 0L) }) test_that("R-devel Recommended copies cannot block ordinary CRAN dependencies", { db <- fixture() db$Path <- NA_character_ future_copy <- db[1L, ] future_copy$Depends <- "R (>= 4.7)" future_copy$Path <- "4.7.0/Recommended" expect_identical( newer_r_candidates(rbind(future_copy, db), "4.4.3", "4.6.1")$Package, c("arules", "arulesSequences", "indirect") ) })