From 46773209134ca14a0fa4403b4caee2565a670af2 Mon Sep 17 00:00:00 2001 From: "Elian H. Thiele-Evans" <60372411+ElianHugh@users.noreply.github.com> Date: Mon, 17 Jun 2024 13:25:56 +1000 Subject: [PATCH] Test dir_state and script install --- .gitignore | 3 +++ DESCRIPTION | 3 ++- R/errors.R | 2 +- README.md | 21 ++++++++++++--------- tests/testthat/test-script.R | 16 ++++++++++++++++ tests/testthat/test-watcher.R | 14 ++++++++++++++ 6 files changed, 48 insertions(+), 11 deletions(-) create mode 100644 tests/testthat/test-script.R diff --git a/.gitignore b/.gitignore index e75435c..f3efe36 100644 --- a/.gitignore +++ b/.gitignore @@ -47,3 +47,6 @@ po/*~ # RStudio Connect folder rsconnect/ + +# debug files +.fuse_hidden* diff --git a/DESCRIPTION b/DESCRIPTION index de13ada..73c67f6 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -21,7 +21,8 @@ Suggests: docopt, remotes, testthat (>= 3.0.0), - xml2 + xml2, + withr Config/testthat/edition: 3 Encoding: UTF-8 Roxygen: list(markdown = TRUE) diff --git a/R/errors.R b/R/errors.R index 0e91713..b41d6b8 100644 --- a/R/errors.R +++ b/R/errors.R @@ -52,7 +52,7 @@ error_cannot_uninstall <- function(path) { } warning_not_installed <- function(path) { - cli::cli_alert_warning( + cli::cli_warn( "{.pkg hotwater} is not installed at {.path {path}}", class = new_hotwater_warning("not_installed") ) diff --git a/README.md b/README.md index 5b4bc53..710ff46 100644 --- a/README.md +++ b/README.md @@ -1,20 +1,23 @@ # hotwater -[![Codecov test coverage](https://codecov.io/gh/ElianHugh/hotwater/branch/main/graph/badge.svg)](https://app.codecov.io/gh/ElianHugh/hotwater?branch=main) + +[![Codecov test +coverage](https://codecov.io/gh/ElianHugh/hotwater/branch/main/graph/badge.svg)](https://app.codecov.io/gh/ElianHugh/hotwater?branch=main) [![R-CMD-check](https://github.com/ElianHugh/hotwater/actions/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/ElianHugh/hotwater/actions/workflows/R-CMD-check.yaml) -~work in progress~ +*work in progress* -- for plumber development -- autoreload for plumber -- also auto-refreshes the browser when a change is made -- run from the commandline with the `/inst/hotwater` bash script +- for plumber development +- autoreload for plumber +- also auto-refreshes the browser when a change is made +- run from the commandline with the `/exec/hotwater` bash script ## Installation -You can install the development version of hotwater from [GitHub](https://github.com/) with: +You can install the development version of hotwater from +[GitHub](https://github.com/) with: ``` r # install.packages("devtools") @@ -25,14 +28,14 @@ devtools::install_github("ElianHugh/hotwater") This is a basic example which shows you how to solve a common problem: -```r +``` r hotwater::run( system.file("examples", "plumber.R", package = "hotwater"), port = 9999L ) ``` -``` +``` r ✔ Server running on <127.0.0.1:9999> [17ms] → Watching ./path/to/ for changes... ``` diff --git a/tests/testthat/test-script.R b/tests/testthat/test-script.R new file mode 100644 index 0000000..8623866 --- /dev/null +++ b/tests/testthat/test-script.R @@ -0,0 +1,16 @@ +test_that("hotwater install/uninstall works", { + local({ + hw_install_folder <- withr::local_tempdir("install_path") + expect_no_error(install_hotwater(hw_install_folder)) + expect_error( + install_hotwater(hw_install_folder), + class = new_hotwater_error("install") + ) + + expect_no_error(uninstall_hotwater(hw_install_folder)) + expect_warning( + uninstall_hotwater(hw_install_folder), + class = new_hotwater_warning("not_installed") + ) + }) +}) diff --git a/tests/testthat/test-watcher.R b/tests/testthat/test-watcher.R index aeac7c3..27d198d 100644 --- a/tests/testthat/test-watcher.R +++ b/tests/testthat/test-watcher.R @@ -43,3 +43,17 @@ test_that("file watcher works", { sort(changes) ) }) + +# todo, might be worth thinking about if its even worth testing the +# implementation details here +test_that("directory_state returns expected file state", { + local({ + watcher_dir <<- withr::local_tempdir("testdir") + writeLines("Hello world", file.path(watcher_dir, "hello.R")) + writeLines("Bye world", file.path(watcher_dir, "bye.R")) + state <<- directory_state(watcher_dir, "*.gitignore") + expect_length(state, 2L) + expect_length(names(state), 2L) + expect_s3_class(state, c("POSIXct", "POSIXt")) + }) +})