diff --git a/R/assert-version.R b/R/assert-version.R index 4aea58f..07c262f 100644 --- a/R/assert-version.R +++ b/R/assert-version.R @@ -86,10 +86,10 @@ assert_version_package <- function( installation_message <- if (1L <= nchar(installation_code)) { - " Install the package with `%s`." |> + " Install the package with `%s`. Afterwards, please restart the R session." |> sprintf(installation_code) } else { - "" + " Afterwards, please restart the R session." } if (!package_is_installed) { diff --git a/tests/testthat/test-assert-version-package.R b/tests/testthat/test-assert-version-package.R index 2c8dd08..3b50ffc 100644 --- a/tests/testthat/test-assert-version-package.R +++ b/tests/testthat/test-assert-version-package.R @@ -14,7 +14,7 @@ test_that("old minimum", { expect_true(r) }) -test_that("minimum that throws an error", { +test_that("minimum that throws an error -base", { expected_error_message <- "Your version of the `base` package is too old" expect_error( assert_version_package("base", "99.1.0"), @@ -26,5 +26,28 @@ test_that("minimum that throws an error", { expected_error_message ) }) -stop("TODO: test installation message for non-existent package.") -stop("TODO: test installation message for an old package.") +test_that("minimum that throws an error -tibble", { + expected_error_message <- "Your version of the `tibble` package is too old" + expect_error( + assert_version_package("tibble", "99.1.0"), + expected_error_message + ) + + expect_error( + assert_version_package("tibble", package_version("99.1.0")), + expected_error_message + ) +}) +test_that("missing package throws an error", { + expected_error_message <- "The package 'tibbleeee' not installed\\. Afterwards, please restart the R session\\." + + expect_error( + assert_version_package("tibbleeee", "99.1.0"), + expected_error_message + ) + + expect_error( + assert_version_package("tibbleeee", "99.1.0"), + expected_error_message + ) +})