Skip to content

Commit

Permalink
test: add test for exotic corner cases of guess_where_config()
Browse files Browse the repository at this point in the history
- test that config file can be found if
   - we end up inside "inst/" (a corner case not tested before)
   - guess_where_config() is fed with argument values for 'path' and 'file' that do not work

-> improves code coverage to 70.75%
  • Loading branch information
ilyaZar committed Aug 3, 2023
1 parent a941ec1 commit 095bfc5
Showing 1 changed file with 50 additions and 0 deletions.
50 changes: 50 additions & 0 deletions tests/testthat/test-config.R
Original file line number Diff line number Diff line change
Expand Up @@ -165,4 +165,54 @@ test_that("golem-config.yml can be renamed and moved to another location", {
# V.B test that default sub-function fails to return path and gives NULL
file.remove("R/app_config.R")
expect_null(try_user_config_location(pkg_path()))

# Cleanup
unlink(path_dummy_golem, TRUE, TRUE)
})

test_that("golem-config.yml can be retrieved for some exotic corner cases", {

path_dummy_golem <- tempfile(pattern = "dummygolem")
create_golem(
path = path_dummy_golem,
open = FALSE
)

old_wd <- setwd(path_dummy_golem)
on.exit(setwd(old_wd))

# 0. The default config path is returned
expect_equal(
guess_where_config(),
fs_path_abs(file.path(
path_dummy_golem,
"inst/golem-config.yml"
))
)

# Test exotic case IV.A - for some reason wd is set to subdir "inst/"
# Change dir to subdir "inst"
setwd(file.path(getwd(), "inst"))
# Test that the default config path is returned
expect_equal(
guess_where_config(),
fs_path_abs(file.path(
path_dummy_golem,
"inst/golem-config.yml"
))
)

# Test exotic case IV.B - for some reason wd is set to subdir "inst/"
# Change dir to golem-pkg toplevel
setwd(path_dummy_golem)
# The default config path is returned though arguments are non-sense
expect_equal(
guess_where_config("hi", "there"),
fs_path_abs(file.path(
path_dummy_golem,
"inst/golem-config.yml"
))
)
# Cleanup
unlink(path_dummy_golem, TRUE, TRUE)
})

0 comments on commit 095bfc5

Please sign in to comment.