Skip to content

Commit 4d256f5

Browse files
Hyperlinks (#1544)
Add hyperlinks in test results
1 parent 27a3916 commit 4d256f5

File tree

4 files changed

+18
-5
lines changed

4 files changed

+18
-5
lines changed

DESCRIPTION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ Depends:
2323
Imports:
2424
brio,
2525
callr (>= 3.5.1),
26-
cli (>= 2.2.0),
26+
cli (>= 3.1.1),
2727
crayon (>= 1.3.4),
2828
desc,
2929
digest,

NEWS.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,9 @@
5252
* When a snapshot changes the hint also mentions that you can use
5353
`snapshot_review()` (#1500, @DanChaltiel) and the message tells you what
5454
variant is active (#1540).
55+
* JUnit reporter now includes skip messages/reasons (@rfineman, #1507).
56+
57+
* Test results show hyperlinks to failed expectation when supported (#1544).
5558

5659
# testthat 3.1.1
5760

R/expectation.R

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -260,11 +260,16 @@ expectation_location <- function(x) {
260260
if (is.null(x$srcref)) {
261261
"???"
262262
} else {
263-
filename <- attr(x$srcref, "srcfile")$filename
263+
srcfile <- attr(x$srcref, "srcfile")
264+
filename <- srcfile$filename
264265
if (identical(filename, "")) {
265266
paste0("Line ", x$srcref[1])
266267
} else {
267-
paste0(basename(filename), ":", x$srcref[1], ":", x$srcref[2])
268+
cli::style_hyperlink(
269+
paste0(basename(filename), ":", x$srcref[1], ":", x$srcref[2]),
270+
paste0("file://", file.path(srcfile$wd, filename)),
271+
params = c(line = x$srcref[1], col = x$srcref[2])
272+
)
268273
}
269274
}
270275
}

R/snapshot.R

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -401,9 +401,14 @@ snapshot_accept_hint <- function(variant, file) {
401401
name <- file.path(variant, file)
402402
}
403403

404+
code_accept <- paste0("snapshot_accept('", name, "')")
405+
code_review <- paste0("snapshot_review('", name, "')")
406+
link <- function(code) {
407+
cli::style_hyperlink(code, paste0("rstudio:run:testthat::", code))
408+
}
404409
paste0(
405-
"* Run `snapshot_accept('", name, "')` to accept the change\n",
406-
"* Run `snapshot_review('", name, "')` to interactively review the change"
410+
"* Run `", link(code_accept), "` to accept the change\n",
411+
"* Run `", link(code_review), "` to interactively review the change"
407412
)
408413
}
409414

0 commit comments

Comments
 (0)