Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# testthat (development version)

* `set_state_inspector()` gains `tolerance` argument and ignores minor FP differences by default (@mcol, #2237).
* `expect_vector()` fails, instead of erroring, if `object` is not a vector (@plietar, #2224).
* New `vignette("mocking")` explains mocking in detail (#1265).
* New `vignette("challenging-functions")` provides an index to other documentation organised by testing challenges (#1265).
Expand Down
12 changes: 10 additions & 2 deletions R/test-state.R
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@
#' @export
#' @param callback Either a zero-argument function that returns an object
#' capturing global state that you're interested in, or `NULL`.
set_state_inspector <- function(callback) {
#' @inheritParams waldo::compare
set_state_inspector <- function(callback, tolerance = testthat_tolerance()) {
if (
!is.null(callback) &&
!(is.function(callback) && length(formals(callback)) == 0)
Expand All @@ -51,11 +52,18 @@ set_state_inspector <- function(callback) {
}

the$state_inspector <- callback
the$state_inspector_tolerance <- tolerance
invisible()
}

testthat_state_condition <- function(before, after, call) {
diffs <- waldo_compare(before, after, x_arg = "before", y_arg = "after")
diffs <- waldo_compare(
before,
after,
x_arg = "before",
y_arg = "after",
tolerance = the$state_inspector_tolerance
)

if (length(diffs) == 0) {
return(NULL)
Expand Down
15 changes: 14 additions & 1 deletion man/set_state_inspector.Rd

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