File: test-file.R

package info (click to toggle)
r-cran-assertthat 0.2.1-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, forky, sid, trixie
  • size: 220 kB
  • sloc: sh: 9; makefile: 2
file content (41 lines) | stat: -rw-r--r-- 1,130 bytes parent folder | download | duplicates (2)
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
context("File assertions")

test_that("is.dir identifies dirs correctly", {
  expect_true(is.dir(tempdir()))
  expect_error(is.dir(tempfile()))
})

test_that("is.writeable works correctly", {
  expect_true(is.writeable(tempdir()))
  tf <- tempfile()
  expect_error(is.writeable(tf)) # file doesn't exist yet
  cat("foo", file=tf)
  expect_true(is.writeable(tf)) # ...but now it does
})

test_that("is.readable works correctly", {
  expect_true(is.readable(tempdir()))
  tf <- tempfile()
  expect_error(is.readable(tf)) # file doesn't exist yet
  cat("foo", file=tf)
  expect_true(is.readable(tf)) # ...but now it does
})

test_that("has_extension works correctly", {
  # no extension
  tf <- tempfile()
  expect_true(has_extension(tf, ""))
  expect_false(has_extension(tf, "x"))
         
  # normal extension
  ext <- "test"
  tf <- tempfile(fileext=paste0(".", ext))
  expect_true(has_extension(tf, ext))
  expect_false(has_extension(tf, paste0(ext, "x")))
  
  # empty extension
  ext <- ""
  tf <- tempfile(fileext=paste0(".", ext))
  expect_true(has_extension(tf, ext))
  expect_false(has_extension(tf, paste0(ext, "x")))
})