1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65
|
NAME <- "capture"
source(file.path('_helper', 'init.R'))
# - capture width issues -------------------------------------------------------
local({
old.opt <- options(width=40L)
on.exit(options(old.opt))
etc <- new("Settings", style=StyleRaw(), text.width=5L) # impossible width
# warn: "Unable to set desired "
res <- diffobj:::capture(letters, etc, function(...) do.call(cat, list(...)))
all.equal(nchar(res), c(40L, 40L, 36L))
})
# - errors in capture ----------------------------------------------------------
etc <- new("Settings", style=StyleRaw())
try(diffobj:::capture(stop('boom'), etc, function(...) stop(...))) # boom
print <- function() NULL
str <- function() NULL
etc@mode <- "auto"
etc@frame <- environment()
try(diffobj:::capt_print(1, 2, etc, function(...) stop(...), list())) # compose
# spec object
try(diffobj:::capt_str(1, 2, etc, function(...) stop(...), list(object=1)))
try( # attempting to deparse
diffobj:::capt_deparse(
stop('a'), stop('b'), etc, function(...) stop(...), list()
)
)
try( # target
suppressWarnings(
diffobj:::capt_file(
tempfile(), tempfile(), etc, function(...) stop(...), list()
) )
)
local({
f <- tempfile()
on.exit(unlink(f), add=TRUE)
writeLines(letters, f)
try( # "`current`"
suppressWarnings(
diffobj:::capt_file(f, tempfile(), etc, function(...) stop(...), list())
)
)
try( # "`target`"
suppressWarnings(
diffobj:::capt_csv(
tempfile(), tempfile(), etc, function(...) stop(...), list()
) )
)
try( # "`current`"
suppressWarnings(
diffobj:::capt_csv(
f, tempfile(), etc, function(...) stop(...), list()
) )
)
})
bad_obj <- structure(list(NULL), class='diffobj_ogewlhgiadfl3')
try( # "Coercion of `target`"
diffobj:::capt_chr(bad_obj, letters, etc, function(...) stop(...), list())
)
try( # "Coercion of `current`"
diffobj:::capt_chr(letters, bad_obj, etc, function(...) stop(...), list())
)
|