Skip to content

Commit 6f7163b

Browse files
write to tempfile() not local file (#472)
1 parent 5996c52 commit 6f7163b

File tree

3 files changed

+18
-12
lines changed

3 files changed

+18
-12
lines changed

tests/testthat/test-file_coverage.R

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
context("file_coverage")
2-
writeLines(con = "s1",
2+
s1 <- tempfile()
3+
t1 <- tempfile()
4+
writeLines(con = s1,
35
"a <- function(x) {
46
x + 1
57
}
@@ -9,18 +11,18 @@ b <- function(x) {
911
else FALSE
1012
}")
1113

12-
writeLines(con = "t1",
14+
writeLines(con = t1,
1315
"a(1)
1416
a(2)
1517
a(3)
1618
b(0)
1719
b(1)
1820
b(2)")
1921

20-
on.exit(unlink(c("s1", "t1")))
22+
on.exit(unlink(c(s1, t1)))
2123

2224
test_that("it works on single files", {
23-
cov <- file_coverage("s1", "t1")
25+
cov <- file_coverage(s1, t1)
2426
cov_d <- as.data.frame(cov)
2527

2628
expect_equal(cov_d$functions, c("a", "b", "b", "b"))

tests/testthat/test-memoised.R

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
context("memoised")
2-
writeLines(con = "s1",
2+
s1 <- tempfile()
3+
t1 <- tempfile()
4+
writeLines(con = s1,
35
"a <- memoise::memoise(function(x) {
46
x + 1
57
})")
68

7-
writeLines(con = "t1",
9+
writeLines(con = t1,
810
"
911
a(1)
1012
a(1)
@@ -13,10 +15,10 @@ a(1)
1315
a(2)
1416
a(3)")
1517

16-
on.exit(unlink(c("s1", "t1")))
18+
on.exit(unlink(c(s1, t1)))
1719

1820
test_that("it works on Vectorized functions", {
19-
cov <- file_coverage("s1", "t1")
21+
cov <- file_coverage(s1, t1)
2022
cov_d <- as.data.frame(cov)
2123

2224
expect_equal(cov_d$functions, "a")

tests/testthat/test-vectorized.R

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,20 @@
11
context("Vectorize")
2-
writeLines(con = "s1",
2+
s1 = tempfile()
3+
t1 = tempfile()
4+
writeLines(con = s1,
35
'scalar_func <- function(x,y) {
46
z <- x + y
57
}
68
79
vector_func <- Vectorize(scalar_func,vectorize.args=c("x","y"),SIMPLIFY=TRUE)')
810

9-
writeLines(con = "t1",
11+
writeLines(con = t1,
1012
"vector_func(1:10, 2)")
1113

12-
on.exit(unlink(c("s1", "t1")))
14+
on.exit(unlink(c(s1, t1)))
1315

1416
test_that("it works on Vectorized functions", {
15-
cov <- file_coverage("s1", "t1")
17+
cov <- file_coverage(s1, t1)
1618
cov_d <- as.data.frame(cov)
1719

1820
expect_equal(cov_d$functions, "vector_func")

0 commit comments

Comments
 (0)