Skip to content

Commit a979ffd

Browse files
Use local_tempfile() to create local file (#4903)
* Use local_tempfile() to create local file * lines= argument requries withr 2.5.0
1 parent 60f8654 commit a979ffd

File tree

2 files changed

+11
-15
lines changed

2 files changed

+11
-15
lines changed

DESCRIPTION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ Imports:
4444
stats,
4545
tibble,
4646
vctrs (>= 0.4.1),
47-
withr (>= 2.0.0)
47+
withr (>= 2.5.0)
4848
Suggests:
4949
covr,
5050
dplyr,

tests/testthat/test-prohibited-functions.R

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -36,20 +36,16 @@ get_n_data.frame <- function(f) {
3636
}
3737

3838
test_that("`get_n_*() detects number of calls properly", {
39-
withr::local_file("tmp.R")
40-
writeLines(
41-
c(
42-
'stop("foo!")',
43-
'warning("bar!")',
44-
"data.frame(x = 1)",
45-
"base::data.frame(x = 1)" # this is not counted
46-
),
47-
"tmp.R"
48-
)
49-
50-
expect_equal(get_n_stop("tmp.R"), 1)
51-
expect_equal(get_n_warning("tmp.R"), 1)
52-
expect_equal(get_n_data.frame("tmp.R"), 1)
39+
tmp <- withr::local_tempfile(lines = c(
40+
'stop("foo!")',
41+
'warning("bar!")',
42+
"data.frame(x = 1)",
43+
"base::data.frame(x = 1)" # this is not counted
44+
))
45+
46+
expect_equal(get_n_stop(tmp), 1)
47+
expect_equal(get_n_warning(tmp), 1)
48+
expect_equal(get_n_data.frame(tmp), 1)
5349
})
5450

5551
# Pattern is needed filter out files such as ggplot2.rdb, which is created when running covr::package_coverage()

0 commit comments

Comments
 (0)