Skip to content

Commit

Permalink
These tests do more harm than good (#2542)
Browse files Browse the repository at this point in the history
Closes #2477

As written, these tests (indirectly) call `remotes::update_packages("roxygen2")` which can cause package installation on any machine that runs the tests. And this installation is NOT scoped correctly, i.e. to a temporary library.

I got fairly far into refactoring the tests, when I realized that fixing them introduced more complexity than was worth it. Passing arguments along isn't a tricky operation. devtools is better off without these tests.
  • Loading branch information
jennybc authored Nov 4, 2023
1 parent 45354cf commit c901718
Showing 1 changed file with 0 additions and 114 deletions.
114 changes: 0 additions & 114 deletions tests/testthat/test-install.R
Original file line number Diff line number Diff line change
@@ -1,117 +1,3 @@
library(mockery)

local({

pkg <- fs::path_real(local_package_create())

path2char <- function(x) {
if (inherits(x, "fs_path")) {
as.character(x)
} else {
x
}
}

expect_passes_args <- function(fn, stub, input_args = list(), expected_args) {
mck <- mockery::mock(NULL)
mockery::stub(fn, stub, mck)

capture.output(suppressMessages(do.call(fn, input_args)))

mockery::expect_called(mck, 1)
mock_args <- mockery::mock_args(mck)[[1]]
mock_args <- lapply(mock_args, path2char)
expect_equal(mock_args, expected_args)
}

custom_args <- list(
dependencies = "dep",
repos = "repo",
type = "type",
upgrade = "upgrade",
quiet = "quiet",
build = "build",
build_opts = "build_opts"
)

dep_defaults <- list(
dependencies = NA,
repos = getOption("repos"),
type = getOption("pkgType"),
upgrade = c("default", "ask", "always", "never"),
quiet = FALSE,
build = TRUE,
build_opts = c("--no-resave-data", "--no-manual", " --no-build-vignettes")
)

dev_dep_defaults <- list(
dependencies = TRUE,
repos = getOption("repos"),
type = getOption("pkgType"),
upgrade = c("default", "ask", "always", "never"),
quiet = FALSE,
build = TRUE,
build_opts = c("--no-resave-data", "--no-manual", " --no-build-vignettes")
)

extra <- list(foo = "foo", bar = "bar")

test_that("install_deps passes default args to remotes::install_deps", {
expect_passes_args(
install_deps,
"remotes::install_deps",
list(pkg),
c(pkg, dep_defaults)
)
})

test_that("install_deps passes custom args to remotes::install_deps", {
expect_passes_args(
install_deps,
"remotes::install_deps",
c(pkg, custom_args),
c(pkg, custom_args)
)
})

test_that("install_deps passes ellipsis args to remotes::install_deps", {
expect_passes_args(
install_deps,
"remotes::install_deps",
c(pkg, extra),
c(pkg, dep_defaults, extra)
)
})

test_that("install_dev_deps passes default args to remotes::install_deps", {
expect_passes_args(
install_dev_deps,
"remotes::install_deps",
list(pkg),
c(pkg, dev_dep_defaults)
)
})

test_that("install_dev_deps passes custom args to remotes::install_deps", {
expect_passes_args(
install_dev_deps,
"remotes::install_deps",
c(pkg, custom_args),
c(pkg, custom_args)
)
})

test_that("install_dev_deps passes ellipsis args to remotes::install_deps", {
expect_passes_args(
install_dev_deps,
"remotes::install_deps",
c(pkg, extra),
c(pkg, dev_dep_defaults, extra)
)
})

})

test_that("vignettes built on install", {
skip_on_cran()

Expand Down

0 comments on commit c901718

Please sign in to comment.