Skip to content

Commit

Permalink
Refactor tests
Browse files Browse the repository at this point in the history
  • Loading branch information
andrie committed Mar 27, 2024
1 parent 1ca50df commit 376768c
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 46 deletions.
79 changes: 39 additions & 40 deletions tests/testthat/test-3-makeRepo.R
Original file line number Diff line number Diff line change
Expand Up @@ -21,53 +21,52 @@
types <- set_test_types()
pkg_type <- types[1]

test_for_type <- function(pkg_type) {
# skip_if_not_installed("mockr")
test_that(sprintf("makeRepo downloads %s files and builds PACKAGES",
pkg_type), {

skip_on_cran()
skip_if_offline()
skip_if_not_installed("mockr")

test_that("makeRepo downloads files and builds PACKAGES", {

skip_on_cran()
skip_if_offline()
skip_if_not_installed("mockr")
types <- set_test_types()
for (pkg_type in types) {

# 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)

ret <- mockr::with_mock(
download_packages = mock_download_packages,
write_packages = mock_write_packages,
.env = "miniCRAN",
{
makeRepo(pkgList, path = repo_root, repos = revolution,
type = pkg_type, quiet = TRUE, Rversion = rvers)
}
suggests = FALSE, Rversion = rvers, quiet = FALSE)
prefix <- repoPrefix(pkg_type, Rversion = rvers)
dir.create(repo_root, recursive = TRUE, showWarnings = FALSE)

ret <- mockr::with_mock(
download_packages = mock_download_packages,
write_packages = mock_write_packages,
.env = "miniCRAN",
{
makeRepo(pkgList, path = repo_root, repos = revolution,
type = pkg_type, quiet = TRUE, Rversion = rvers)
}
)

expect_type(ret, "character")
expect_equal(length(ret), length(pkgList))

expect_true(
.checkForRepoFiles(repo_root, pkgList, prefix)
)
expect_true(
file.exists(file.path(repo_root, prefix, "PACKAGES.gz"))
)
expect_true(
all(
pkgList %in% pkgAvail(repos = repo_root,
type = pkg_type,
Rversion = rvers)[, "Package"]
)
)
}
})

expect_type(ret, "character")
expect_equal(length(ret), length(pkgList))

expect_true(
.checkForRepoFiles(repo_root, pkgList, prefix)
)
expect_true(
file.exists(file.path(repo_root, prefix, "PACKAGES.gz"))
)
expect_true(
all(
pkgList %in% pkgAvail(repos = repo_root,
type = pkg_type,
Rversion = rvers)[, "Package"]
)
)
})
}

# 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)
12 changes: 6 additions & 6 deletions tests/testthat/test-4-makeRepo-from-localCRAN.R
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ names(types) <- c("win.binary")

pkg_type <- names(types)

for (pkg_type in names(types)) {
test_that(sprintf("makeRepo downloads %s files and builds PACKAGES file", pkg_type), {
# skip_on_cran()
skip_if_offline(revolution_mran)
test_that("makeRepo downloads files and builds PACKAGES file", {
skip_if_offline(revolution_mran)
# skip_on_cran()
for (pkg_type in names(types)) {

# Create local miniCRAN
# mockery::stub(makeRepo, "download_packages", mock_download_packages, depth = 1)
Expand Down Expand Up @@ -83,7 +83,7 @@ for (pkg_type in names(types)) {
)
)

})
}
}
})

unlink(repo_root, recursive = TRUE)

0 comments on commit 376768c

Please sign in to comment.