Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# testthat (development version)

* `skip_if_not_installed()` produces a clearer message (@MichaelChirico, #1959).
* `with_mock()` and `local_mock()` have been unconditionally deprecated as they will no longer work in future versions of R (#1999).
* `expect_condition()` and friends now include the `class` of the expected condition in the failure mesage, if used (#1987).
* `LANGUAGE` is now set to `"C"` in reprocucible environments (i.e.
Expand Down
8 changes: 7 additions & 1 deletion R/skip.R
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,14 @@ skip_if <- function(condition, message = NULL) {
#' @param minimum_version Minimum required version for the package
#' @rdname skip
skip_if_not_installed <- function(pkg, minimum_version = NULL) {
# most common case: it's not installed
tryCatch(
find.package(pkg),
error = function(e) skip(paste0("{", pkg, "} is not installed"))
)
# rarer: it's installed, but fails to load
if (!requireNamespace(pkg, quietly = TRUE)) {
skip(paste0(pkg, " cannot be loaded"))
skip(paste0("{", pkg, "} cannot be loaded"))
}

if (!is.null(minimum_version)) {
Expand Down
2 changes: 1 addition & 1 deletion tests/testthat/_snaps/skip.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@

# skip_if_not_installed() works as expected

Reason: doesntexist cannot be loaded
Reason: {doesntexist} is not installed

---

Expand Down
Loading