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