diff --git a/tests/testthat/test-config.R b/tests/testthat/test-config.R index fd553276..70ef66aa 100644 --- a/tests/testthat/test-config.R +++ b/tests/testthat/test-config.R @@ -76,3 +76,71 @@ test_that("config works", { ) }) }) +test_that("golem-config.yml can be moved to another location", { + + path_dummy_golem <- tempfile(pattern = "dummygolem") + + golem::create_golem( + path = path_dummy_golem, + open = FALSE + ) + + old_wd <- setwd(path_dummy_golem) + on.exit(setwd(old_wd)) + + # The good config path is returned + expect_equal( + golem:::guess_where_config(), + golem:::fs_path_abs(file.path( + path_dummy_golem, + "inst/golem-config.yml" + )) + ) + # document_and_reload does not throw an error + expect_error( + document_and_reload(), + regexp = NA + ) + expect_equal( + get_golem_name(), + basename(path_dummy_golem) + ) + expect_equal( + get_golem_wd(), + path_dummy_golem + ) + + ## Move config file + dir.create( + "inst/config" + ) + file.copy( + from = "inst/golem-config.yml", + to = "inst/config/golem.yml" + ) + file.remove( + "inst/golem-config.yml" + ) + # User adjusts the correct line in app_config.R: + tmp_app_config_r <- readLines("R/app_config.R") + tmp_app_config_r[36] <- " file = app_sys(\"config/golem.yml\")" + writeLines(tmp_app_config_r, "R/app_config.R") + + # The good config path is returned + expect_equal( + golem:::guess_where_config(), + golem:::fs_path_abs(file.path( + path_dummy_golem, + "inst/config/golem.yml" + )) + ) + # document_and_reload does not throw an error + expect_error( + document_and_reload(), + regexp = NA + ) + expect_equal( + get_golem_name(), + basename(path_dummy_golem) + ) +})