Skip to content

Commit

Permalink
Merge branch 'develop' into release_0.4.0
Browse files Browse the repository at this point in the history
  • Loading branch information
thebioengineer committed Nov 2, 2021
2 parents 7e4f250 + 8cb4b0c commit 5282766
Show file tree
Hide file tree
Showing 2 changed files with 92 additions and 2 deletions.
14 changes: 12 additions & 2 deletions R/file_and_path_utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,18 @@ vt_path <- function(...){
#'
#' @export
vt_find_config <- function(){

root <- find_root(has_file(".here") | is_rstudio_project | is_r_package | is_vcs_root)

tryCatch({
root <- find_root(has_file(".here") | is_rstudio_project | is_r_package | is_vcs_root)
}, error = function(e){
abort(
paste0(
"Could not find root directory. ",
"Is your working directory inside a package, validation packet, or project?\n"
),
class = "vt.validation_root_missing"
)
})

tryCatch({

Expand Down
80 changes: 80 additions & 0 deletions tests/testthat/test-find_config.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
test_that("Find config when within a package with validation", {

withr::with_tempdir({
quiet <- capture.output({
vt_create_package(
"example.package",
open = FALSE)
})


withr::with_dir(new = "example.package", {
expect_equal(
vt_find_config(),
normalizePath(file.path(getwd(), "vignettes","validation","validation.yml"),winslash = "/")
)
})
})
})

test_that("Find config when within a package with validation when working dir is non-standard", {

withr::with_tempdir({
quiet <- capture.output({
vt_create_package(
"example.package",
working_dir = "inst",
open = FALSE)
})


withr::with_dir(new = "example.package", {
expect_equal(
vt_find_config(),
normalizePath(
file.path(getwd(), "inst","validation","validation.yml"),
winslash = "/")
)
})
})
})

test_that("Find config when within a validation packet", {

withr::with_tempdir({
quiet <- capture.output({
vt_create_packet("example_packet",
target = "example.package",
open = FALSE)
})


withr::with_dir(new = "example_packet", {
expect_equal(
vt_find_config(),
normalizePath(
file.path(getwd(), "validation","validation.yml"),
winslash = "/")
)
})

})

})


test_that("Informative error when outside a packet or package", {

withr::with_tempdir({

expect_error(
vt_find_config(),
paste0(
"Could not find root directory. ",
"Is your working directory inside a package, validation packet, or project?\n"
),
fixed = TRUE)
})

})

0 comments on commit 5282766

Please sign in to comment.