diff --git a/R/pkgDep.R b/R/pkgDep.R index 289aa6f..d63d7c9 100644 --- a/R/pkgDep.R +++ b/R/pkgDep.R @@ -76,7 +76,10 @@ pkgDep <- function(pkg, availPkgs, repos = getOption("repos"), type = "source", quiet = quiet, ...) } - assert_that(nrow(availPkgs) > 0, msg = "Unable to retrieve available packages from CRAN") + assert_that( + nrow(availPkgs) > 0, + msg = sprintf("Unable to retrieve %s package %s from %s", type, pkg, repos) + ) pkgInAvail <- pkg %in% availPkgs[, "Package"] diff --git a/tests/testthat/helpers.R b/tests/testthat/helpers.R index 3eb43c9..0775aab 100644 --- a/tests/testthat/helpers.R +++ b/tests/testthat/helpers.R @@ -100,8 +100,8 @@ mock_write_packages <- function(dir, type = "source", r_version) { if (missing(pkgs)) pkgs <- c("chron", "curl") if (missing(types)) types <- set_test_types() - pdb_source <- pkgAvail(repos = MRAN, type = "source", Rversion = Rversion) - pdb_win <- pkgAvail(repos = MRAN, type = "win.binary", Rversion = Rversion) + # pdb_source <- pkgAvail(repos = MRAN, type = "source", Rversion = Rversion) + # pdb_win <- pkgAvail(repos = MRAN, type = "win.binary", Rversion = Rversion) # pdb_mac <- pkgAvail(repos = MRAN, type = "mac.binary", Rversion = Rversion) mockr::with_mock( @@ -111,7 +111,8 @@ mock_write_packages <- function(dir, type = "source", r_version) { { for (type in types) { - pkgList_source <- pkgDep(pkgs, availPkgs = pdb_source, repos = MRAN, + pdb <- pkgAvail(repos = MRAN, type = type, Rversion = Rversion) + pkgList_source <- pkgDep(pkgs, availPkgs = pdb, repos = MRAN, type = type, suggests = FALSE, Rversion = Rversion) makeRepo(pkgList_source, path = path, repos = MRAN, @@ -119,20 +120,6 @@ mock_write_packages <- function(dir, type = "source", r_version) { quiet = TRUE, Rversion = Rversion) } - - # pkgList_win <- pkgDep(pkgs, availPkgs = pdb_win, repos = MRAN, - # type = "win.binary", - # suggests = FALSE, Rversion = Rversion) - # makeRepo(pkgList_win, path = path, repos = MRAN, - # type = "win.binary", - # quiet = TRUE, Rversion = Rversion) - - # pkgList_mac <- pkgDep(pkgs, availPkgs = pdb_mac, repos = MRAN, - # type = "mac.binary", - # suggests = FALSE, Rversion = Rversion) - # makeRepo(pkgList_mac, path = path, repos = MRAN, - # type = "mac.binary", - # quiet = TRUE, Rversion = Rversion) } ) } diff --git a/tests/testthat/test-3-makeRepo.R b/tests/testthat/test-3-makeRepo.R index 49241d4..7c27ec8 100644 --- a/tests/testthat/test-3-makeRepo.R +++ b/tests/testthat/test-3-makeRepo.R @@ -1,12 +1,12 @@ { - revolution <- MRAN("2023-08-04") + revolution <- MRAN("2023-08-31") if (!is.online(revolution, tryHttp = FALSE)) { # Use http:// for older versions of R revolution <- sub("^https://", "http://", revolution) } - rvers <- "4.0" + rvers <- "4.3" pkgs <- c("Rcpp") repo_root <- file.path(tempdir(), "miniCRAN", Sys.Date()) if (file.exists(repo_root)) unlink(repo_root, recursive = TRUE) @@ -19,6 +19,7 @@ # types are defined in env var `minicran_test_scope` types <- set_test_types() +pkg_type <- types[1] test_for_type <- function(pkg_type) { # skip_if_not_installed("mockr") @@ -29,19 +30,20 @@ test_for_type <- function(pkg_type) { skip_if_offline() skip_if_not_installed("mockr") + # pdb <- pkgAvail(repos = revolution, type = pkg_type, quiet = TRUE) pdb <- pkgAvail(repos = revolution, type = pkg_type, Rversion = rvers, quiet = TRUE) pkgList <- pkgDep(pkgs, availPkgs = pdb, repos = revolution, type = pkg_type, suggests = FALSE, Rversion = rvers, quiet = FALSE) prefix <- repoPrefix(pkg_type, Rversion = rvers) dir.create(repo_root, recursive = TRUE, showWarnings = FALSE) - mockr::with_mock( + ret <- mockr::with_mock( download_packages = mock_download_packages, write_packages = mock_write_packages, .env = "miniCRAN", { - ret <- makeRepo(pkgList, path = repo_root, repos = revolution, - type = pkg_type, quiet = TRUE, Rversion = rvers) + makeRepo(pkgList, path = repo_root, repos = revolution, + type = pkg_type, quiet = TRUE, Rversion = rvers) } ) @@ -64,6 +66,8 @@ test_for_type <- function(pkg_type) { }) } -for (pkg_type in (types)) {test_for_type(pkg_type = pkg_type)} +# types are defined in env var `minicran_test_scope` +types <- set_test_types() +for (pkg_type in types) {test_for_type(pkg_type = pkg_type)} unlink(repo_root, recursive = TRUE) diff --git a/tests/testthat/test-5-updateRepo.R b/tests/testthat/test-5-updateRepo.R index 95ce3fc..323dc18 100644 --- a/tests/testthat/test-5-updateRepo.R +++ b/tests/testthat/test-5-updateRepo.R @@ -11,13 +11,13 @@ # Use http:// for older versions of R revolution <- sub("^https://", "http://", revolution) } - rvers <- "4.0" - pkgs <- c("chron", "XML") + rvers <- "4.2" + pkgs <- c("chron", "data.table") types <- intersect( set_test_types(), - # c("source", "win.binary", "mac.binary") - c("source", "win.binary") + # c("source", "win.binary") + c("source", "win.binary", "mac.binary") ) names(types) <- types @@ -38,10 +38,10 @@ test_that("sample repo is setup correctly", { }) expect_type(pkgList, "list") - z <- .createSampleRepo(path = repo_root, MRAN = revolution, Rversion = rvers, + .createSampleRepo(path = repo_root, MRAN = revolution, Rversion = rvers, pkgs = pkgs, types = names(types)) # expect_type(z, "character") - pkg_names <- unname(pkgAvail(repo_root, quiet = TRUE)[, "Package"]) + pkg_names <- unname(pkgAvail(repo_root, quiet = TRUE, type = type, Rversion = rvers)[, "Package"]) expect_true(all(pkgs %in% pkg_names)) }) @@ -49,8 +49,8 @@ test_that("sample repo is setup correctly", { # Add packages to repo ---------------------------------------------------- pkgsAdd <- c("Rcpp") - pkg_type <- names(types)[1] + for (pkg_type in names(types)) { skip_if_not_installed("mockr") @@ -198,7 +198,7 @@ for (pkg_type in names(types)) { # In the following allow for differences between mac.binary and other types expect_gte(nrow(old), 1) expect_equal(ncol(old), 4) - expect_true( "XML" %in% rownames(old)) + expect_true( "data.table" %in% rownames(old)) mockr::with_mock( download_packages = mock_download_packages,