Skip to content

Commit

Permalink
Hyperlinks (#1544)
Browse files Browse the repository at this point in the history
Add hyperlinks in test results
  • Loading branch information
romainfrancois authored Feb 18, 2022
1 parent 27a3916 commit 4d256f5
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 5 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ Depends:
Imports:
brio,
callr (>= 3.5.1),
cli (>= 2.2.0),
cli (>= 3.1.1),
crayon (>= 1.3.4),
desc,
digest,
Expand Down
3 changes: 3 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@
* When a snapshot changes the hint also mentions that you can use
`snapshot_review()` (#1500, @DanChaltiel) and the message tells you what
variant is active (#1540).
* JUnit reporter now includes skip messages/reasons (@rfineman, #1507).

* Test results show hyperlinks to failed expectation when supported (#1544).

# testthat 3.1.1

Expand Down
9 changes: 7 additions & 2 deletions R/expectation.R
Original file line number Diff line number Diff line change
Expand Up @@ -260,11 +260,16 @@ expectation_location <- function(x) {
if (is.null(x$srcref)) {
"???"
} else {
filename <- attr(x$srcref, "srcfile")$filename
srcfile <- attr(x$srcref, "srcfile")
filename <- srcfile$filename
if (identical(filename, "")) {
paste0("Line ", x$srcref[1])
} else {
paste0(basename(filename), ":", x$srcref[1], ":", x$srcref[2])
cli::style_hyperlink(
paste0(basename(filename), ":", x$srcref[1], ":", x$srcref[2]),
paste0("file://", file.path(srcfile$wd, filename)),
params = c(line = x$srcref[1], col = x$srcref[2])
)
}
}
}
9 changes: 7 additions & 2 deletions R/snapshot.R
Original file line number Diff line number Diff line change
Expand Up @@ -401,9 +401,14 @@ snapshot_accept_hint <- function(variant, file) {
name <- file.path(variant, file)
}

code_accept <- paste0("snapshot_accept('", name, "')")
code_review <- paste0("snapshot_review('", name, "')")
link <- function(code) {
cli::style_hyperlink(code, paste0("rstudio:run:testthat::", code))
}
paste0(
"* Run `snapshot_accept('", name, "')` to accept the change\n",
"* Run `snapshot_review('", name, "')` to interactively review the change"
"* Run `", link(code_accept), "` to accept the change\n",
"* Run `", link(code_review), "` to interactively review the change"
)
}

Expand Down

0 comments on commit 4d256f5

Please sign in to comment.