Debian Codegraph @

inst/testme/test-utils,conditions.R

raw
1 library(parallelly)
2
3 message("*** utils,conditions ...")
4
5 stopf <- parallelly:::stopf
6 warnf <- parallelly:::warnf
7 msgf <- parallelly:::msgf
8
9 message("*** stopf() ...")
10
11 res <- tryCatch({
12 stopf("Hello %s", "world")
13 }, error = identity)
14 print(res)
15 stopifnot(inherits(res, "simpleError"))
16 stopifnot(grepl("Hello world", res$message))
17
18
19 res <- tryCatch({
20 stopf("Hello %s", "world", call. = quote(a + b))
21 }, error = identity)
22 print(res)
23 stopifnot(inherits(res, "simpleError"))
24 stopifnot(grepl("Hello world", res$message))
25
26
27 res <- tryCatch({
28 stopf("Hello %s", "world", call. = NULL)
29 }, error = identity)
30 print(res)
31 stopifnot(inherits(res, "simpleError"))
32 stopifnot(grepl("Hello world", res$message))
33
34
35 res <- tryCatch({
36 stopf("Hello %s", "world", call. = TRUE)
37 }, error = identity)
38 print(res)
39 stopifnot(inherits(res, "simpleError"))
40 stopifnot(grepl("Hello world", res$message))
41
42
43 f <- function() {
44 stopf("Hello %s", "world", call. = sys.call())
45 }
46 res <- tryCatch(f(), error = identity)
47 print(res)
48 stopifnot(inherits(res, "simpleError"))
49 stopifnot(grepl("Hello world", res$message))
50
51
52 res <- tryCatch({
53 stopf("Hello %s", "world", domain = "R-futile.options")
54 }, error = identity)
55 print(res)
56 stopifnot(inherits(res, "simpleError"))
57 stopifnot(grepl("Hello world", res$message))
58
59 message("*** stopf() ... DONE")
60
61 message("*** warnf() ...")
62
63 res <- tryCatch({
64 warnf("Hello %s", "world")
65 }, warning = identity)
66 print(res)
67 stopifnot(inherits(res, "simpleWarning"))
68 stopifnot(grepl("Hello world", res$message))
69
70
71 res <- tryCatch({
72 warnf("Hello %s", "world", immediate. = TRUE)
73 }, warning = identity)
74 print(res)
75 stopifnot(inherits(res, "simpleWarning"))
76 stopifnot(grepl("Hello world", res$message))
77
78
79 res <- tryCatch({
80 warnf("Hello %s", "world", immediate. = TRUE, domain = "R-futile.options")
81 }, warning = identity)
82 print(res)
83 stopifnot(inherits(res, "simpleWarning"))
84 stopifnot(grepl("Hello world", res$message))
85
86
87 res <- tryCatch({
88 warnf("Hello %s", "world", call. = quote(a + b))
89 }, warning = identity)
90 print(res)
91 stopifnot(inherits(res, "simpleWarning"))
92 stopifnot(grepl("Hello world", res$message))
93
94
95 res <- tryCatch({
96 warnf("Hello %s", "world", call. = NULL)
97 }, warning = identity)
98 print(res)
99 stopifnot(inherits(res, "simpleWarning"))
100 stopifnot(grepl("Hello world", res$message))
101
102
103 res <- tryCatch({
104 warnf("Hello %s", "world", call. = TRUE)
105 }, warning = identity)
106 print(res)
107 stopifnot(inherits(res, "simpleWarning"))
108 stopifnot(grepl("Hello world", res$message))
109
110
111 f <- function() {
112 warnf("Hello %s", "world", call. = sys.call())
113 }
114 res <- tryCatch(f(), warning = identity)
115 print(res)
116 stopifnot(inherits(res, "simpleWarning"))
117 stopifnot(grepl("Hello world", res$message))
118
119
120 res <- tryCatch({
121 warnf("Hello %s", "world", domain = "R-futile.options")
122 }, warning = identity)
123 print(res)
124 stopifnot(inherits(res, "simpleWarning"))
125 stopifnot(grepl("Hello world", res$message))
126
127 message("*** warnf() ... DONE")
128
129 message("*** msgf() ...")
130
131 msg <- "Hello world"
132 res <- capture.output({
133 msgf("Hello %s", "world")
134 }, type = "message")
135 print(res)
136 stopifnot(identical(res, msg))
137
138
139 msg <- "Hello world"
140 res <- capture.output({
141 msgf("Hello %s", "world", appendLF = TRUE)
142 }, type = "message")
143 print(res)
144 stopifnot(identical(res, msg))
145
146
147 msg <- "Hello world"
148 res <- capture.output({
149 msgf("Hello %s", "world", domain = "R-futile.options")
150 }, type = "message")
151 print(res)
152 stopifnot(identical(res, msg))
153
154
155 msg <- "Hello world"
156 res <- capture.output({
157 msgf("Hello %s", "world", appendLF = TRUE, domain = "R-futile.options")
158 }, type = "message")
159 print(res)
160 stopifnot(identical(res, msg))
161
162
163 message("*** msgf() ... DONE")
164
165
166 message("*** utils,conditions ... DONE")