Skip to content

Commit

Permalink
add installation predicates
Browse files Browse the repository at this point in the history
  • Loading branch information
maxheld83 committed Sep 12, 2024
1 parent 14dd118 commit 601a2f6
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 1 deletion.
7 changes: 7 additions & 0 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,10 @@ Suggests:
Config/testthat/edition: 3
Config/testthat/parallel: true
Config/Needs/website: rmarkdown
Collate:
'dependencies.R'
'elf-package.R'
'examples.R'
'tests.R'
'installed.R'
'options.R'
7 changes: 7 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
# Generated by roxygen2: do not edit by hand

export(assert_pkg_installed)
export(check_pkg_installed)
export(expect_pkg_installed)
export(is_installed2)
export(make_skip_if_not_function)
export(opt_set_local2)
export(skip_if_pkg_not_installed2)
export(source_pef)
export(test_pkg_installed)
export(transform_with_generated)
export(use_ex_file)
importFrom(checkmate,makeExpectation)
importFrom(checkmate,vname)
2 changes: 2 additions & 0 deletions R/elf-package.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,7 @@
"_PACKAGE"

## usethis namespace: start
#' @importFrom checkmate makeExpectation
#' @importFrom checkmate vname
## usethis namespace: end
NULL
32 changes: 32 additions & 0 deletions R/installed.R
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,45 @@ check_pkg_installed <- function(x = character(1L)) {
}

#' @describeIn pkg_installed returns `x` invisibly or errors out.
#' @inheritParams checkmate::makeAssertion
#' @inheritParams checkmate::assert
#' @export
assert_pkg_installed <- checkmate::makeAssertionFunction(check_pkg_installed)

#' @describeIn pkg_installed returns `TRUE` or `FALSE`
#' @inheritParams checkmate::makeTest
#' @export
test_pkg_installed <- checkmate::makeTestFunction(check_pkg_installed)

#' @describeIn pkg_installed returns an [testthat::expectation()]
#' @inheritParams checkmate::makeExpectation
#' @export
expect_pkg_installed <- checkmate::makeExpectationFunction(check_pkg_installed)

#' @describeIn pkg_installed
#' skips test if package is *not* installed.
#' Same as [testthat::skip_if_not_installed()],
#' except using [rlang::is_installed()] under the hood.
#' @include tests.R
#' @export
skip_if_pkg_not_installed2 <- make_skip_if_not_function(check_pkg_installed)

# installed but not via load_all ====

#' Check if a package is installed, but not via [pkgload::load_all()]
#'
#' To speed up development,
#' [pkgload::load_all()] simulates installing a package.
#' This simulation is usually sufficient,
#' but there are edge cases which it cannot cover.
#' Use this family of predicates to guard against these edge cases.
#'
#' @details
#' A frequent example of an edge case for [pkgload::load_all()]
#' occurs when child processes are launched during development,
#' such as in [shinytest2](https://rstudio.github.io/shinytest2/).
#' These child processes may not "know" that their parent
#' used the `load_all()`d version of an in-development package,
#' but may instead use whichever version was last installed.
#' This can lead to inconsistent results and painful confusion.
#' @noRd
1 change: 0 additions & 1 deletion R/tests.R
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ transform_with_generated <- function(x = character()) {
#' [checkmate](https://mllg.github.io/checkmate/index.html)'s
#' `check_*()`-type functions into [testthat](https://testthat.r-lib.org)'s
#' `skip_if_not_*()` functions.
#'
#' @inheritParams checkmate::makeAssertionFunction
#' @details
#' Notice that `check_*()` are always formulated *positively*;
Expand Down

0 comments on commit 601a2f6

Please sign in to comment.