Skip to content

Commit 919b7d7

Browse files
committed
Merge commit '3f9e226d12ccf999db9e82f26d5fbe574da53a29'
2 parents fb2f50a + 3f9e226 commit 919b7d7

File tree

301 files changed

+7107
-3251
lines changed

Some content is hidden

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

301 files changed

+7107
-3251
lines changed

.Rbuildignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,8 @@
2020
^\.github/workflows/R\.yaml$
2121
^\.github/workflows/pr-commands\.yaml$
2222
^CRAN-SUBMISSION$
23+
^[\.]?air\.toml$
24+
^\.vscode$
25+
^\.git-blame-ignore-rev$
26+
^CLAUDE\.md$
27+
^\.claude$

.claude/settings.local.json

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

.git-blame-ignore-rev

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# This file lists revisions of large-scale formatting/style changes so that
2+
# they can be excluded from git blame results.
3+
#
4+
# To set this file as the default ignore file for git blame, run:
5+
# $ git config blame.ignoreRevsFile .git-blame-ignore-revs
6+
7+
# https://github.com/r-lib/testthat/pull/2121
8+
13d17788e5d3a54fa83beed25e325703608f8b9f

.vscode/extensions.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"recommendations": [
3+
"Posit.air-vscode"
4+
]
5+
}

.vscode/settings.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"[r]": {
3+
"editor.formatOnSave": true,
4+
"editor.defaultFormatter": "Posit.air-vscode"
5+
}
6+
}

CLAUDE.md

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
# CLAUDE.md
2+
3+
This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
4+
5+
## About This Project
6+
7+
testthat is R's most popular unit testing framework, used by thousands of CRAN packages. It provides functions to make testing R code as fun and addictive as possible, with clear expectations, visual progress indicators, and seamless integration with R package development workflows.
8+
9+
## Key Development Commands
10+
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
16+
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
21+
- `devtools::check()` - Run R CMD check
22+
- `devtools::install()` - Install package locally
23+
24+
### Documentation
25+
26+
- Always run `devtools::document()` after changing any roxygen2 docs.
27+
28+
## Core Architecture
29+
30+
### Main Components
31+
32+
1. **Core Testing Functions** (`R/test-that.R`, `R/test-package.R`):
33+
- `test_that()` - The fundamental testing function
34+
- `test_local()`, `test_package()`, `test_check()` - Different ways to run test suites
35+
36+
2. **Expectations** (`R/expect-*.R`):
37+
- Modular expectation functions (equality, conditions, types, etc.)
38+
- Each expectation type has its own file following the pattern `expect-[type].R`
39+
40+
3. **Reporters** (`R/reporter*.R`):
41+
- Different output formats for test results
42+
- Object-oriented design with base `Reporter` class
43+
- Includes check, debug, progress, summary, JUnit, TAP formats
44+
45+
4. **Snapshot Testing** (`R/snapshot*.R`):
46+
- Value snapshots, file snapshots, output snapshots
47+
- Automatic management and comparison of expected outputs
48+
49+
5. **Parallel Testing** (`R/parallel*.R`):
50+
- Multi-core test execution
51+
- Configuration via `Config/testthat/parallel: true` in DESCRIPTION
52+
53+
6. **Mocking** (`R/mock*.R`, `R/mock2*.R`):
54+
- Function mocking capabilities
55+
- Both legacy (`mock.R`) and modern (`mock2*.R`) implementations
56+
57+
### Key Design Patterns
58+
59+
- **Editions**: testthat has different "editions" with varying behavior, controlled by `Config/testthat/edition`
60+
- **Reporters**: Extensible reporting system using R6 classes
61+
- **Lazy Evaluation**: Expectations use substitute() and lazy evaluation for better error messages
62+
- **C++ Integration**: Core functionality implemented in C++ for performance
63+
64+
### File Organization
65+
66+
- `R/` - All R source code, organized by functionality
67+
- `src/` - C++ source code and Makevars
68+
- `inst/include/testthat/` - C++ headers for other packages to use
69+
- `tests/testthat/` - Package's own comprehensive test suite
70+
- `vignettes/` - Documentation on testing concepts and workflows
71+
72+
### Important Configuration
73+
74+
The package uses several DESCRIPTION fields for configuration:
75+
- `Config/testthat/edition: 3` - Sets testthat edition
76+
- `Config/testthat/parallel: true` - Enables parallel testing
77+
- `Config/testthat/start-first` - Tests to run first in parallel mode
78+
79+
### C++ Testing Infrastructure
80+
81+
testthat provides C++ testing capabilities via Catch framework:
82+
- Headers in `inst/include/testthat/`
83+
- Test runner infrastructure in `src/test-runner.cpp`
84+
- Integration with R's testing system
85+
86+
### Snapshot Testing Workflow
87+
88+
- Snapshots stored in `tests/testthat/_snaps/`
89+
- Different snapshot types: values, files, output
90+
- Version-specific snapshots for different R versions
91+
- Use `testthat::snapshot_accept()` to update snapshots
92+
93+
This codebase prioritizes backward compatibility, comprehensive testing, and clear, descriptive error messages to help R developers write better tests.

DESCRIPTION

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -15,31 +15,31 @@ 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.6.0)
18+
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-
digest (>= 0.6.33),
25-
evaluate (>= 1.0.1),
26-
jsonlite (>= 1.8.7),
27-
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),
2827
magrittr (>= 2.0.3),
2928
methods,
30-
pkgload (>= 1.3.2.1),
29+
pkgload (>= 1.4.0),
3130
praise (>= 1.0.0),
32-
processx (>= 3.8.2),
33-
ps (>= 1.7.5),
34-
R6 (>= 2.5.1),
35-
rlang (>= 1.1.1),
31+
processx (>= 3.8.6),
32+
ps (>= 1.9.1),
33+
R6 (>= 2.6.1),
34+
rlang (>= 1.1.6),
3635
utils,
37-
waldo (>= 0.6.0),
36+
waldo (>= 0.6.2),
3837
withr (>= 3.0.2)
3938
Suggests:
4039
covr,
4140
curl (>= 0.9.5),
4241
diffviewer (>= 0.1.0),
42+
digest (>= 0.6.33),
4343
knitr,
4444
rmarkdown,
4545
rstudioapi,

NAMESPACE

Lines changed: 8 additions & 4 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)
@@ -114,11 +115,13 @@ export(expect_no_warning)
114115
export(expect_null)
115116
export(expect_output)
116117
export(expect_output_file)
118+
export(expect_r6_class)
117119
export(expect_reference)
118120
export(expect_s3_class)
119121
export(expect_s4_class)
120122
export(expect_s7_class)
121123
export(expect_setequal)
124+
export(expect_shape)
122125
export(expect_silent)
123126
export(expect_snapshot)
124127
export(expect_snapshot_error)
@@ -144,29 +147,27 @@ export(is.expectation)
144147
export(is_a)
145148
export(is_checking)
146149
export(is_equivalent_to)
147-
export(is_false)
148150
export(is_identical_to)
149151
export(is_informative_error)
150152
export(is_less_than)
151153
export(is_more_than)
152-
export(is_null)
153154
export(is_parallel)
154155
export(is_snapshot)
155156
export(is_testing)
156-
export(is_true)
157157
export(it)
158158
export(local_edition)
159159
export(local_mock)
160160
export(local_mocked_bindings)
161+
export(local_on_cran)
161162
export(local_reproducible_output)
162163
export(local_snapshotter)
163164
export(local_test_context)
164165
export(local_test_directory)
165166
export(make_expectation)
166-
export(matches)
167167
export(mock_output_sequence)
168168
export(new_expectation)
169169
export(not)
170+
export(pass)
170171
export(prints_text)
171172
export(quasi_label)
172173
export(run_cpp_tests)
@@ -189,7 +190,9 @@ export(skip_on_covr)
189190
export(skip_on_cran)
190191
export(skip_on_os)
191192
export(skip_on_travis)
193+
export(skip_unless_r)
192194
export(snapshot_accept)
195+
export(snapshot_reject)
193196
export(snapshot_review)
194197
export(source_dir)
195198
export(source_file)
@@ -228,5 +231,6 @@ import(rlang)
228231
importFrom(R6,R6Class)
229232
importFrom(brio,readLines)
230233
importFrom(brio,writeLines)
234+
importFrom(lifecycle,deprecated)
231235
importFrom(magrittr,"%>%")
232236
useDynLib(testthat, .registration = TRUE)

NEWS.md

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

33
* `local_mock()` and `with_mock()` have been deprecated because they are no longer permitted in R 4.5.
4+
* `snapshot_review()` now passes `...` on to `shiny::runApp()` (#1928).
5+
* `expect_named()` now gives more informative errors (#2091).
6+
* `expect_*()` functions consistently and rigorously check their inputs (#1754).
7+
* `test_that()` no longer warns about the absence of `{}` since it no longer seems to be necessary.
8+
* `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).
9+
* 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).
10+
* New `snapshot_reject()` rejects all modified snapshots by deleting the `.new` variants (#1923).
11+
* 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).
12+
* Power `expect_mapequal()` with `waldo::compare(list_as_map = TRUE)` (#1521).
13+
* 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.)
14+
* `expect_snapshot()` no longer skips on CRAN, as that skips the rest of the test. Instead it just returns, neither succeeding nor failing (#1585).
15+
* Interrupting a test now prints the test name. This makes it easier to tell where a very slow test might be hanging (#1464)
16+
* Parallel testthat now does not ignore test files with syntax errors (#1360).
17+
* `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.
18+
* `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.
19+
* `describe()` now correctly scopes `skip()` (#2007).
20+
* `ParallelProgressReporter` now respect `max_failures` (#1162).
21+
* 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.
22+
* New `expect_r6_class()` (#2030).
23+
* `expect_*()` functions consistently and rigorously check their inputs (#1754).
24+
* `JunitReporter()` no longer fails with `"no applicable method for xml_add_child"` for warnings outside of tests (#1913). Additionally, warnings now save their backtraces.
25+
* `JunitReporter()` strips ANSI escapes in more placese (#1852, #2032).
26+
* `try_again()` is now publicised. The first argument is now the number of retries, not tries (#2050).
27+
* `vignette("custom-expectations)` has been overhauled to make it much clearer how to create high-quality expectations (#2113, #2132, #2072).
28+
* `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).
29+
* `expect_snapshot_value()` can now handle expressions that generate `-` (#1678) or zero length atomic vectors (#2042).
30+
* `expect_matches()` failures should be a little easier to read (#2135, #2181).
31+
* New `local_on_cran(TRUE)` allows you to simulate how your tests will run on CRAN (#2112).
32+
* `expect_no_*()` now executes the entire code block, rather than stopping at the first message or warning (#1991).
33+
* `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 (#)
34+
* New `pass()` function to use in place of `succeed()` (#2113).
35+
* `expectation()` is now a combination of `new_expectation()` and `exp_signal()` (#2125).
36+
* `is_null()`/`matches()` deprecated in 2.0.0 (2017-12-19) and `is_true()`/`is_false()` deprecated in 2.1.0 (2019-04-23) have been removed (#2109).
37+
* `local_edition()` now gives a useful error for bad values (#1547).
38+
* testthat now requires R 4.1.
39+
* `expect_s4_class()` now supports unquoting (@stibu81, #2064).
40+
* `it()` now finds the correct evaluation environment in more cases (@averissimo, #2085).
441
* Fixed an issue preventing compilation from succeeding due to deprecation / removal of `std::uncaught_exception()` (@kevinushey, #2047).
42+
* New `skip_unless_r()` to skip running tests on unsuitable versions of R, e.g. `skip_unless_r(">= 4.1.0")` to skip tests that require, say, `...names` (@MichaelChirico, #2022)
43+
* `skip_on_os()` gains an option `"emscripten"` of the `os` argument to skip tests on Emscripten (@eitsupi, #2103).
44+
* New expectation, `expect_shape()`, for testing the shape (i.e., the `length()`, `nrow()`, `ncol()`, or `dim()`), all in one place (#1423, @michaelchirico).
545

646
# testthat 3.2.3
747

0 commit comments

Comments
 (0)