Skip to content

Commit

Permalink
Merge branch 'r-lib:main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
LDSamson committed Dec 12, 2023
2 parents a20a6d8 + fe50a22 commit e679de8
Show file tree
Hide file tree
Showing 26 changed files with 1,378 additions and 79 deletions.
3 changes: 1 addition & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: testthat
Title: Unit Testing for R
Version: 3.2.0.9000
Version: 3.2.1.9000
Authors@R: c(
person("Hadley", "Wickham", , "hadley@posit.co", role = c("aut", "cre")),
person("Posit Software, PBC", role = c("cph", "fnd")),
Expand All @@ -22,7 +22,6 @@ Imports:
cli (>= 3.6.1),
desc (>= 1.4.2),
digest (>= 0.6.33),
ellipsis (>= 0.3.2),
evaluate (>= 0.21),
jsonlite (>= 1.8.7),
lifecycle (>= 1.0.3),
Expand Down
18 changes: 18 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,26 @@
# testthat (development version)

# testthat 3.2.1

* Fix incorrect format string detected by latest R-devel. Fix thanks to
Tomas Kalibera.

* `expect_snapshot()` handles unexpected errors like errors outside of
snapshots, i.e. they terminate the entire test and get a traceback (#1906).

* `JunitReporter()` now uses ensures numeric values are saved the xml file
with `.` as decimal separator. (@maksymiuks, #1660)

* `local_mocked_bindings()` can now mock any object, not just functions
(#1896).

* `skip_if_offline()` now uses `captive.apple.com` by default. This is the
hostname that Apple devices use to check that they're online so it should
have a higher reliability than `r-project.org` (@jdblischak, #1890).

* `test_file(desc = )` will now find `describe()` tests as well as `test_that()`
tests (#1903).

# testthat 3.2.0

## Lifecycle changes
Expand Down
2 changes: 1 addition & 1 deletion R/deprec-condition.R
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ get_messages <- function(x) {
#' has been deprecated.
#'
#' @param x An error object.
#' @inheritParams ellipsis::dots_empty
#' @inheritParams rlang::args_dots_empty
#'
#' @details
#' A few classes are hard-coded as uninformative:
Expand Down
7 changes: 5 additions & 2 deletions R/expect-condition.R
Original file line number Diff line number Diff line change
Expand Up @@ -254,8 +254,11 @@ expect_condition_matching <- function(base_class,
inherit = TRUE,
info = NULL,
label = NULL,
trace_env = caller_env()) {
ellipsis::check_dots_used(action = warn)
trace_env = caller_env(),
error_call = caller_env()) {
check_dots_used(error = function(cnd) {
warn(conditionMessage(cnd), call = error_call)
})

matcher <- cnd_matcher(
base_class,
Expand Down
13 changes: 4 additions & 9 deletions R/mock2.R
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,8 @@
#' )
#' ```
#' @export
#' @param ... Name-value pairs providing functions to mock.
#' @param ... Name-value pairs providing new values (typically functions) to
#' temporarily replace the named bindings.
#' @param code Code to execute with specified bindings.
#' @param .env Environment that defines effect scope. For expert use only.
#' @param .package The name of the package where mocked functions should be
Expand Down Expand Up @@ -195,14 +196,6 @@ check_bindings <- function(x, error_call = caller_env()) {
call = error_call
)
}

is_fun <- map_lgl(x, is.function)
if (!any(is_fun)) {
cli::cli_abort(
"All elements of {.arg ...} must be functions.",
call = error_call
)
}
}

# For testing -------------------------------------------------------------
Expand Down Expand Up @@ -244,6 +237,8 @@ show_bindings <- function(name, env = caller_env()) {
invisible()
}

test_mock_value <- 10

env_desc <- function(env) {
cat(obj_address(env), ": ", env_name(env), "\n", sep = "")
}
2 changes: 1 addition & 1 deletion R/skip.R
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ package_version <- function(x) {

#' @export
#' @rdname skip
skip_if_offline <- function(host = "r-project.org") {
skip_if_offline <- function(host = "captive.apple.com") {
skip_on_cran()
check_installed("curl")

Expand Down
2 changes: 1 addition & 1 deletion R/snapshot.R
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ expect_snapshot <- function(x,
if (error) {
expect(FALSE, msg, trace = state$error[["trace"]])
} else {
exp_signal(expectation("error", msg, trace = state$error[["trace"]]))
cnd_signal(state$error)
}
return()
}
Expand Down
2 changes: 1 addition & 1 deletion R/source.R
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ filter_desc <- function(exprs, desc = NULL, error_call = caller_env()) {
for (i in seq_along(exprs)) {
expr <- exprs[[i]]

if (!is_call(expr, "test_that", n = 2)) {
if (!is_call(expr, c("test_that", "describe"), n = 2)) {
if (!found) {
include[[i]] <- TRUE
}
Expand Down
2 changes: 1 addition & 1 deletion R/test-files.R
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ test_dir <- function(path,
#' @param path Path to file.
#' @param ... Additional parameters passed on to `test_dir()`
#' @param desc Optionally, supply a string here to run only a single
#' test that has this `desc`ription.
#' test (`test_that()` or `describe()`) with this `desc`ription.
#' @export
#' @examples
#' path <- testthat_example("success")
Expand Down
19 changes: 0 additions & 19 deletions R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -9,31 +9,12 @@ escape_regex <- function(x) {
gsub(paste0("([\\", paste0(collapse = "\\", chars), "])"), "\\\\\\1", x, perl = TRUE)
}

# For R 3.1
dir.exists <- function(paths) {
file.exists(paths) & file.info(paths)$isdir
}

maybe_restart <- function(restart) {
if (!is.null(findRestart(restart))) {
invokeRestart(restart)
}
}

# Backport for R 3.2
strrep <- function(x, times) {
x = as.character(x)
if (length(x) == 0L)
return(x)
unlist(.mapply(function(x, times) {
if (is.na(x) || is.na(times))
return(NA_character_)
if (times <= 0L)
return("")
paste0(replicate(times, x), collapse = "")
}, list(x = x, times = times), MoreArgs = list()), use.names = FALSE)
}

# Backport for R < 4.0
deparse1 <- function(expr, ...) paste(deparse(expr, ...), collapse = "\n")

Expand Down
23 changes: 1 addition & 22 deletions cran-comments.md
Original file line number Diff line number Diff line change
@@ -1,24 +1,3 @@
## revdepcheck results

We checked 7822 reverse dependencies, comparing R CMD check results across CRAN and dev versions of this package.

* We saw 0 new problems
* We failed to check 13 packages

Issues with CRAN packages are summarised below.

### Failed to check

* bayesdfa (NA)
* Boom (NA)
* CausalImpact (NA)
* ctsem (NA)
* fdaPDE (NA)
* loon.ggplot (NA)
* loon.shiny (NA)
* loon.tourr (NA)
* Rborist (NA)
* rstanarm (NA)
* SSVS (NA)
* tidyfit (NA)
* vivid (NA)
We checked all reverse dependencies, comparing R CMD check results across CRAN and dev versions of this package. Unfortunately something is up with our revdep test system and I failed to check ~1200 packages. I'm pretty confident these are bioconductor packages and unrelated to changes to testthat.
2 changes: 1 addition & 1 deletion inst/include/testthat/testthat.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ class r_streambuf : public std::streambuf {
if (n == 1)
Rprintf("%c", *s);
else
Rprintf("%.*s", n, s);
Rprintf("%.*s", static_cast<int>(n), s);

return n;

Expand Down
3 changes: 2 additions & 1 deletion man/local_mocked_bindings.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/skip.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/test_file.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit e679de8

Please sign in to comment.