library(testthat)
# R/utils.R
source_all <- function(paths, ...) {
lapply(paths, source, ...)
invisible(paths)
}
# test/testthat/test-utils.R
test_that("sources all files", {
r <- withr::local_tempdir()
file1 <- fs::file_create(fs::path(r, "x.R"))
file2 <- fs::file_create(fs::path(r, "y.R"))
writeLines("x <- 1", file1)
writeLines("y <- 1", file2)
e <- new.env()
files <- c("x.R", "y.R")
source_all(fs::path(r, files), local = e)
expect_equal(ls(envir = e), c("x", "y"))
})
#> Test passed 😀
Created on 2021-05-17 by the reprex package (v2.0.0)