Skip to content

Commit 7a6169c

Browse files
committed
Merged origin/main into s3-class-docs
2 parents 550a8b6 + 77ae470 commit 7a6169c

Some content is hidden

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

50 files changed

+565
-43
lines changed

.claude/settings.local.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
{
22
"permissions": {
33
"allow": [
4-
"Bash(find:*)"
4+
"Bash(find:*)",
5+
"Bash(R:*)"
56
],
67
"deny": []
7-
}
8+
},
9+
"$schema": "https://json.schemastore.org/claude-code-settings.json"
810
}

CLAUDE.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,15 @@ 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+
- `devtools::load_all()` - Load package for development
2020
- `devtools::document()` - Generate documentation
2121
- `devtools::check()` - Run R CMD check
2222
- `devtools::install()` - Install package locally

NEWS.md

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

3+
* `expect_*()` functions consistently and rigorously check their inputs (#1754).
4+
* `JunitReporter()` no longer fails with `"no applicable method for xml_add_child"` for warnings outside of tests (#1913). Additionally, warnings now save their backtraces.
35
* `JunitReporter()` strips ANSI escapes in more placese (#1852, #2032).
46
* `try_again()` is now publicised. The first argument is now the number of retries, not tries (#2050).
57
* `vignette("custom-expectations)` has been overhauled to make it much clearer how to create high-quality expectations (#2113, #2132, #2072).

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/expect-condition.R

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,10 @@ expect_error <- function(
114114
info = NULL,
115115
label = NULL
116116
) {
117+
check_string(regexp, allow_null = TRUE, allow_na = TRUE)
118+
check_string(class, allow_null = TRUE)
119+
check_bool(inherit)
120+
117121
if (edition_get() >= 3) {
118122
expect_condition_matching_(
119123
"error",
@@ -158,6 +162,11 @@ expect_warning <- function(
158162
info = NULL,
159163
label = NULL
160164
) {
165+
check_string(regexp, allow_null = TRUE, allow_na = TRUE)
166+
check_string(class, allow_null = TRUE)
167+
check_bool(inherit)
168+
check_bool(all)
169+
161170
if (edition_get() >= 3) {
162171
if (!missing(all)) {
163172
warn("The `all` argument is deprecated")
@@ -207,6 +216,11 @@ expect_message <- function(
207216
info = NULL,
208217
label = NULL
209218
) {
219+
check_string(regexp, allow_null = TRUE, allow_na = TRUE)
220+
check_string(class, allow_null = TRUE)
221+
check_bool(inherit)
222+
check_bool(all)
223+
210224
if (edition_get() >= 3) {
211225
expect_condition_matching_(
212226
"message",
@@ -239,6 +253,10 @@ expect_condition <- function(
239253
info = NULL,
240254
label = NULL
241255
) {
256+
check_string(regexp, allow_null = TRUE, allow_na = TRUE)
257+
check_string(class, allow_null = TRUE)
258+
check_bool(inherit)
259+
242260
if (edition_get() >= 3) {
243261
expect_condition_matching_(
244262
"condition",

R/expect-equality.R

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ expect_equal <- function(
6565
) {
6666
act <- quasi_label(enquo(object), label)
6767
exp <- quasi_label(enquo(expected), expected.label)
68+
check_number_decimal(tolerance, min = 0, allow_null = TRUE)
6869

6970
if (edition_get() >= 3) {
7071
expect_waldo_equal_("equal", act, exp, info, ..., tolerance = tolerance)

R/expect-inheritance.R

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ NULL
6161
#' @export
6262
#' @rdname inheritance-expectations
6363
expect_type <- function(object, type) {
64-
stopifnot(is.character(type), length(type) == 1)
64+
check_string(type)
6565

6666
act <- quasi_label(enquo(object))
6767
act_type <- typeof(act$val)
@@ -84,6 +84,8 @@ expect_type <- function(object, type) {
8484
#' from any element of `class`. If `TRUE`, checks that object has a class
8585
#' that's identical to `class`.
8686
expect_s3_class <- function(object, class, exact = FALSE) {
87+
check_bool(exact)
88+
8789
act <- quasi_label(enquo(object))
8890
act$class <- format_class(class(act$val))
8991
exp_lab <- format_class(class)
@@ -113,7 +115,7 @@ expect_s3_class <- function(object, class, exact = FALSE) {
113115
}
114116
}
115117
} else {
116-
abort("`class` must be a NA or a character vector")
118+
stop_input_type(class, c("a character vector", "NA"))
117119
}
118120

119121
pass(act$val)
@@ -203,7 +205,7 @@ isS3 <- function(x) is.object(x) && !isS4(x)
203205
#' @inheritParams expect_type
204206
#' @export
205207
expect_is <- function(object, class, info = NULL, label = NULL) {
206-
stopifnot(is.character(class))
208+
check_character(class)
207209
edition_deprecate(
208210
3,
209211
"expect_is()",

R/expect-known.R

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,10 @@ expect_known_output <- function(
5858
print = FALSE,
5959
width = 80
6060
) {
61+
check_string(file)
62+
check_bool(update)
63+
check_bool(print)
64+
check_number_whole(width, min = 1)
6165
edition_deprecate(
6266
3,
6367
"expect_known_output()",
@@ -131,6 +135,10 @@ expect_output_file <- function(
131135
print = FALSE,
132136
width = 80
133137
) {
138+
check_string(file)
139+
check_bool(update)
140+
check_bool(print)
141+
check_number_whole(width, min = 1)
134142
# Code is a copy of expect_known_output()
135143
edition_deprecate(
136144
3,
@@ -158,6 +166,9 @@ expect_known_value <- function(
158166
label = NULL,
159167
version = 2
160168
) {
169+
check_string(file)
170+
check_bool(update)
171+
check_number_whole(version, min = 1)
161172
edition_deprecate(
162173
3,
163174
"expect_known_value()",

R/expect-length.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
#' expect_length(1:10, 1)
1515
#' }
1616
expect_length <- function(object, n) {
17-
stopifnot(is.numeric(n), length(n) == 1)
17+
check_number_whole(n, min = 0)
1818

1919
act <- quasi_label(enquo(object))
2020
act$n <- length(act$val)

R/expect-match.R

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,11 @@ expect_no_match <- function(
7777
) {
7878
# Capture here to avoid environment-related messiness
7979
act <- quasi_label(enquo(object), label)
80-
stopifnot(is.character(regexp), length(regexp) == 1)
81-
stopifnot(is.character(act$val))
80+
check_character(object)
81+
check_string(regexp)
82+
check_bool(perl)
83+
check_bool(fixed)
84+
check_bool(all)
8285

8386
expect_match_(
8487
act = act,

0 commit comments

Comments
 (0)