Skip to content

Commit 97066ea

Browse files
committed
Merged origin/main into oo-mocking
2 parents 39a9a94 + b626c06 commit 97066ea

Some content is hidden

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

61 files changed

+575
-281
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
}
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
name: Claude Code Review
2+
3+
on:
4+
pull_request:
5+
types: [opened, synchronize]
6+
# Optional: Only run on specific file changes
7+
# paths:
8+
# - "src/**/*.ts"
9+
# - "src/**/*.tsx"
10+
# - "src/**/*.js"
11+
# - "src/**/*.jsx"
12+
13+
jobs:
14+
claude-review:
15+
# Optional: Filter by PR author
16+
# if: |
17+
# github.event.pull_request.user.login == 'external-contributor' ||
18+
# github.event.pull_request.user.login == 'new-developer' ||
19+
# github.event.pull_request.author_association == 'FIRST_TIME_CONTRIBUTOR'
20+
21+
runs-on: ubuntu-latest
22+
permissions:
23+
contents: read
24+
pull-requests: read
25+
issues: read
26+
id-token: write
27+
28+
steps:
29+
- name: Checkout repository
30+
uses: actions/checkout@v4
31+
with:
32+
fetch-depth: 1
33+
34+
- name: Run Claude Code Review
35+
id: claude-review
36+
uses: anthropics/claude-code-action@beta
37+
with:
38+
anthropic_api_key: ${{ secrets.ANTHROPIC_API_KEY }}
39+
40+
# Optional: Specify model (defaults to Claude Sonnet 4, uncomment for Claude Opus 4.1)
41+
# model: "claude-opus-4-1-20250805"
42+
43+
# Direct prompt for automated review (no @claude mention needed)
44+
direct_prompt: |
45+
Please review this pull request and MINIMAL provide feedback on
46+
potential bugs or issues. Never praise or flatter. Be concise.
47+
Use simple, clear language. If you don't have anything significant
48+
to add, just reply LGTM.
49+
50+
# Optional: Use sticky comments to make Claude reuse the same comment on subsequent pushes to the same PR
51+
use_sticky_comment: true
52+
53+
# Optional: Add specific tools for running tests or linting
54+
# allowed_tools: "Bash(npm run test),Bash(npm run lint),Bash(npm run typecheck)"
55+
56+
# Optional: Skip review for certain conditions
57+
# if: |
58+
# !contains(github.event.pull_request.title, '[skip-review]') &&
59+
# !contains(github.event.pull_request.title, '[WIP]')

.github/workflows/claude.yml

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
name: Claude Code
2+
3+
on:
4+
issue_comment:
5+
types: [created]
6+
pull_request_review_comment:
7+
types: [created]
8+
issues:
9+
types: [opened, assigned]
10+
pull_request_review:
11+
types: [submitted]
12+
13+
jobs:
14+
claude:
15+
if: |
16+
(github.event_name == 'issue_comment' && contains(github.event.comment.body, '@claude')) ||
17+
(github.event_name == 'pull_request_review_comment' && contains(github.event.comment.body, '@claude')) ||
18+
(github.event_name == 'pull_request_review' && contains(github.event.review.body, '@claude')) ||
19+
(github.event_name == 'issues' && (contains(github.event.issue.body, '@claude') || contains(github.event.issue.title, '@claude')))
20+
runs-on: ubuntu-latest
21+
permissions:
22+
contents: read
23+
pull-requests: read
24+
issues: read
25+
id-token: write
26+
actions: read # Required for Claude to read CI results on PRs
27+
steps:
28+
- name: Checkout repository
29+
uses: actions/checkout@v4
30+
with:
31+
fetch-depth: 1
32+
33+
- name: Install air
34+
uses: posit-dev/setup-air@v1
35+
36+
- uses: r-lib/actions/setup-r@v2
37+
with:
38+
use-public-rspm: true
39+
40+
- uses: r-lib/actions/setup-r-dependencies@v2
41+
with:
42+
extra-packages: any::rcmdcheck,roxygen2
43+
needs: check
44+
45+
- name: Run Claude Code
46+
id: claude
47+
uses: anthropics/claude-code-action@beta
48+
with:
49+
anthropic_api_key: ${{ secrets.ANTHROPIC_API_KEY }}
50+
51+
# This is an optional setting that allows Claude to read CI results on PRs
52+
additional_permissions: |
53+
actions: read
54+
55+
# Optional: Specify model (defaults to Claude Sonnet 4, uncomment for Claude Opus 4.1)
56+
# model: "claude-opus-4-1-20250805"
57+
58+
# Optional: Customize the trigger phrase (default: @claude)
59+
# trigger_phrase: "/claude"
60+
61+
# Optional: Trigger when specific user is assigned to an issue
62+
# assignee_trigger: "claude-bot"
63+
64+
# Optional: Allow Claude to run specific commands
65+
allowed_tools: "Bash(R:*);Bash(air format:*)"
66+
67+
# Optional: Add custom instructions for Claude to customize its behavior for your project
68+
# custom_instructions: |
69+
# Follow our coding standards
70+
# Ensure all new code has tests
71+
# Use TypeScript for new files
72+
73+
# Optional: Custom environment variables for Claude
74+
# claude_env: |
75+
# NODE_ENV: test

NEWS.md

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

33
* New `local_mocked_s3_method()`, `local_mocked_s4_method()`, and `local_mocked_r6_class()` allow you to mock S3 and S4 methods and R6 classes (#1892, #1916)
4+
* `expect_snapshot_file(name=)` must have a unique file path. If a snapshot file attempts to be saved with a duplicate `name`, an error will be thrown. (#1592)
5+
* `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.
6+
* `snapshot_accept(test)` now works when the test file name contains `.` (#1669).
47
* `local_mock()` and `with_mock()` have been deprecated because they are no longer permitted in R 4.5.
58
* `snapshot_review()` now passes `...` on to `shiny::runApp()` (#1928).
69
* `expect_named()` now gives more informative errors (#2091).
@@ -42,7 +45,7 @@
4245
* Fixed an issue preventing compilation from succeeding due to deprecation / removal of `std::uncaught_exception()` (@kevinushey, #2047).
4346
* 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)
4447
* `skip_on_os()` gains an option `"emscripten"` of the `os` argument to skip tests on Emscripten (@eitsupi, #2103).
45-
* New expectation, `expect_shape()`, for testing the shape (i.e., the `length()`, `nrow()`, `ncol()`, or `dim()`), all in one place (#1423, @michaelchirico).
48+
* New expectation, `expect_shape()`, for testing the shape (i.e., the `nrow()`, `ncol()`, or `dim()`), all in one place (#1423, @michaelchirico).
4649

4750
# testthat 3.2.3
4851

R/auto-test.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ auto_test_package <- function(
8383
test_path <- normalizePath(file.path(path, "tests", "testthat"))
8484

8585
# Start by loading all code and running all tests
86-
withr::local_envvar("NOT_CRAN" = "true")
86+
local_assume_not_on_cran()
8787
pkgload::load_all(path)
8888
test_dir(
8989
test_path,

R/expect-length.R

Lines changed: 0 additions & 27 deletions
This file was deleted.

R/expect-shape.R

Lines changed: 31 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,44 @@
1-
#' Do you expect an object with this shape?
1+
#' Do you expect an object with this length or shape?
22
#'
3-
#' This is a generalization of [expect_length()] to test the "shape" of
4-
#' more general objects like data.frames, matrices, and arrays.
3+
#' `expect_length()` inspects the [length()] of an object; `expect_shape()`
4+
#' inspects the "shape" (i.e. [nrow()], [ncol()], or [dim()]) of
5+
#' higher-dimensional objects like data.frames, matrices, and arrays.
56
#'
6-
#' @seealso [expect_length()] to specifically make assertions about the
7-
#' [length()] of a vector.
7+
#' @seealso [expect_vector()] to make assertions about the "size" of a vector.
88
#' @inheritParams expect_that
9-
#' @param ... Ignored.
10-
#' @param nrow,ncol Expected [nrow()]/[ncol()] of `object`.
11-
#' @param dim Expected [dim()] of `object`.
9+
#' @param n Expected length.
1210
#' @family expectations
1311
#' @export
1412
#' @examples
13+
#' expect_length(1, 1)
14+
#' expect_length(1:10, 10)
15+
#' show_failure(expect_length(1:10, 1))
16+
#'
1517
#' x <- matrix(1:9, nrow = 3)
1618
#' expect_shape(x, nrow = 3)
19+
#' show_failure(expect_shape(x, nrow = 4))
1720
#' expect_shape(x, ncol = 3)
21+
#' show_failure(expect_shape(x, ncol = 4))
1822
#' expect_shape(x, dim = c(3, 3))
23+
#' show_failure(expect_shape(x, dim = c(3, 4, 5)))
24+
expect_length <- function(object, n) {
25+
check_number_whole(n, min = 0)
26+
27+
act <- quasi_label(enquo(object))
28+
act$n <- length(act$val)
29+
30+
if (act$n != n) {
31+
msg <- sprintf("%s has length %i, not length %i.", act$lab, act$n, n)
32+
return(fail(msg))
33+
}
34+
pass(act$val)
35+
}
36+
37+
#' @param nrow,ncol Expected [nrow()]/[ncol()] of `object`.
38+
#' @param dim Expected [dim()] of `object`.
39+
#' @rdname expect_length
40+
#' @param ... Not used; used to force naming of other arguments.
41+
#' @export
1942
expect_shape = function(object, ..., nrow, ncol, dim) {
2043
check_dots_empty()
2144
check_exclusive(nrow, ncol, dim)

R/local.R

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -190,8 +190,7 @@ local_test_directory <- function(path, package = NULL, .env = parent.frame()) {
190190
}
191191

192192
local_interactive_reporter <- function(.env = parent.frame()) {
193-
# Definitely not on CRAN
194-
withr::local_envvar(NOT_CRAN = "true", .local_envir = .env)
193+
local_assume_not_on_cran(.env)
195194
withr::local_options(testthat_interactive = TRUE, .local_envir = .env)
196195

197196
# Use edition from working directory

R/parallel.R

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,8 @@ test_files_parallel <- function(
4141
stop_on_failure = FALSE,
4242
stop_on_warning = FALSE,
4343
wrap = TRUE, # unused, to match test_files signature
44-
load_package = c("none", "installed", "source")
44+
load_package = c("none", "installed", "source"),
45+
shuffle = FALSE
4546
) {
4647
# TODO: support timeouts. 20-30s for each file by default?
4748

@@ -59,7 +60,8 @@ test_files_parallel <- function(
5960
test_dir = test_dir,
6061
load_helpers = load_helpers,
6162
num_workers = num_workers,
62-
load_package = load_package
63+
load_package = load_package,
64+
shuffle = shuffle
6365
)
6466

6567
withr::with_dir(test_dir, {
@@ -83,7 +85,7 @@ test_files_parallel <- function(
8385

8486
test_files_reporter_parallel <- function(reporter, .env = parent.frame()) {
8587
lister <- ListReporter$new()
86-
snapshotter <- MainprocessSnapshotReporter$new("_snaps", fail_on_new = FALSE)
88+
snapshotter <- MainprocessSnapshotReporter$new("_snaps")
8789
reporters <- list(
8890
find_reporter(reporter),
8991
lister, # track data
@@ -227,7 +229,8 @@ queue_setup <- function(
227229
test_dir,
228230
num_workers,
229231
load_helpers,
230-
load_package
232+
load_package,
233+
shuffle = FALSE
231234
) {
232235
# TODO: observe `load_package`, but the "none" default is not
233236
# OK for the subprocess, because it'll not have the tested package
@@ -266,9 +269,11 @@ queue_setup <- function(
266269
})
267270
queue <- task_q$new(concurrency = num_workers, load_hook = load_hook)
268271

269-
fun <- transport_fun(function(path) asNamespace("testthat")$queue_task(path))
272+
fun <- transport_fun(function(path, shuffle) {
273+
asNamespace("testthat")$queue_task(path, shuffle)
274+
})
270275
for (path in test_paths) {
271-
queue$push(fun, list(path))
276+
queue$push(fun, list(path, shuffle))
272277
}
273278

274279
queue
@@ -299,19 +304,19 @@ queue_process_setup <- function(
299304
the$testing_env <- env
300305
}
301306

302-
queue_task <- function(path) {
307+
queue_task <- function(path, shuffle = FALSE) {
303308
withr::local_envvar("TESTTHAT_IS_PARALLEL" = "true")
304-
snapshotter <- SubprocessSnapshotReporter$new(
305-
snap_dir = "_snaps",
306-
fail_on_new = FALSE
307-
)
309+
snapshotter <- SubprocessSnapshotReporter$new(snap_dir = "_snaps")
308310
withr::local_options(testthat.snapshotter = snapshotter)
309311
reporters <- list(
310312
SubprocessReporter$new(),
311313
snapshotter
312314
)
313315
multi <- MultiReporter$new(reporters = reporters)
314-
with_reporter(multi, test_one_file(path, env = the$testing_env))
316+
with_reporter(
317+
multi,
318+
test_one_file(path, env = the$testing_env, shuffle = shuffle)
319+
)
315320
NULL
316321
}
317322

R/skip.R

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,14 @@ local_on_cran <- function(on_cran, frame = caller_env()) {
190190
withr::local_envvar(NOT_CRAN = tolower(!on_cran), .local_envir = frame)
191191
}
192192

193+
# Assert that we're not on CRAN, but don't override the user's setting
194+
local_assume_not_on_cran <- function(frame = caller_env()) {
195+
if (Sys.getenv("NOT_CRAN") != "") {
196+
return()
197+
}
198+
withr::local_envvar("NOT_CRAN" = "true", .local_envir = frame)
199+
}
200+
193201
#' @export
194202
#' @param os Character vector of one or more operating systems to skip on.
195203
#' Supported values are `"windows"`, `"mac"`, `"linux"`, `"solaris"`,

0 commit comments

Comments
 (0)