Skip to content

Commit d9be2ea

Browse files
committed
Merged origin/main into snapshot-skip
2 parents 058455d + 8d08da2 commit d9be2ea

File tree

193 files changed

+6642
-1103
lines changed

Some content is hidden

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

193 files changed

+6642
-1103
lines changed

.claude/settings.local.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,10 @@
55
"Bash(find:*)",
66
"Bash(R:*)",
77
"Bash(rm:*)",
8-
"Bash(air format:*)"
8+
"Bash(air format:*)",
9+
"Edit(R/**)",
10+
"Edit(tests/**)",
11+
"Edit(vignettes/**)"
912
],
1013
"deny": []
1114
}

CLAUDE.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,13 @@ General advice:
1818
- `devtools::test_file("tests/testthat/test-filename.R")` - Run tests in a specific file
1919
- DO NOT USE `devtools::test_active_file()`
2020
- `devtools::load_all()` - Load package for development
21-
- `devtools::document()` - Generate documentation
2221
- `devtools::check()` - Run R CMD check
2322
- `devtools::install()` - Install package locally
2423

24+
### Documentation
25+
26+
- Always run `devtools::document()` after changing any roxygen2 docs.
27+
2528
## Core Architecture
2629

2730
### Main Components

NAMESPACE

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ export(ProgressReporter)
4545
export(RStudioReporter)
4646
export(Reporter)
4747
export(SilentReporter)
48+
export(SlowReporter)
4849
export(StopReporter)
4950
export(SummaryReporter)
5051
export(TapReporter)
@@ -191,6 +192,7 @@ export(skip_on_os)
191192
export(skip_on_travis)
192193
export(skip_unless_r)
193194
export(snapshot_accept)
195+
export(snapshot_reject)
194196
export(snapshot_review)
195197
export(source_dir)
196198
export(source_file)

NEWS.md

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,20 @@
11
# testthat (development version)
22

33
* `snapshot_review()` disables the skip button if there's only one snapshot to review (#2025).
4+
* `test_dir()`, `test_file()`, `test_package()`, `test_check()`, `test_local()`, `source_file()` gain a `shuffle` argument uses `sample()` to randomly reorder the top-level expressions in each test file (#1942). This random reordering surfaces dependencies between tests and code outside of any test, as well as dependencies between tests. This helps you find and eliminate unintentional dependencies.
5+
* `snapshot_accept(test)` now works when the test file name contains `.` (#1669).
6+
* `local_mock()` and `with_mock()` have been deprecated because they are no longer permitted in R 4.5.
7+
* `snapshot_review()` now passes `...` on to `shiny::runApp()` (#1928).
8+
* `expect_named()` now gives more informative errors (#2091).
9+
* `expect_*()` functions consistently and rigorously check their inputs (#1754).
10+
* `test_that()` no longer warns about the absence of `{}` since it no longer seems to be necessary.
11+
* `test_that()`, `describe()`, and `it()` can now be arbitrarily nested. Each component will skip only if it and its subtests don't contain any expectations. The interactive stop reporter has been fixed so it doesn't duplicate failures. (#2063, #2188).
12+
* Test filtering now works with `it()`, and the `desc` argument can take a character vector in order to recursively filter subtests (i.e. `it()` nested inside of `describe()`) (#2118).
13+
* New `snapshot_reject()` rejects all modified snapshots by deleting the `.new` variants (#1923).
14+
* New `SlowReporter` makes it easier to find the slowest tests in your package. The easiest way to run it is with `devtools::test(reporter = "slow")` (#1466).
15+
* Power `expect_mapequal()` with `waldo::compare(list_as_map = TRUE)` (#1521).
16+
* On CRAN, `test_that()` now automatically skips if a package is not installed (#1585). Practically, this means that you no longer need to check that suggested packages are installed. (We don't do this in the tidyverse because we think it has limited payoff, but other styles advise differently.)
17+
* `expect_snapshot()` no longer skips on CRAN, as that skips the rest of the test. Instead it just returns, neither succeeding nor failing (#1585).
418
* Interrupting a test now prints the test name. This makes it easier to tell where a very slow test might be hanging (#1464)
519
* Parallel testthat now does not ignore test files with syntax errors (#1360).
620
* `expect_lt()`, `expect_gt()`, and friends have a refined display that is more likely to display the correct number of digits and shows you the actual values compared.
@@ -16,7 +30,7 @@
1630
* `vignette("custom-expectations)` has been overhauled to make it much clearer how to create high-quality expectations (#2113, #2132, #2072).
1731
* `expect_snapshot()` and friends will now fail when creating a new snapshot on CI. This is usually a signal that you've forgotten to run it locally before committing (#1461).
1832
* `expect_snapshot_value()` can now handle expressions that generate `-` (#1678) or zero length atomic vectors (#2042).
19-
* `expect_matches()` failures should be a little easier to read (#2135).
33+
* `expect_matches()` failures should be a little easier to read (#2135, #2181).
2034
* New `local_on_cran(TRUE)` allows you to simulate how your tests will run on CRAN (#2112).
2135
* `expect_no_*()` now executes the entire code block, rather than stopping at the first message or warning (#1991).
2236
* `expect_no_failures()` and `expect_no_successes()` are now deprecated as `expect_success()` now test for no failures and `expect_failure()` tests for no successes (#)

R/describe.R

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
#'
2727
#' @param description description of the feature
2828
#' @param code test code containing the specs
29+
#' @keywords internal
2930
#' @export
3031
#' @examples
3132
#' describe("matrix()", {
@@ -59,7 +60,8 @@
5960
describe <- function(description, code) {
6061
local_description_push(description)
6162

62-
test_code(code, parent.frame(), skip_on_empty = FALSE)
63+
code <- substitute(code)
64+
test_code(code, parent.frame())
6365
}
6466

6567
#' @export
@@ -68,5 +70,5 @@ it <- function(description, code = NULL) {
6870
local_description_push(description)
6971

7072
code <- substitute(code)
71-
test_code(code, env = parent.frame(), skip_on_empty = FALSE)
73+
test_code(code, parent.frame())
7274
}

R/edition.R

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ edition_deprecate <- function(in_edition, what, instead = NULL) {
2727
return()
2828
}
2929

30-
warn(c(
31-
paste0("`", what, "` was deprecated in ", edition_name(in_edition), "."),
30+
cli::cli_warn(c(
31+
"{.code {what}} was deprecated in {edition_name(in_edition)}.",
3232
i = instead
3333
))
3434
}
@@ -40,7 +40,7 @@ edition_require <- function(in_edition, what) {
4040
return()
4141
}
4242

43-
stop(paste0("`", what, "` requires ", edition_name(in_edition), "."))
43+
cli::cli_abort("{.code {what}} requires {edition_name(in_edition)}.")
4444
}
4545

4646
edition_name <- function(x) {

R/expect-comparison.R

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#' Does code return a number greater/less than the expected value?
1+
#' Do you expect a number bigger or smaller than this?
22
#'
33
#' @inheritParams expect_equal
44
#' @param object,expected A value to compare and its expected bound.
@@ -39,7 +39,10 @@ expect_compare_ <- function(
3939

4040
cmp <- op(act$val, exp$val)
4141
if (length(cmp) != 1 || !is.logical(cmp)) {
42-
abort("Result of comparison must be a single logical value")
42+
cli::cli_abort(
43+
"Result of comparison must be a single logical value.",
44+
call = trace_env
45+
)
4346
}
4447
if (!isTRUE(cmp)) {
4548
digits <- max(
@@ -109,14 +112,14 @@ expect_gte <- function(object, expected, label = NULL, expected.label = NULL) {
109112
#' @param ... All arguments passed on to `expect_lt()`/`expect_gt()`.
110113
#' @keywords internal
111114
expect_less_than <- function(...) {
112-
warning("Deprecated: please use `expect_lt()` instead", call. = FALSE)
115+
cli::cli_warn("Deprecated: please use {.fn expect_lt} instead.")
113116
expect_lt(...)
114117
}
115118

116119
#' @rdname expect_less_than
117120
#' @export
118121
expect_more_than <- function(...) {
119-
warning("Deprecated: please use `expect_gt()` instead", call. = FALSE)
122+
cli::cli_warn("Deprecated: please use {.fn expect_gt} instead.")
120123
expect_gt(...)
121124
}
122125

R/expect-condition.R

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#' Does code throw an error, warning, message, or other condition?
1+
#' Do you expect an error, warning, message, or other condition?
22
#'
33
#' @description
44
#' `expect_error()`, `expect_warning()`, `expect_message()`, and
@@ -169,7 +169,7 @@ expect_warning <- function(
169169

170170
if (edition_get() >= 3) {
171171
if (!missing(all)) {
172-
warn("The `all` argument is deprecated")
172+
cli::cli_warn("The {.arg all} argument is deprecated.")
173173
}
174174

175175
expect_condition_matching_(

R/expect-constant.R

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#' Does code return `TRUE` or `FALSE`?
1+
#' Do you expect `TRUE` or `FALSE`?
22
#'
33
#' @description
44
#' These are fall-back expectations that you can use when none of the other
@@ -42,7 +42,7 @@ expect_false <- function(object, info = NULL, label = NULL) {
4242
expect_waldo_equal_("equal", act, exp, info = info, ignore_attr = TRUE)
4343
}
4444

45-
#' Does code return `NULL`?
45+
#' Do you expect `NULL`?
4646
#'
4747
#' This is a special case because `NULL` is a singleton so it's possible
4848
#' check for it either with `expect_equal(x, NULL)` or `expect_type(x, "NULL")`.

R/expect-equality.R

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#' Does code return the expected value?
1+
#' Do you expect this value?
22
#'
33
#' @description
44
#' These functions provide two levels of strictness when comparing a
@@ -126,7 +126,8 @@ expect_waldo_equal_ <- function(
126126
exp,
127127
info = NULL,
128128
...,
129-
trace_env = caller_env()
129+
trace_env = caller_env(),
130+
error_prefix = NULL
130131
) {
131132
comp <- waldo_compare(
132133
act$val,
@@ -145,6 +146,7 @@ expect_waldo_equal_ <- function(
145146
"`expected`",
146147
paste0(comp, collapse = "\n\n")
147148
)
149+
msg <- paste0(error_prefix, msg)
148150
return(fail(msg, info = info, trace_env = trace_env))
149151
}
150152
pass(act$val)

0 commit comments

Comments
 (0)