diff --git a/NAMESPACE b/NAMESPACE index 754d006..876d889 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -7,14 +7,11 @@ S3method(parse_all,connection) S3method(parse_all,default) S3method(print,evaluate_evaluation) S3method(replay,character) +S3method(replay,condition) S3method(replay,default) -S3method(replay,error) S3method(replay,list) -S3method(replay,message) S3method(replay,recordedplot) S3method(replay,source) -S3method(replay,value) -S3method(replay,warning) export(create_traceback) export(evaluate) export(flush_console) diff --git a/R/replay.R b/R/replay.R index 04de410..e1a0d1f 100644 --- a/R/replay.R +++ b/R/replay.R @@ -22,7 +22,9 @@ #' message("Goodbye") #' } #' replay(evaluate("f2()")) -replay <- function(x) UseMethod("replay", x) +replay <- function(x) { + UseMethod("replay", x) +} #' @export replay.list <- function(x) { @@ -45,25 +47,10 @@ replay.source <- function(x) { } #' @export -replay.warning <- function(x) { - cat_line(format_condition(x)) -} - -#' @export -replay.message <- function(x) { - cat_line(format_condition(x)) -} - -#' @export -replay.error <- function(x) { +replay.condition <- function(x) { cat_line(format_condition(x)) } -#' @export -replay.value <- function(x) { - if (x$visible) print(x$value) -} - #' @export replay.recordedplot <- function(x) { print(x) @@ -88,14 +75,9 @@ format_condition <- function(x) { } body <- conditionMessage(x) - if (inherits(x, "message")) { - - } - paste0(header, "\n", body) } - #' Line prompt. #' #' Format a single expression as if it had been entered at the command prompt. diff --git a/tests/testthat/_snaps/replay.md b/tests/testthat/_snaps/replay.md index 55befee..a47efb5 100644 --- a/tests/testthat/_snaps/replay.md +++ b/tests/testthat/_snaps/replay.md @@ -31,6 +31,15 @@ Error in f(): 4 +# replace nicely formats multiple lines + + Code + replay(ev) + Output + > 1 + + + 2 + [1] 3 + # format_condition handles different types of warning Code diff --git a/tests/testthat/test-replay.R b/tests/testthat/test-replay.R index 10699ec..79f2f9d 100644 --- a/tests/testthat/test-replay.R +++ b/tests/testthat/test-replay.R @@ -33,6 +33,22 @@ test_that("replay handles rlang conditions", { expect_snapshot(replay(ev)) }) +test_that("replace nicely formats multiple lines", { + ev <- evaluate("1 + \n 2") + expect_snapshot(replay(ev)) +}) + +test_that("can replay plots", { + ev <- evaluate("plot(1)") + + path <- withr::local_tempfile() + pdf(path) + expect_output(replay(ev)) + dev.off() + + expect_true(file.exists(path)) +}) + test_that("format_condition handles different types of warning", { expect_snapshot({ w1 <- simpleWarning("This is a warning")