Skip to content

Commit 78b6e1d

Browse files
committed
Merge commit '551f1018e62da2811bcd2a82032efef133b85d95'
2 parents dbf2745 + 551f101 commit 78b6e1d

118 files changed

Lines changed: 1965 additions & 671 deletions

File tree

Some content is hidden

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

.claude/settings.local.json

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
{
2+
"$schema": "https://json.schemastore.org/claude-code-settings.json",
23
"permissions": {
34
"allow": [
4-
"Bash(find:*)"
5+
"Bash(find:*)",
6+
"Bash(R:*)",
7+
"Bash(rm:*)",
8+
"Bash(air format:*)"
59
],
610
"deny": []
711
}
8-
}
12+
}

CLAUDE.md

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,16 @@ testthat is R's most popular unit testing framework, used by thousands of CRAN p
88

99
## Key Development Commands
1010

11-
### Testing
12-
- `devtools::test()` or `Ctrl/Cmd+Shift+T` in RStudio - Run all tests
13-
- `devtools::test_file("tests/testthat/test-filename.R")` - Run tests in a specific file
14-
- `testthat::test_local()` - Run tests for local source package
15-
- `testthat::test_package("testthat")` - Run tests for installed package
16-
- `R CMD check` - Full package check including tests
11+
General advice:
12+
* When running R from the console, always run it with `--quiet --vanilla`
13+
* Always run `air format .` after generating code
14+
15+
### Development tools
1716

18-
### Building and Installation
19-
- `devtools::load_all()` or `Ctrl/Cmd+Shift+L` - Load package for development
17+
- `devtools::test()` - Run all tests
18+
- `devtools::test_file("tests/testthat/test-filename.R")` - Run tests in a specific file
19+
- DO NOT USE `devtools::test_active_file()`
20+
- `devtools::load_all()` - Load package for development
2021
- `devtools::document()` - Generate documentation
2122
- `devtools::check()` - Run R CMD check
2223
- `devtools::install()` - Install package locally

DESCRIPTION

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -17,23 +17,23 @@ BugReports: https://github.com/r-lib/testthat/issues
1717
Depends:
1818
R (>= 4.1.0)
1919
Imports:
20-
brio (>= 1.1.3),
21-
callr (>= 3.7.3),
22-
cli (>= 3.6.1),
23-
desc (>= 1.4.2),
24-
evaluate (>= 1.0.1),
25-
jsonlite (>= 1.8.7),
26-
lifecycle (>= 1.0.3),
20+
brio (>= 1.1.5),
21+
callr (>= 3.7.6),
22+
cli (>= 3.6.5),
23+
desc (>= 1.4.3),
24+
evaluate (>= 1.0.4),
25+
jsonlite (>= 2.0.0),
26+
lifecycle (>= 1.0.4),
2727
magrittr (>= 2.0.3),
2828
methods,
29-
pkgload (>= 1.3.2.1),
29+
pkgload (>= 1.4.0),
3030
praise (>= 1.0.0),
31-
processx (>= 3.8.2),
32-
ps (>= 1.7.5),
33-
R6 (>= 2.5.1),
34-
rlang (>= 1.1.1),
31+
processx (>= 3.8.6),
32+
ps (>= 1.9.1),
33+
R6 (>= 2.6.1),
34+
rlang (>= 1.1.6),
3535
utils,
36-
waldo (>= 0.6.0),
36+
waldo (>= 0.6.2),
3737
withr (>= 3.0.2)
3838
Suggests:
3939
covr,

NAMESPACE

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ export(expect_no_warning)
114114
export(expect_null)
115115
export(expect_output)
116116
export(expect_output_file)
117+
export(expect_r6_class)
117118
export(expect_reference)
118119
export(expect_s3_class)
119120
export(expect_s4_class)
@@ -228,5 +229,6 @@ import(rlang)
228229
importFrom(R6,R6Class)
229230
importFrom(brio,readLines)
230231
importFrom(brio,writeLines)
232+
importFrom(lifecycle,deprecated)
231233
importFrom(magrittr,"%>%")
232234
useDynLib(testthat, .registration = TRUE)

NEWS.md

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

33
* Interrupting a test now prints the test name. This makes it easier to tell where a very slow test might be hanging (#1464)
4+
* `describe()`, `it()`, and `test_that()` now have a shared stack of descriptions so that if you nest any inside of each other, any resulting failures will show you the full path.
5+
* `describe()` now correctly scopes `skip()` (#2007).
6+
* `ParallelProgressReporter` now respect `max_failures` (#1162).
7+
* The last snapshot is no longer lost if the snapshot file is missing the final newline (#2092). It's easy to accidentally remove this because there are two trailing new lines in snapshot files and many editors will automatically remove if you touch the file.
8+
* New `expect_r6_class()` (#2030).
9+
* `expect_*()` functions consistently and rigorously check their inputs (#1754).
10+
* `JunitReporter()` no longer fails with `"no applicable method for xml_add_child"` for warnings outside of tests (#1913). Additionally, warnings now save their backtraces.
11+
* `JunitReporter()` strips ANSI escapes in more placese (#1852, #2032).
12+
* `try_again()` is now publicised. The first argument is now the number of retries, not tries (#2050).
13+
* `vignette("custom-expectations)` has been overhauled to make it much clearer how to create high-quality expectations (#2113, #2132, #2072).
14+
* `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).
415
* `expect_snapshot_value()` can now handle expressions that generate `-` (#1678) or zero length atomic vectors (#2042).
516
* `expect_matches()` failures should be a little easier to read (#2135).
617
* New `local_on_cran(TRUE)` allows you to simulate how your tests will run on CRAN (#2112).

R/auto-test.R

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,18 @@
11
#' Watches code and tests for changes, rerunning tests as appropriate.
22
#'
3+
#' @description
4+
#' `r lifecycle::badge("superseded")`
5+
#'
36
#' The idea behind `auto_test()` is that you just leave it running while
47
#' you develop your code. Every time you save a file it will be automatically
58
#' tested and you can easily see if your changes have caused any test
6-
#' failures.
9+
#' failures.
710
#'
811
#' The current strategy for rerunning tests is as follows:
912
#'
1013
#' - if any code has changed, then those files are reloaded and all tests
1114
#' rerun
1215
#' - otherwise, each new or modified test is run
13-
#'
14-
#' In the future, `auto_test()` might implement one of the following more
15-
#' intelligent alternatives:
16-
#'
17-
#' - Use codetools to build up dependency tree and then rerun tests only
18-
#' when a dependency changes.
19-
#' - Mimic ruby's autotest and rerun only failing tests until they pass,
20-
#' and then rerun all tests.
21-
#
2216
#' @seealso [auto_test_package()]
2317
#' @export
2418
#' @param code_path path to directory containing code
@@ -27,7 +21,7 @@
2721
#' @param env environment in which to execute test suite.
2822
#' @param hash Passed on to [watch()]. When FALSE, uses less accurate
2923
#' modification time stamps, but those are faster for large files.
30-
#' @keywords debugging
24+
#' @keywords internal
3125
auto_test <- function(
3226
code_path,
3327
test_path,
@@ -67,15 +61,12 @@ auto_test <- function(
6761
watch(c(code_path, test_path), watcher, hash = hash)
6862
}
6963

70-
#' Watches a package for changes, rerunning tests as appropriate.
71-
#'
7264
#' @param pkg path to package
7365
#' @export
7466
#' @param reporter test reporter to use
7567
#' @param hash Passed on to [watch()]. When FALSE, uses less accurate
7668
#' modification time stamps, but those are faster for large files.
77-
#' @keywords debugging
78-
#' @seealso [auto_test()] for details on how method works
69+
#' @rdname auto_test
7970
auto_test_package <- function(
8071
pkg = ".",
8172
reporter = default_reporter(),

R/compare.R

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ compare <- function(x, y, ...) {
1616
}
1717

1818
comparison <- function(equal = TRUE, message = "Equal") {
19-
stopifnot(is.logical(equal), length(equal) == 1)
20-
stopifnot(is.character(message))
19+
check_bool(equal)
20+
check_character(message)
2121

2222
structure(
2323
list(

R/deprec-condition.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ capture_warnings <- function(code, ignore_deprecation = FALSE) {
129129
}
130130

131131
get_messages <- function(x) {
132-
vapply(x, cnd_message, FUN.VALUE = character(1))
132+
map_chr(x, cnd_message)
133133
}
134134

135135
#' Is an error informative?

R/describe.R

Lines changed: 4 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -56,43 +56,17 @@
5656
#' it("can handle division by 0") #not yet implemented
5757
#' })
5858
#' })
59-
6059
describe <- function(description, code) {
61-
check_string(description, allow_empty = FALSE)
62-
describe_description <- description
63-
64-
# prepares a new environment for each it-block
65-
describe_environment <- new.env(parent = parent.frame())
66-
describe_environment$it <- function(description, code = NULL) {
67-
check_string(description, allow_empty = FALSE)
68-
code <- substitute(code)
69-
70-
description <- paste0(describe_description, ": ", description)
71-
describe_it(description, code, describe_environment)
72-
}
73-
74-
eval(substitute(code), describe_environment)
75-
invisible()
76-
}
77-
78-
describe_it <- function(description, code, env = parent.frame()) {
79-
reporter <- get_reporter() %||% local_interactive_reporter()
80-
local_test_context()
60+
local_description_push(description)
8161

82-
test_code(
83-
description,
84-
code,
85-
env = env,
86-
reporter = reporter,
87-
skip_on_empty = FALSE
88-
)
62+
test_code(code, parent.frame(), skip_on_empty = FALSE)
8963
}
9064

9165
#' @export
9266
#' @rdname describe
9367
it <- function(description, code = NULL) {
94-
check_string(description, allow_empty = FALSE)
68+
local_description_push(description)
9569

9670
code <- substitute(code)
97-
describe_it(description, code, env = parent.frame())
71+
test_code(code, env = parent.frame(), skip_on_empty = FALSE)
9872
}

R/expect-comparison.R

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -54,35 +54,35 @@ expect_compare_ <- function(
5454
#' @export
5555
#' @rdname comparison-expectations
5656
expect_lt <- function(object, expected, label = NULL, expected.label = NULL) {
57-
act <- quasi_label(enquo(object), label, arg = "object")
58-
exp <- quasi_label(enquo(expected), expected.label, arg = "expected")
57+
act <- quasi_label(enquo(object), label)
58+
exp <- quasi_label(enquo(expected), expected.label)
5959

6060
expect_compare_("<", act, exp)
6161
}
6262

6363
#' @export
6464
#' @rdname comparison-expectations
6565
expect_lte <- function(object, expected, label = NULL, expected.label = NULL) {
66-
act <- quasi_label(enquo(object), label, arg = "object")
67-
exp <- quasi_label(enquo(expected), expected.label, arg = "expected")
66+
act <- quasi_label(enquo(object), label)
67+
exp <- quasi_label(enquo(expected), expected.label)
6868

6969
expect_compare_("<=", act, exp)
7070
}
7171

7272
#' @export
7373
#' @rdname comparison-expectations
7474
expect_gt <- function(object, expected, label = NULL, expected.label = NULL) {
75-
act <- quasi_label(enquo(object), label, arg = "object")
76-
exp <- quasi_label(enquo(expected), expected.label, arg = "expected")
75+
act <- quasi_label(enquo(object), label)
76+
exp <- quasi_label(enquo(expected), expected.label)
7777

7878
expect_compare_(">", act, exp)
7979
}
8080

8181
#' @export
8282
#' @rdname comparison-expectations
8383
expect_gte <- function(object, expected, label = NULL, expected.label = NULL) {
84-
act <- quasi_label(enquo(object), label, arg = "object")
85-
exp <- quasi_label(enquo(expected), expected.label, arg = "expected")
84+
act <- quasi_label(enquo(object), label)
85+
exp <- quasi_label(enquo(expected), expected.label)
8686

8787
expect_compare_(">=", act, exp)
8888
}

0 commit comments

Comments
 (0)