tests/testthat/test_package2install.R

file1 <- "data/exampleCode.R"
file2 <- "data/exampleCodeMD.Rmd"
dir <- "data"

test_that(".findPackages return character vector", {
    expect_is(.findPackages(file1), "character")
    expect_is(.findPackages(file2), "character")
})

test_that(".findPackages works for library and require", {
    expect_equal(.findPackages(file1),
                 c("plotly",
                   "rmarkdown",
                   "testthat",
                   "shiny",
                   "plumber",
                   "devtools"))
    expect_equal(.findPackages(file2),
                 c("MASS",
                   "broom",
                   "devtools",
                   "forcats",
                   "httr",
                   "lme4",
                   "usethis",
                   "xml2"))
})


test_that("packages2Install works for library and require", {
    expect_output(
        packages2Install(dir),
        "install\\.packages\\(c\\(\"broom\", \"devtools\", \"forcats\", \"httr\", \"lme4\", \"MASS\", \"plotly\", \"plumber\", \"rmarkdown\", \"shiny\", \"testthat\", \"usethis\", \"xml2\"\\)\\)"
    )
})
juliendiot42/rjdiotperso documentation built on Jan. 8, 2020, 3:38 p.m.