Skip to content

Commit f24641d

Browse files
committed
Merged origin/main into fix/parallel-teardown
2 parents be38592 + 79a9ed8 commit f24641d

15 files changed

+99
-113
lines changed

.github/workflows/claude-code-review.yml

Lines changed: 5 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -42,31 +42,13 @@ jobs:
4242

4343
# Direct prompt for automated review (no @claude mention needed)
4444
direct_prompt: |
45-
Please review this pull request and provide feedback on:
46-
- Code quality and best practices
47-
- Potential bugs or issues
48-
- Performance considerations
49-
- Security concerns
50-
- Test coverage
51-
52-
Be constructive and helpful in your feedback.
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.
5349
5450
# Optional: Use sticky comments to make Claude reuse the same comment on subsequent pushes to the same PR
55-
# use_sticky_comment: true
56-
57-
# Optional: Customize review based on file types
58-
# direct_prompt: |
59-
# Review this PR focusing on:
60-
# - For TypeScript files: Type safety and proper interface usage
61-
# - For API endpoints: Security, input validation, and error handling
62-
# - For React components: Performance, accessibility, and best practices
63-
# - For tests: Coverage, edge cases, and test quality
64-
65-
# Optional: Different prompts for different authors
66-
# direct_prompt: |
67-
# ${{ github.event.pull_request.author_association == 'FIRST_TIME_CONTRIBUTOR' &&
68-
# 'Welcome! Please review this PR from a first-time contributor. Be encouraging and provide detailed explanations for any suggestions.' ||
69-
# 'Please provide a thorough code review focusing on our coding standards and best practices.' }}
51+
use_sticky_comment: true
7052

7153
# Optional: Add specific tools for running tests or linting
7254
# allowed_tools: "Bash(npm run test),Bash(npm run lint),Bash(npm run typecheck)"
@@ -75,4 +57,3 @@ jobs:
7557
# if: |
7658
# !contains(github.event.pull_request.title, '[skip-review]') &&
7759
# !contains(github.event.pull_request.title, '[WIP]')
78-

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/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: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ test_files_parallel <- function(
6565
)
6666

6767
withr::with_dir(test_dir, {
68-
reporters <- test_files_reporter_parallel(reporter)
68+
reporters <- test_files_reporter(reporter, "parallel")
6969
with_reporter(reporters$multi, {
7070
parallel_updates <- reporter$capabilities$parallel_updates
7171
if (parallel_updates) {
@@ -83,23 +83,6 @@ test_files_parallel <- function(
8383
})
8484
}
8585

86-
test_files_reporter_parallel <- function(reporter, .env = parent.frame()) {
87-
lister <- ListReporter$new()
88-
snapshotter <- MainprocessSnapshotReporter$new("_snaps")
89-
reporters <- list(
90-
find_reporter(reporter),
91-
lister, # track data
92-
snapshotter
93-
)
94-
withr::local_options(
95-
"testthat.snapshotter" = snapshotter,
96-
.local_envir = .env
97-
)
98-
list(
99-
multi = MultiReporter$new(reporters = compact(reporters)),
100-
list = lister
101-
)
102-
}
10386

10487
default_num_cpus <- function() {
10588
# Use common option, if set

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"`,

R/snapshot-file-snaps.R

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,6 @@ FileSnaps <- R6::R6Class(
3939
},
4040

4141
append = function(test, variant, data) {
42-
if (!has_name(self$snaps, variant)) {
43-
# Needed for R < 3.6
44-
self$snaps[[variant]] <- list()
45-
}
46-
4742
self$snaps[[variant]][[test]] <- c(self$snaps[[variant]][[test]], data)
4843
length(self$snaps[[variant]][[test]])
4944
},

R/snapshot-reporter.R

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ SnapshotReporter <- R6::R6Class(
140140
return()
141141
}
142142

143-
# If expectation errors or skips, need to reset remaining snapshots
143+
# If expectation errors or skips, need to copy snapshots from old to cur
144144
if (expectation_error(result) || expectation_skip(result)) {
145145
self$cur_snaps$reset(self$test, self$old_snaps)
146146
}
@@ -204,23 +204,19 @@ get_snapshotter <- function() {
204204
#' @export
205205
#' @keywords internal
206206
local_snapshotter <- function(
207-
snap_dir = NULL,
207+
reporter = SnapshotReporter,
208+
snap_dir = "_snaps",
208209
cleanup = FALSE,
209210
fail_on_new = NULL,
210-
.env = parent.frame()
211+
frame = caller_env()
211212
) {
212-
snap_dir <- snap_dir %||% withr::local_tempdir(.local_envir = .env)
213-
reporter <- SnapshotReporter$new(
214-
snap_dir = snap_dir,
215-
fail_on_new = fail_on_new
216-
)
217-
if (!identical(cleanup, FALSE)) {
218-
cli::cli_warn("{.arg cleanup} is deprecated.")
219-
}
213+
reporter <- reporter$new(snap_dir = snap_dir, fail_on_new = fail_on_new)
214+
withr::local_options("testthat.snapshotter" = reporter, .local_envir = frame)
220215

221-
withr::local_options(
222-
"testthat.snapshotter" = reporter,
223-
.local_envir = .env
224-
)
225216
reporter
226217
}
218+
219+
local_test_snapshotter <- function(snap_dir = NULL, frame = caller_env()) {
220+
snap_dir <- snap_dir %||% withr::local_tempdir(.local_envir = frame)
221+
local_snapshotter(snap_dir = snap_dir, fail_on_new = FALSE, frame = frame)
222+
}

R/test-files.R

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ test_files_serial <- function(
221221
local_testing_env(env)
222222

223223
test_files_setup_state(test_dir, test_package, load_helpers, env)
224-
reporters <- test_files_reporter(reporter)
224+
reporters <- test_files_reporter(reporter, "serial")
225225

226226
with_reporter(
227227
reporters$multi,
@@ -315,15 +315,30 @@ test_files_setup_state <- function(
315315
withr::defer(source_test_teardown(".", env), frame) # old school
316316
}
317317

318-
test_files_reporter <- function(reporter, .env = parent.frame()) {
318+
test_files_reporter <- function(
319+
reporter,
320+
mode = c("serial", "parallel"),
321+
frame = caller_env()
322+
) {
323+
mode <- arg_match(mode)
324+
325+
# User selected reporter
326+
user <- find_reporter(reporter)
327+
328+
# Reporter that collect test results
319329
lister <- ListReporter$new()
320-
reporters <- list(
321-
find_reporter(reporter),
322-
lister, # track data
323-
local_snapshotter("_snaps", .env = .env)
324-
)
330+
331+
# Snapshot reporter
332+
if (mode == "parallel") {
333+
snap_base <- MainprocessSnapshotReporter
334+
} else {
335+
snap_base <- SnapshotReporter
336+
}
337+
snap <- local_snapshotter(snap_base, fail_on_new = on_ci(), frame = frame)
338+
339+
reporters <- compact(list(user, lister, snap))
325340
list(
326-
multi = MultiReporter$new(reporters = compact(reporters)),
341+
multi = MultiReporter$new(reporters = reporters),
327342
list = lister
328343
)
329344
}

R/test-package.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ test_local <- function(
6969
package <- pkgload::pkg_name(path)
7070
test_path <- file.path(pkgload::pkg_path(path), "tests", "testthat")
7171

72-
withr::local_envvar(NOT_CRAN = "true")
72+
local_assume_not_on_cran()
7373
test_dir(
7474
test_path,
7575
package = package,

man/local_snapshotter.Rd

Lines changed: 3 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)