Skip to content

Commit 9c93b8f

Browse files
authored
Utils upkeep (#2140)
* Remove older R work arounds * Remove older withr work arounds * Remove utils functions that are only used in one place
1 parent 8566f94 commit 9c93b8f

File tree

10 files changed

+18
-52
lines changed

10 files changed

+18
-52
lines changed

R/deprec-condition.R

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ capture_messages <- function(code) {
101101
code,
102102
message = function(condition) {
103103
out$push(condition)
104-
maybe_restart("muffleMessage")
104+
tryInvokeRestart("muffleMessage")
105105
}
106106
)
107107

@@ -121,7 +121,7 @@ capture_warnings <- function(code, ignore_deprecation = FALSE) {
121121
}
122122

123123
out$push(condition)
124-
maybe_restart("muffleWarning")
124+
tryInvokeRestart("muffleWarning")
125125
}
126126
)
127127

R/evaluate-promise.R

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,14 @@ evaluate_promise <- function(code, print = FALSE) {
2020
handle_warning <- function(condition) {
2121
if (!is_deprecation(condition)) {
2222
warnings$push(condition)
23-
maybe_restart("muffleWarning")
23+
tryInvokeRestart("muffleWarning")
2424
}
2525
}
2626

2727
messages <- Stack$new()
2828
handle_message <- function(condition) {
2929
messages$push(condition)
30-
maybe_restart("muffleMessage")
30+
tryInvokeRestart("muffleMessage")
3131
}
3232

3333
path <- withr::local_tempfile()

R/expect-condition.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -351,7 +351,7 @@ cnd_matcher <- function(
351351
if (!is.null(class) && !inherits(x, class)) {
352352
return(FALSE)
353353
}
354-
if (!is.null(regexp) && !isNA(regexp)) {
354+
if (!is.null(regexp) && !identical(regexp, NA)) {
355355
withCallingHandlers(
356356
grepl(regexp, conditionMessage(x), ...),
357357
error = function(e) {

R/expect-self-test.R

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -163,9 +163,7 @@ expect_snapshot_reporter <- function(
163163
paths = test_path("reporters/tests.R")
164164
) {
165165
local_options(rlang_trace_format_srcrefs = FALSE)
166-
withr::local_rng_version("3.3")
167-
set.seed(1014)
168-
# withr::local_seed(1014)
166+
withr::local_seed(1014)
169167

170168
expect_snapshot_output(
171169
with_reporter(reporter, {

R/test-that.R

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -163,11 +163,11 @@ test_code <- function(test, code, env, reporter, skip_on_empty = TRUE) {
163163

164164
register_expectation(e, 5)
165165

166-
maybe_restart("muffleWarning")
166+
tryInvokeRestart("muffleWarning")
167167
}
168168
handle_message <- function(e) {
169169
if (edition_get() < 3) {
170-
maybe_restart("muffleMessage")
170+
tryInvokeRestart("muffleMessage")
171171
}
172172
}
173173
handle_skip <- function(e) {

R/try-again.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ try_again <- function(times, code) {
2525
if (
2626
identical(e$message, "restarting interrupted promise evaluation")
2727
) {
28-
maybe_restart("muffleWarning")
28+
tryInvokeRestart("muffleWarning")
2929
}
3030
}
3131
),

R/utils.R

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -27,15 +27,6 @@ escape_regex <- function(x) {
2727
)
2828
}
2929

30-
maybe_restart <- function(restart) {
31-
if (!is.null(findRestart(restart))) {
32-
invokeRestart(restart)
33-
}
34-
}
35-
36-
# Backport for R < 4.0
37-
deparse1 <- function(expr, ...) paste(deparse(expr, ...), collapse = "\n")
38-
3930
can_entrace <- function(cnd) {
4031
!inherits(cnd, "Throwable")
4132
}
@@ -48,8 +39,6 @@ transport_fun <- function(f) {
4839
f
4940
}
5041

51-
isNA <- function(x) length(x) == 1 && is.na(x)
52-
5342
compact <- function(x) {
5443
x[lengths(x) > 0]
5544
}
@@ -99,10 +88,3 @@ map_lgl <- function(.x, .f, ...) {
9988
}
10089

10190
r_version <- function() paste0("R", getRversion()[, 1:2])
102-
103-
# Waiting on https://github.com/r-lib/withr/pull/188
104-
local_tempfile1 <- function(lines, env = parent.frame()) {
105-
path <- withr::local_tempfile(.local_envir = env)
106-
writeLines(lines, path)
107-
path
108-
}

tests/testthat/_snaps/reporter-progress.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131

3232
[ FAIL 1 | WARN 0 | SKIP 0 | PASS 0 ]
3333

34-
I believe in you!
34+
No one gets it right on their first try
3535

3636
# gracefully handles multiple contexts
3737

@@ -45,7 +45,7 @@
4545
== Results =====================================================================
4646
[ FAIL 0 | WARN 0 | SKIP 0 | PASS 1 ]
4747

48-
You rock!
48+
Way to go!
4949

5050
# fails after max_fail tests
5151

@@ -205,7 +205,7 @@
205205
[ FAIL 11 | WARN 0 | SKIP 0 | PASS 0 ]
206206
== Terminated early ============================================================
207207

208-
I believe in you!
208+
No one gets it right on their first try
209209

210210
# can fully suppress incremental updates
211211

@@ -224,7 +224,7 @@
224224
== Results =====================================================================
225225
[ FAIL 0 | WARN 0 | SKIP 0 | PASS 7 ]
226226

227-
You rock!
227+
Way to go!
228228

229229
---
230230

@@ -235,7 +235,7 @@
235235
== Results =====================================================================
236236
[ FAIL 0 | WARN 0 | SKIP 0 | PASS 7 ]
237237

238-
You rock!
238+
Way to go!
239239

240240
# reports backtraces
241241

@@ -509,7 +509,7 @@
509509

510510
[ FAIL 9 | WARN 1 | SKIP 0 | PASS 1 ]
511511

512-
I believe in you!
512+
No one gets it right on their first try
513513

514514
# records skips
515515

@@ -527,7 +527,7 @@
527527

528528
[ FAIL 0 | WARN 0 | SKIP 2 | PASS 0 ]
529529

530-
You rock!
530+
Way to go!
531531

532532
# compact display is informative
533533

tests/testthat/_snaps/skip.md

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,7 @@
1616

1717
# autogenerated message is always single line
1818

19-
Reason: a_very_long_argument_name || a_very_long_argument_name || a_very_long_argument_name ||
20-
a_very_long_argument_name || a_very_long_argument_name ||
21-
a_very_long_argument_name || a_very_long_argument_name ||
22-
a_very_long_argument_name || a_very_long_argument_name ||
23-
a_very_long_argument_name || a_very_long_argument_name ||
24-
a_very_long_argument_name || a_very_long_argument_name ||
25-
a_very_long_argument_name is not TRUE
19+
Reason: a_very_long_argument_name || a_very_long_argument_name || a_very_long_argument_name || a_very_long_argument_name || a_very_long_argument_name || a_very_long_argument_name || a_very_long_argument_name || a_very_long_argument_name || a_very_long_argument_name || a_very_long_argument_name || a_very_long_argument_name || a_very_long_argument_name || a_very_long_argument_name || a_very_long_argument_name is not TRUE
2620

2721
# skip_if_not_installed() works as expected
2822

@@ -36,14 +30,6 @@
3630

3731
Reason: offline
3832

39-
# skip_on_cran generates useful message
40-
41-
Reason: On CRAN
42-
43-
# skip_on_cran() works as expected
44-
45-
Reason: On CRAN
46-
4733
# skip_on_ci() works as expected
4834

4935
Reason: On CI

tests/testthat/test-snapshot-file.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ test_that("can announce snapshot file", {
8686
})
8787

8888
test_that("can transform snapshot contents", {
89-
path <- local_tempfile1(c("secret", "ssh secret squirrel"))
89+
path <- withr::local_tempfile(lines = c("secret", "ssh secret squirrel"))
9090

9191
redact <- function(x) gsub("secret", "<redacted>", x)
9292
expect_snapshot_file(path, "secret.txt", transform = redact)

0 commit comments

Comments
 (0)