/usr/share/doc/r-cran-withr/tests/testthat/test-connection.R is in r-cran-withr 2.1.0-1ubuntu3.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 | context("connection")
describe("with_connection", {
it("errors if connection is not named", {
expect_error({
with_connection(list(TRUE), TRUE)
}, "all(is.named(con)) is not TRUE", fixed = TRUE)
})
it("creates a single connection", {
tmp <- tempfile()
on.exit(unlink(tmp))
expect_false(exists("con"))
with_connection(list(con = file(tmp, "w")), {
writeLines(c("foo", "bar"), con)
})
expect_false(exists("con"))
expect_equal(readLines(tmp), c("foo", "bar"))
})
it("creates multiple connections", {
tmp <- tempfile()
tmp2 <- tempfile()
on.exit(unlink(c(tmp, tmp2)))
expect_false(exists("con"))
expect_false(exists("con2"))
with_connection(list(con = file(tmp, "w"), con2 = file(tmp2, "w")), {
writeLines(c("foo", "bar"), con)
writeLines(c("baz", "qux"), con2)
})
expect_false(exists("con"))
expect_false(exists("con2"))
expect_equal(readLines(tmp), c("foo", "bar"))
expect_equal(readLines(tmp2), c("baz", "qux"))
})
})
describe("local_connection", {
it("creates a single connection", {
tmp <- tempfile()
on.exit(unlink(tmp))
expect_false(exists("con"))
(function() {
con <- local_connection(file(tmp, "w"))
writeLines(c("foo", "bar"), con)
})()
expect_false(exists("con"))
expect_equal(readLines(tmp), c("foo", "bar"))
})
})
|