Skip to content
Snippets Groups Projects
Commit a50331e6 authored by David Dorchies's avatar David Dorchies
Browse files

fix(add_report): check if template exists

Refs #11
parent a8ed6a02
No related branches found
No related tags found
No related merge requests found
......@@ -10,10 +10,13 @@
#'
#' @inherit create_reports examples
#'
add_report <- function(name, template = "inrae", path = ".") {
if (!dir.exists(file.path(path, "reports"))) {
add_report <- function(name, template = "inrae", path = pkgload::pkg_path()) {
if (!all(dir.exists(file.path(path, c("reports", "templates"))))) {
stop("Report structure not found, call `create_reports` first!")
}
if (!dir.exists(file.path(path, "templates", template))) {
stop("Template\"", template, "\" not found in ", file.path(path, "templates"))
}
destpath <- file.path(path, "reports", name)
if (dir.exists(destpath))
stop("The folder ",
......
......@@ -4,7 +4,7 @@
\alias{add_report}
\title{Add a new report in a fairify project}
\usage{
add_report(name, template = "inrae", path = ".")
add_report(name, template = "inrae", path = pkgload::pkg_path())
}
\arguments{
\item{name}{Name of the report (sub-folder name in "reports")}
......
......@@ -2,6 +2,15 @@ test_that("add_report should raise error if reports does not exists", {
path <- tempfile(pattern = "dir")
dir.create(path, recursive = TRUE)
expect_error(add_report("test", path = path))
unlink(path, recursive = TRUE)
})
test_that("add_report should raise error if template does not exists", {
path <- tempfile(pattern = "dir")
dir.create(path, recursive = TRUE)
create_reports(path)
expect_error(add_report("test", template = "wrong_template", path = path))
unlink(path, recursive = TRUE)
})
test_that("add_report should create a report", {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment