Skip to content

Commit 23d8276

Browse files
committed
Add example
1 parent d78f8aa commit 23d8276

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed

β€ŽR/extract.Rβ€Ž

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,31 @@
11
#' Extract a reprex from a failed expectation
22
#'
3+
#' @description
34
#' `extract_test()` creates a minimal reprex for a failed expectation.
45
#' It extracts all non-test code before the failed expectation as well as
56
#' all code inside the test up to and including the failed expectation.
67
#'
8+
#' This is particularly useful when you're debugging test failures in
9+
#' someone else's package.
10+
#'
711
#' @param location A string giving the location in the form
812
#' `FILE:LINE[:COLUMN]`.
913
#' @param path Path to write the reprex to. Defaults to `stdout()`.
1014
#' @return This function is called for its side effect of rendering a
1115
#' reprex to `path`. This function will never error: if extraction
1216
#' fails, the error message will be written to `path`.
1317
#' @export
18+
#' @examples
19+
#' # If you see a test failure like this:
20+
#' # ── Failure (test-extract.R:46:3): errors if can't find test ───────────────
21+
#' # Expected FALSE to be TRUE.
22+
#' # Differences:
23+
#' # `actual`: FALSE
24+
#' # `expected`: TRUE
25+
#'
26+
#' # You can run this:
27+
#' \dontrun{extract_test("test-extract.R:46:3")}
28+
#' # to see just the code needed to reproduce the failure
1429
extract_test <- function(location, path = stdout()) {
1530
check_string(location)
1631

β€Žman/extract_test.Rdβ€Ž

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

0 commit comments

Comments
Β (0)