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 )
0 commit comments