Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions R/source.R
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ datasource <- function(
comment = "",
skip_quote = TRUE
) {
if (length(file) == 0) {
stop("`file` vector length must be greater than 0", call. = FALSE)
}
if (inherits(file, "source")) {
# If `skip` and `comment` arguments are expliictly passed, we want to use
# those even if `file` is already a source
Expand Down
9 changes: 9 additions & 0 deletions tests/testthat/test-read-file.R
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,10 @@ test_that("read_file returns \"\" on an empty file", {
expect_equal(read_file(test_path("empty-file")), "")
})

test_that("read_file errors when provided an empty vector", {
expect_error(read_file(raw()))
expect_error(read_file(numeric()))
})
# read_file_raw ---------------------------------------------------------------

test_that("read_file_raw works with a local text file", {
Expand All @@ -84,3 +88,8 @@ test_that("read_file_raw works with a character datasource", {
test_that("read_file_raw returns raw() on an empty file", {
expect_equal(read_file_raw(test_path("empty-file")), raw())
})

test_that("read_file_raw errors when provided an empty vector", {
expect_error(read_file_raw(raw()))
expect_error(read_file_raw(numeric()))
})