|
| 1 | +test_that("creating a new R file works", { |
| 2 | + |
| 3 | + file_name <- file.path(tempdir(check = TRUE), "hello.R") |
| 4 | + |
| 5 | + expect_false(file.exists(file_name)) |
| 6 | + |
| 7 | + file_new(file_name, "R", open = FALSE) |
| 8 | + |
| 9 | + expect_true(file.exists(file_name)) |
| 10 | + |
| 11 | + on.exit(unlink(tempdir(), recursive = TRUE), add = TRUE) |
| 12 | + |
| 13 | +}) |
| 14 | + |
| 15 | +test_that("creating a new JS file works", { |
| 16 | + |
| 17 | + file_name <- file.path(tempdir(check = TRUE), "hello.js") |
| 18 | + |
| 19 | + expect_false(file.exists(file_name)) |
| 20 | + |
| 21 | + file_new(file_name, "js", open = FALSE) |
| 22 | + |
| 23 | + expect_true(file.exists(file_name)) |
| 24 | + |
| 25 | + on.exit(unlink(tempdir(), recursive = TRUE), add = TRUE) |
| 26 | + |
| 27 | +}) |
| 28 | + |
| 29 | +test_that("creating a new markdown file works", { |
| 30 | + |
| 31 | + file_name <- file.path(tempdir(check = TRUE), "hello.md") |
| 32 | + |
| 33 | + expect_false(file.exists(file_name)) |
| 34 | + |
| 35 | + file_new_md(file_name, open = FALSE) |
| 36 | + |
| 37 | + expect_true(file.exists(file_name)) |
| 38 | + |
| 39 | + on.exit(unlink(tempdir(), recursive = TRUE), add = TRUE) |
| 40 | + |
| 41 | +}) |
| 42 | + |
| 43 | +test_that("creating a new text file works", { |
| 44 | + |
| 45 | + file_name <- file.path(tempdir(check = TRUE), "hello.txt") |
| 46 | + |
| 47 | + expect_false(file.exists(file_name)) |
| 48 | + |
| 49 | + file_new_text(file_name, open = FALSE) |
| 50 | + |
| 51 | + expect_true(file.exists(file_name)) |
| 52 | + |
| 53 | + on.exit(unlink(tempdir(), recursive = TRUE), add = TRUE) |
| 54 | + |
| 55 | +}) |
| 56 | + |
| 57 | +test_that("deleting a file works", { |
| 58 | + |
| 59 | + file_name <- tempfile(tmpdir = tempdir(check = TRUE), fileext = ".R") |
| 60 | + |
| 61 | + expect_false(file.exists(file_name)) |
| 62 | + |
| 63 | + writeLines("I exist!", con = file_name) |
| 64 | + |
| 65 | + expect_true(file.exists(file_name)) |
| 66 | + |
| 67 | + file_delete(file_name, ask = FALSE) |
| 68 | + |
| 69 | + expect_false(file.exists(file_name)) |
| 70 | + |
| 71 | + on.exit(unlink(tempdir(), recursive = TRUE), add = TRUE) |
| 72 | + |
| 73 | +}) |
| 74 | + |
| 75 | +test_that("copying files works", { |
| 76 | + |
| 77 | + file_name <- tempfile(tmpdir = tempdir(check = TRUE), fileext = ".R") |
| 78 | + copy_name <- tempfile(pattern = "copy", tmpdir = tempdir(check = TRUE), fileext = ".R") |
| 79 | + |
| 80 | + expect_false(file.exists(file_name)) |
| 81 | + expect_false(file.exists(copy_name)) |
| 82 | + |
| 83 | + writeLines("I exist!", con = file_name) |
| 84 | + |
| 85 | + expect_true(file.exists(file_name)) |
| 86 | + file_copy(file_name, copy_name) |
| 87 | + expect_true(file.exists(copy_name)) |
| 88 | + |
| 89 | + on.exit(unlink(tempdir(), recursive = TRUE), add = TRUE) |
| 90 | + |
| 91 | +}) |
0 commit comments