File: test-capture.Rout.save

package info (click to toggle)
r-cran-diffobj 0.3.5-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 2,432 kB
  • sloc: ansic: 455; javascript: 96; sh: 32; makefile: 8
file content (118 lines) | stat: -rwxr-xr-x 4,484 bytes parent folder | download
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118

R version 4.0.3 (2020-10-10) -- "Bunny-Wunnies Freak Out"
Copyright (C) 2020 The R Foundation for Statistical Computing
Platform: x86_64-apple-darwin17.0 (64-bit)

R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.

R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.

Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.

> 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))
+ })
[1] TRUE
Warning message:
In diffobj:::capture(letters, etc, function(...) do.call(cat, list(...))) :
  Unable to set desired width 5, (invalid 'width' parameter, allowed 10...10000);proceeding with existing setting.
> 
> # - errors in capture ----------------------------------------------------------
> 
> etc <- new("Settings", style=StyleRaw())
> try(diffobj:::capture(stop('boom'), etc, function(...) stop(...))) # boom
Error in eval(x, etc@frame) : boom
Error in err("Failed attempting to get text representation of object: ",  : 
  Failed attempting to get text representation of object: boom
> print <- function() NULL
> str <- function() NULL
> etc@mode <- "auto"
> etc@frame <- environment()
> try(diffobj:::capt_print(1, 2, etc, function(...) stop(...), list())) # compose
Error in match.call(definition, call, expand.dots, envir) : 
  unused argument (x = NULL)
Error in err("Unable to compose `print` call") : 
  Unable to compose `print` call
> # spec object
> try(diffobj:::capt_str(1, 2, etc, function(...) stop(...), list(object=1)))
Error in err("You may not specify `object` as part of `extra`") : 
  You may not specify `object` as part of `extra`
> try(  # attempting to deparse
+   diffobj:::capt_deparse(
+     stop('a'), stop('b'), etc,  function(...) stop(...), list()
+   )
+ )
Error in do.call(deparse, c(list(target), extra), quote = TRUE) : a
Error in err("Error attempting to deparse object(s)") : 
  Error attempting to deparse object(s)
> try(  # target
+   suppressWarnings(
+     diffobj:::capt_file(
+       tempfile(), tempfile(), etc,  function(...) stop(...), list()
+   ) )
+ )
Error in file(con, "r") : cannot open the connection
Error in err("Unable to read `target` file.") : 
  Unable to read `target` file.
> 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()
+     ) )
+   )
+ })
Error in file(con, "r") : cannot open the connection
Error in err("Unable to read `current` file.") : 
  Unable to read `current` file.
Error in file(file, "rt") : cannot open the connection
Error in err("Unable to read `target` file.") : 
  Unable to read `target` file.
Error in file(file, "rt") : cannot open the connection
Error in err("Unable to read `current` file.") : 
  Unable to read `current` file.
> bad_obj <- structure(list(NULL), class='diffobj_ogewlhgiadfl3')
> try( # "Coercion of `target`"
+   diffobj:::capt_chr(bad_obj, letters, etc,  function(...) stop(...), list())
+ )
Error in diffobj:::capt_chr(bad_obj, letters, etc, function(...) stop(...),  : 
  Coercion of `target` did not produce character object (list).
> try( # "Coercion of `current`"
+   diffobj:::capt_chr(letters, bad_obj, etc,  function(...) stop(...), list())
+ )
Error in diffobj:::capt_chr(letters, bad_obj, etc, function(...) stop(...),  : 
  Coercion of `current` did not produce character object (list).
> 
> proc.time()
   user  system elapsed 
  1.053   0.116   1.168