Skip to content

Commit 894e0b3

Browse files
authored
Merge pull request PecanProject#3814 from KrishnaShuk/refactor/test-status-isolation
test(utils): improve test isolation in test-status.R
2 parents fefff05 + 68edc74 commit 894e0b3

File tree

1 file changed

+6
-13
lines changed

1 file changed

+6
-13
lines changed

base/utils/tests/testthat/test-status.R

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,8 @@
11
context("status")
22

3-
make_testdir <- function() {
4-
td <- tempfile()
5-
dir.create(td)
6-
teardown(unlink(td, recursive = TRUE, force = TRUE))
7-
8-
td
9-
}
103

114
test_that("status functions accept explicit filename", {
12-
d <- make_testdir()
5+
d <- withr::local_tempdir()
136
f <- file.path(d, "MY_STATUS")
147

158
expect_silent(status.start("TRAITS", f))
@@ -29,22 +22,22 @@ test_that("status functions accept explicit filename", {
2922
})
3023

3124
test_that("status handles file = dir/", {
32-
d <- make_testdir()
25+
d <- withr::local_tempdir()
3326
status.start("NONE", d)
3427
status.end("DONE", d)
3528
expect_equal(status.check("NONE", file.path(d, "STATUS")), 1L)
3629
})
3730

3831
test_that("status functions read from local settings", {
39-
settings <- list(outdir = make_testdir())
32+
settings <- list(outdir = withr::local_tempdir())
4033
expect_silent(status.skip("auto"))
4134
expect_match(
4235
readLines(file.path(settings$outdir, "STATUS"))[[1]],
4336
"^auto.*SKIPPED\\s*$")
4437
})
4538

4639
test_that("status finds settings defined outside immediate calling scope", {
47-
settings <- list(outdir = make_testdir())
40+
settings <- list(outdir = withr::local_tempdir())
4841
f <- function(name) {
4942
status.start(name)
5043
status.end()
@@ -60,11 +53,11 @@ test_that("status finds settings defined outside immediate calling scope", {
6053

6154
test_that("status writes to stdout on bad filename", {
6255
expect_output(status.start("NOFILE"), "NOFILE")
63-
settings <- list(outdir = file.path(make_testdir(), "fake", "path"))
56+
settings <- list(outdir = file.path(withr::local_tempdir(), "fake", "path"))
6457
expect_output(status.end(), "\\d{4}-\\d{2}-\\d{2}.*DONE")
6558
})
6659

6760
test_that("status.check returns 0 on bad filename", {
6861
expect_equal(status.check("NOFILE"), 0L)
69-
expect_equal(status.check("NOFILE", file.path(make_testdir(), "fake")), 0L)
62+
expect_equal(status.check("NOFILE", file.path(withr::local_tempdir(), "fake")), 0L)
7063
})

0 commit comments

Comments
 (0)