context("unit test for utils-desc")
# load_packages_mentioned_in_description ----------------------------------
test_that("load_packages_mentioned_in_description fails if there is no DESCRIPTION file", {
path_temp <- .get_temp_dir()
.delete_and_create_dir(path_temp)
#############################
## Invalid Input Arguments ##
#############################
## No DESCRIPTION file
expect_error(load_packages_mentioned_in_description(path = path_temp))
})
test_that("load_packages_mentioned_in_description works", {
path_temp <- .get_temp_dir()
.delete_and_create_dir(path_temp)
## Create a DESCRIPTION object
target <- file.path(path_temp, "DESCRIPTION")
writeLines("Package: test", target)
description_obj <- desc::description$new(file = path_temp)
###########################
## Valid Input Arguments ##
###########################
## Empty DESCRIPTION file
expect_silent(load_packages_mentioned_in_description(path = path_temp))
## Ignore "R" dependency
description_obj$set_dep(package = "R", type = "Depends", version = ">= 3.5.2")
description_obj$write(target)
expect_silent(load_packages_mentioned_in_description(path = path_temp))
## One dependency of type "Imports"
description_obj$set_dep(package = "parallel", type = "Imports", version = "*")
description_obj$write(target)
try(detach("package:parallel", unload = TRUE, character.only = TRUE, force = TRUE), silent = TRUE)
expect_message(load_packages_mentioned_in_description(path = path_temp))
expect_true("parallel" %in% .packages())
## Non-existing dependencies
description_obj$set_dep(package = "xxx", type = "Imports", version = "*")
description_obj$set_dep(package = "yyy", type = "Imports", version = "*")
description_obj$write(target)
expect_message(load_packages_mentioned_in_description(path = path_temp))
})
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.