-
Notifications
You must be signed in to change notification settings - Fork 205
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Throw error if
libdir
is not empty but selfcontained = TRUE
Fixes #417 and saves users from accidentally deleting important files by throwing an error when the user provides a `libdir` that contains files. This is only an issue when `selfcontained = TRUE` because otherwise the files written into `libdir` are not removed after saving the widget html.
- Loading branch information
Showing
2 changed files
with
33 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
test_that("saveWidget errors if `selfcontained = TRUE` and `libdir` is not empty", { | ||
tmpdir <- tempfile() | ||
dir.create(tmpdir) | ||
on.exit(unlink(tmpdir, recursive = TRUE), add = TRUE) | ||
|
||
owd <- setwd(tmpdir) | ||
on.exit(setwd(owd), add = TRUE) | ||
|
||
# widget | ||
widget <- widget_html("widgetE", "htmlwidgets", id = "id", style = NULL, class = NULL) | ||
|
||
# Create a libdir with something in it | ||
dir.create("libdir") | ||
writeLines("not empty", file.path("libdir", "not-empty.txt")) | ||
|
||
expect_error( | ||
saveWidget(widget, "widget.html", selfcontained = TRUE, libdir = "libdir") | ||
) | ||
}) |