Skip to content

Commit

Permalink
remove prompt without restart needed (closes #58)
Browse files Browse the repository at this point in the history
  • Loading branch information
simonpcouch committed Nov 7, 2024
1 parent e1e5d36 commit 63bf547
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
5 changes: 3 additions & 2 deletions R/prompt.R
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,9 @@ prompt_remove <- function(role) {
path <- prompt_locate(role)
file.remove(path)

# TODO: this doesn't do enough to remove s.t. a new
# prompt with the same role can be added
pal_env <- pal_env()
rlang::env_unbind(pal_env, paste0(".pal_prompt_", role))
rlang::env_unbind(pal_env, paste0(".pal_rs_", role))

invisible(path)
}
Expand Down
13 changes: 13 additions & 0 deletions tests/testthat/test-prompt.R
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,19 @@ test_that("new prompts error informatively with bad pre-fill contents", {
)
})

test_that("prompts can be added, removed, and added again without restart (#58)", {
skip_if_offline()
# contains two prompts, `boop-replace` and `wop-prefix`
withr::local_options(.pal_dir = "test-prompt-dir")
testthat::local_mocked_bindings(interactive = function(...) {FALSE})
withr::defer(prompt_remove("template"))

path <- prompt_new("template", "prefix")
prompt_remove("template")
prompt_new("template", "prefix")

expect_true(file.exists(path))
})

test_that("is_markdown_file works", {
expect_true(is_markdown_file("some_file.md"))
Expand Down

0 comments on commit 63bf547

Please sign in to comment.