Skip to content

Commit 20a533f

Browse files
committed
Claude feedback
1 parent 4e5b189 commit 20a533f

File tree

3 files changed

+11
-6
lines changed

3 files changed

+11
-6
lines changed

R/extract.R

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#' Extract a reprex from an failed expectation
1+
#' Extract a reprex from a failed expectation
22
#'
33
#' `extract_test()` creates a minimal reprex for a failed expectation.
44
#' It extracts all non-test code before the failed expectation as well as
@@ -23,13 +23,13 @@ extract_test <- function(location, path = stdout()) {
2323

2424
test_path <- test_path(pieces[[1]])
2525
line <- as.integer(pieces[2])
26-
source <- paste0("# Extracted from tests/testthat/", path, ":", line)
26+
source <- paste0("# Extracted from ", test_path, ":", line)
2727

2828
lines <- tryCatch(
2929
extract_test_lines(test_path, line),
3030
error = function(cnd) {
3131
lines <- strsplit(conditionMessage(cnd), "\n")[[1]]
32-
lines <- c("Failed to extract test", lines)
32+
lines <- c("", "Failed to extract test: ", lines)
3333
paste0("# ", lines)
3434
}
3535
)
@@ -68,7 +68,10 @@ extract_test_lines <- function(path, line, error_call = caller_env()) {
6868
prequel <- NULL
6969
}
7070

71-
# Now we extract the contents of the test
71+
# Now we extract the contents of the last test
72+
if (!any(is_subtest)) {
73+
cli::cli_abort("Failed to find test at line {line}.", call = error_call)
74+
}
7275
test_idx <- rev(which(is_subtest))[[1]]
7376
call <- exprs[[test_idx]]
7477
check_test_call(call, error_call = error_call)
@@ -95,7 +98,7 @@ check_test_call <- function(expr, error_call = caller_env()) {
9598
}
9699
if (!is_call(expr[[3]], "{")) {
97100
cli::cli_abort(
98-
"test call has use {",
101+
"test call doesn't use `{`",
99102
internal = TRUE,
100103
call = error_call
101104
)

man/extract_test.Rd

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/testthat/test-expect-output.R

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
f <- function() NULL
22
g <- function() cat("!")
33

4+
writeLines("Hi!", "../someoutput.txt")
5+
46
test_that("expect = NA checks for no output", {
57
expect_success(expect_output(f(), NA))
68
expect_snapshot_failure(expect_output(g(), NA))

0 commit comments

Comments
 (0)