Skip to content

Commit

Permalink
tests: switch from cargo-watch to watchexec-cli and improve `just…
Browse files Browse the repository at this point in the history
… watch`
  • Loading branch information
laniakea64 committed Oct 6, 2024
1 parent f08fa6b commit 0bc0868
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 12 deletions.
4 changes: 2 additions & 2 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ is a simple test-runner in the `main` fn.
* Rust ([simple/recommended installation instructions](https://www.rust-lang.org/tools/install); for detailed and alternative installation instructions see [here](https://forge.rust-lang.org/infra/other-installation-methods.html))

Run `just deps` to install the cargo dev dependencies, which right now is only
[`cargo-watch`](https://crates.io/crates/cargo-watch).
[`Watchexec CLI`](https://crates.io/crates/watchexec-cli).

### Running the tests

Expand Down Expand Up @@ -80,7 +80,7 @@ To run the filetype detection tests, run `just ftdetect` in tests/.
If you're going to do more than a simple change, I recommend calling `just watch` in tests/,
which will watch for any changes in the whole repo and re-run the test suite.
By default, it will run the syntax highlighting tests.
`just watch` accepts up to two parameters to customize which tests to watch:
`just watch` accepts positional parameters to customize which tests to watch:

```bash
# watch all syntax highlighting tests (default)
Expand Down
19 changes: 9 additions & 10 deletions tests/justfile
Original file line number Diff line number Diff line change
Expand Up @@ -14,25 +14,24 @@ cases_invalid_justfiles := """
run FILTER='':
cargo run {{ if FILTER == '' { '' } else { '-- ' + quote(FILTER) } }}

watchwatch := '`just watch watch` is redundant'

# run tests whenever a file changes
watch RECIPE='run' FILTER='': build
cargo watch \
[positional-arguments]
watch *args:
{{if args =~ '(?:^|\s)watch(?:\s|$)' { error('`just watch watch` is redundant') } else { '' } }}
watchexec \
--clear \
--shell "{{quote(just_executable())}} \
{{if RECIPE == 'watch' { error(watchwatch) } else { quote(RECIPE) } }} \
{{if RECIPE + FILTER =~ 'watch' { error(watchwatch) } else if FILTER == '' { '' } else { quote(FILTER) } }} \
" \
--watch ..
--shell=none \
--project-origin .. \
--watch .. \
{{quote(just_executable())}} "$@"

# run ftdetect tests
ftdetect:
cargo run --bin=test-ftdetect

# install development dependencies
deps:
cargo install --locked cargo-watch
cargo install watchexec-cli

# compile test runner without running tests
build:
Expand Down

0 comments on commit 0bc0868

Please sign in to comment.