Skip to content

Commit 7feb406

Browse files
committed
Merge branch 'main' into feature/add-recursive-dirs
2 parents ca0543e + c0845db commit 7feb406

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

57 files changed

+649
-806
lines changed

DESCRIPTION

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Package: testthat
22
Title: Unit Testing for R
3-
Version: 3.1.10.9001
3+
Version: 3.2.0.9001
44
Authors@R: c(
55
person("Hadley", "Wickham", , "[email protected]", role = c("aut", "cre")),
66
person("Posit Software, PBC", role = c("cph", "fnd")),
@@ -15,28 +15,28 @@ License: MIT + file LICENSE
1515
URL: https://testthat.r-lib.org, https://github.com/r-lib/testthat
1616
BugReports: https://github.com/r-lib/testthat/issues
1717
Depends:
18-
R (>= 3.1)
18+
R (>= 3.6.0)
1919
Imports:
20-
brio,
21-
callr (>= 3.5.1),
22-
cli (>= 3.4.0),
23-
desc,
24-
digest,
25-
ellipsis (>= 0.2.0),
26-
evaluate,
27-
jsonlite,
28-
lifecycle,
29-
magrittr,
20+
brio (>= 1.1.3),
21+
callr (>= 3.7.3),
22+
cli (>= 3.6.1),
23+
desc (>= 1.4.2),
24+
digest (>= 0.6.33),
25+
ellipsis (>= 0.3.2),
26+
evaluate (>= 0.21),
27+
jsonlite (>= 1.8.7),
28+
lifecycle (>= 1.0.3),
29+
magrittr (>= 2.0.3),
3030
methods,
31-
pkgload (>= 1.3.0),
32-
praise,
31+
pkgload (>= 1.3.2.1),
32+
praise (>= 1.0.0),
3333
processx (>= 3.8.2),
34-
ps (>= 1.3.4),
35-
R6 (>= 2.2.0),
36-
rlang (>= 1.1.0),
34+
ps (>= 1.7.5),
35+
R6 (>= 2.5.1),
36+
rlang (>= 1.1.1),
3737
utils,
38-
waldo (>= 0.5.0),
39-
withr (>= 2.4.3)
38+
waldo (>= 0.5.1),
39+
withr (>= 2.5.0)
4040
Suggests:
4141
covr,
4242
curl (>= 0.9.5),

NAMESPACE

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ S3method(format,expectation)
1414
S3method(format,expectation_success)
1515
S3method(format,mismatch_character)
1616
S3method(format,mismatch_numeric)
17-
S3method(is_informative_error,default)
1817
S3method(output_replay,character)
1918
S3method(output_replay,error)
2019
S3method(output_replay,message)

NEWS.md

Lines changed: 48 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,59 @@
11
# testthat (development version)
22

3+
* Adds `recursive` parameter to `test_dir()` to allow the use of directories to
4+
organize test files (@radbasa, #1605).
5+
6+
# testthat 3.2.0
7+
8+
## Lifecycle changes
9+
10+
* `is_informative_error()` and the `wrap` argument to `test_dir()` and friends
11+
are now defunct.
12+
13+
* `expect_no_error()`, `expect_no_warning()`, `expect_no_message()`,
14+
`expect_no_condition()`, `local_mocked_bindings()`, and
15+
`with_mocked_bindings()` are now stable, not experimental.
16+
17+
## New features
18+
19+
* All packages, regardless of whether or not they use rlang 1.0.0, now
20+
use the new snapshot display for errors, warnings, and messages (#1856).
21+
This no longer shows the class name, instead focussing on a display that
22+
more closely mimics what you'll see interactively, including showing the
23+
error call.
24+
325
* testthat uses an improved algorithm for finding the srcref associated with
426
an expectation/error/warning/skip. It now looks for the most recent call
527
that has known source and is found inside the `test_that()` call. This
628
generally gives more specific locations than the previous approach and
729
gives much better locations if an error occurs in an exit handler.
830

9-
* Helpers should no longer be run twice.
31+
## Minor features and bug fixes
32+
33+
* Helpers are no longer run twice.
34+
35+
* `expect_setequal()` correctly displays results when only one of actual and
36+
expected is missing elements (#1835).
37+
38+
* `expect_snapshot()` and friends no longer create a temporary file on every
39+
invocation.
40+
41+
* `expect_snapshot_file()` now generates clickable links to review changes
42+
(#1821).
43+
44+
* `expect_snapshot_value()` has an improved error if the object can't be
45+
safely serialized using the specified `style` (#1771).
46+
47+
* `options(rlang_interactive = TRUE)` no longer causes `skip_on_cran()` to
48+
not run on CRAN (#1868).
49+
50+
* `skip_if_offline()` now errors if you don't have curl installed (#1854).
51+
52+
* `StopReporter` gains the ability to suppress praise when a test passes.
53+
54+
* `ProgressReporter` now uses is a two characters wide skip column in order
55+
to have a consistent width when 10 or more tests are skipped in a single file
56+
(@mgirlich, #1844).
1057

1158
* `test_file()` gains a `desc` argument which allows you to run a single
1259
test from a file (#1776).
@@ -54,9 +101,6 @@
54101

55102
* `teardown_env()` works in more cases.
56103

57-
* All packages, regardless of whether or not they use rlang, now
58-
use the new snapshot display for errors, warnings, and messages.
59-
60104
* testthat no longer truncates tracebacks and uses rlang's default tree
61105
display.
62106

R/deprec-condition.R

Lines changed: 1 addition & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -141,25 +141,5 @@ get_messages <- function(x) {
141141
#' @keywords internal
142142
#' @export
143143
is_informative_error <- function(x, ...) {
144-
lifecycle::deprecate_warn("3.0.0", "is_informative_error()")
145-
ellipsis::check_dots_empty()
146-
147-
if (!inherits(x, "error")) {
148-
return(TRUE)
149-
}
150-
151-
if (inherits(x, c("simpleError", "Rcpp::eval_error", "Rcpp::exception"))) {
152-
return(FALSE)
153-
}
154-
155-
if (inherits_only(x, c("rlang_error", "error", "condition"))) {
156-
return(FALSE)
157-
}
158-
159-
UseMethod("is_informative_error")
160-
}
161-
162-
#' @export
163-
is_informative_error.default <- function(x, ...) {
164-
TRUE
144+
lifecycle::deprecate_stop("3.0.0", "is_informative_error()")
165145
}

R/edition.R

Lines changed: 0 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -73,33 +73,3 @@ local_edition <- function(x, .env = parent.frame()) {
7373
edition_get <- function() {
7474
the$edition %||% find_edition(".")
7575
}
76-
77-
78-
find_dep_version <- function(name, path, package = NULL) {
79-
desc <- find_description(path, package)
80-
if (is.null(desc)) {
81-
return(NULL)
82-
}
83-
84-
deps <- desc$get_deps()
85-
i <- match(name, deps[["package"]])
86-
if (is_na(i)) {
87-
return(NULL)
88-
}
89-
90-
dep <- deps[[i, "version"]]
91-
dep <- strsplit(dep, " ")[[1]]
92-
if (!is_character(dep, 2) && !is_string(dep[[1]], ">=")) {
93-
return(NULL)
94-
}
95-
96-
dep[[2]]
97-
}
98-
has_dep <- function(name, path, package = NULL) {
99-
!is.null(find_dep_version(name, path, package = package))
100-
}
101-
102-
use_rlang_1_0 <- function() {
103-
rlang::is_true(peek_option("testthat:::rlang_dep")) &&
104-
is_installed("rlang", version = "0.99.0.9001")
105-
}

R/expect-no-condition.R

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
#' Does code run without error, warning, message, or other condition?
22
#'
33
#' @description
4-
#' `r lifecycle::badge("experimental")`
5-
#'
64
#' These expectations are the opposite of [expect_error()],
75
#' `expect_warning()`, `expect_message()`, and `expect_condition()`. They
86
#' assert the absence of an error, warning, or message, respectively.
@@ -11,7 +9,7 @@
119
#' @param message,class The default, `message = NULL, class = NULL`,
1210
#' will fail if there is any error/warning/message/condition.
1311
#'
14-
#' If many cases, particularly when testing warnings and message, you will
12+
#' In many cases, particularly when testing warnings and messages, you will
1513
#' want to be more specific about the condition you are hoping **not** to see,
1614
#' i.e. the condition that motivated you to write the test. Similar to
1715
#' `expect_error()` and friends, you can specify the `message` (a regular

R/local.R

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -174,10 +174,6 @@ local_test_directory <- function(path, package = NULL, .env = parent.frame()) {
174174
# Set edition before changing working directory in case path is relative
175175
local_edition(find_edition(path, package), .env = .env)
176176

177-
withr::local_options(
178-
"testthat:::rlang_dep" = has_dep("rlang", path, package),
179-
.local_envir = .env
180-
)
181177
withr::local_dir(
182178
path,
183179
.local_envir = .env

R/mock.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
#' @param .env the environment in which to patch the functions,
2121
#' defaults to the top-level environment. A character is interpreted as
2222
#' package name.
23-
#' @param .local_env Environment in which to add exit handler.
23+
#' @param .local_envir Environment in which to add exit handler.
2424
#' For expert use only.
2525
#' @keywords internal
2626
#' @return The result of the last unnamed parameter

R/mock2.R

Lines changed: 29 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
#' Mocking tools
22
#'
33
#' @description
4-
#' `r lifecycle::badge("experimental")`
5-
#'
64
#' `with_mocked_bindings()` and `local_mocked_bindings()` provide tools for
75
#' "mocking", temporarily redefining a function so that it behaves differently
86
#' during tests. This is helpful for testing functions that depend on external
@@ -48,11 +46,21 @@
4846
#'
4947
#' ## Base functions
5048
#'
51-
#' Note that it's not possible to mock functions in the base namespace
52-
#' (i.e. functions that you can use without explicitly importing them)
53-
#' since currently we don't know of a way to to mock them without potentially
54-
#' affecting all running code. If you need to mock a base function, you'll
55-
#' need to create a wrapper, as described below.
49+
#' To mock a function in the base package, you need to make sure that you
50+
#' have a binding for this function in your package. It's easiest to do this
51+
#' by binding the value to `NULL`. For example, if you wanted to mock
52+
#' `interactive()` in your package, you'd need to include this code somewhere
53+
#' in your package:
54+
#'
55+
#' ```R
56+
#' interactive <- NULL
57+
#' ```
58+
#'
59+
#' Why is this necessary? `with_mocked_bindings()` and `local_mocked_bindings()`
60+
#' work by temporarily modifying the bindings within your package's namespace.
61+
#' When these tests are running inside of `R CMD check` the namespace is locked
62+
#' which means it's not possible to create new bindings so you need to make sure
63+
#' that the binding exists already.
5664
#'
5765
#' ## Namespaced calls
5866
#'
@@ -65,21 +73,12 @@
6573
#' }
6674
#' ```
6775
#'
68-
#' To mock here, you'll need to modify `another_function()` inside the
76+
#' To mock this function, you'd need to modify `another_function()` inside the
6977
#' `anotherpackage` package. You _can_ do this by supplying the `.package`
70-
#' argument:
71-
#'
72-
#' ```R
73-
#' local_mocked_bindings(
74-
#' another_function = function(...) "new_value",
75-
#' .package = "anotherpackage"
76-
#' )
77-
#' ```
78-
#'
79-
#' But it's not a great idea to mock a namespace that you don't own because
80-
#' it affects all code in that package, not just code in your package. Instead,
81-
#' it's safer to either import the function into your package, or make a wrapper
82-
#' that you can mock:
78+
#' argument to `local_mocked_bindings()` but we don't recommend it because
79+
#' it will affect all calls to `anotherpackage::another_function()`, not just
80+
#' the calls originating in your package. Instead, it's safer to either import
81+
#' the function into your package, or make a wrapper that you can mock:
8382
#'
8483
#' ```R
8584
#' some_function <- function() {
@@ -98,10 +97,11 @@
9897
#' @param code Code to execute with specified bindings.
9998
#' @param .env Environment that defines effect scope. For expert use only.
10099
#' @param .package The name of the package where mocked functions should be
101-
#' inserted. Generally, you should not need to supply this as it will be
102-
#' automatically detected when whole package tests are run or when there's
103-
#' one package under active development (i.e. loaded with
104-
#' [pkgload::load_all()]).
100+
#' inserted. Generally, you should not supply this as it will be automatically
101+
#' detected when whole package tests are run or when there's one package
102+
#' under active development (i.e. loaded with [pkgload::load_all()]).
103+
#' We don't recommend using this to mock functions in other packages,
104+
#' as you should not modify namespaces that you don't own.
105105
local_mocked_bindings <- function(..., .package = NULL, .env = caller_env()) {
106106
bindings <- list2(...)
107107
check_bindings(bindings)
@@ -232,6 +232,10 @@ test_mock_method.integer <- function(x) {
232232
"y"
233233
}
234234

235+
test_mock_base <- function() {
236+
interactive()
237+
}
238+
interactive <- NULL
235239

236240
show_bindings <- function(name, env = caller_env()) {
237241
envs <- env_parents(env)

R/reporter-junit.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ JunitReporter <- R6::R6Class("JunitReporter",
136136
if (is.character(self$out)) {
137137
xml2::write_xml(self$doc, self$out, format = TRUE)
138138
} else if (inherits(self$out, "connection")) {
139-
file <- tempfile()
139+
file <- withr::local_tempfile()
140140
xml2::write_xml(self$doc, file, format = TRUE)
141141
cat(brio::read_file(file), file = self$out)
142142
} else {

0 commit comments

Comments
 (0)