Skip to content

Commit

Permalink
Test dir_state and script install
Browse files Browse the repository at this point in the history
  • Loading branch information
ElianHugh committed Jun 17, 2024
1 parent 0ec377f commit 4677320
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 11 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -47,3 +47,6 @@ po/*~

# RStudio Connect folder
rsconnect/

# debug files
.fuse_hidden*
3 changes: 2 additions & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion R/errors.R
Original file line number Diff line number Diff line change
Expand Up @@ -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")
)
Expand Down
21 changes: 12 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,20 +1,23 @@
# hotwater

<!-- badges: start -->
[![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)
<!-- badges: end -->

~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")
Expand All @@ -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...
```
16 changes: 16 additions & 0 deletions tests/testthat/test-script.R
Original file line number Diff line number Diff line change
@@ -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")
)
})
})
14 changes: 14 additions & 0 deletions tests/testthat/test-watcher.R
Original file line number Diff line number Diff line change
Expand Up @@ -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"))
})
})

0 comments on commit 4677320

Please sign in to comment.