forked from ThinkR-open/golem
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* add user supplied `file` for `run_dev()` & make covr. 100% for `run_dev.R` (ThinkR-open#1050) * fix: user supplied 'file'-argument works correctly - use path constructed from 'file' argument instead of hard code "dev/run_dev.R" - improve error message on failure Refs: ThinkR-open#886 * tests: improve test-covr. of run_dev.R form 0% to 100% - add test for default 'file' argument - add test for user supplied 'file' argument where - run_dev.R renamed to run_dev2.R - path to run_dev changed to top-level golem path - add test for error if run_dev cannot find the 'file' * docs: update docs for run_dev - give a bit more context on usage - fix some typos - use markdown highlighting consistently - add invisible return as this is a pure side-effect function * core update README --------- Co-authored-by: Ilya Zarubin <[email protected]>
- Loading branch information
1 parent
7ba820b
commit 65d3d29
Showing
4 changed files
with
89 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
path_dummy_golem <- tempfile(pattern = "dummygolem") | ||
create_golem( | ||
path = path_dummy_golem, | ||
open = FALSE | ||
) | ||
test_that("run_dev() works for different files and fails if missing", { | ||
with_dir( | ||
path_dummy_golem, | ||
{ | ||
# Adjust file for testing run_dev() with default file="dev/run_dev.R" | ||
run_dev_update <- readLines("dev/run_dev.R") | ||
# suppress other behavior of run_dev that is not meant for testing | ||
run_dev_update[2] <- "# options(golem.app.prod = FALSE)" | ||
run_dev_update[6] <- "# options(shiny.port = httpuv::randomPort())" | ||
run_dev_update[8] <- "# golem::detach_all_attached()" | ||
run_dev_update[12] <- "# golem::document_and_reload()" | ||
run_dev_update[15] <- "print('DEFAULT run_dev')" | ||
# write new run_dev.R file for testing | ||
run_dev_update <- writeLines(run_dev_update, "dev/run_dev.R") | ||
# Make a copy of run_dev and move it elsewhere (but inside golem) | ||
file.copy( | ||
from = "dev/run_dev.R", | ||
to = file.path(get_golem_wd(), "run_dev2.R") | ||
) | ||
# Adjust copy for testing run_dev() with user supplied file="run_dev2.R" | ||
run_dev_update <- readLines("run_dev2.R") | ||
run_dev_update[15] <- "print('NEW run_dev2')" | ||
run_dev_update <- writeLines(run_dev_update, "run_dev2.R") | ||
# The default run_dev works | ||
expect_output( | ||
run_dev(), | ||
regexp = "DEFAULT run_dev" | ||
) | ||
# The new run_dev2 works too | ||
expect_output( | ||
run_dev(file = "run_dev2.R"), | ||
regexp = "NEW run_dev2" | ||
) | ||
# A wrong path supplied to 'file' fails with informative error | ||
expect_error( | ||
run_dev(file = "run_dev3.R"), | ||
regexp = "Unable to locate the run_dev-file passed via the 'file' argument." | ||
) | ||
unlink(path_dummy_golem, recursive = TRUE) | ||
} | ||
) | ||
}) |