Skip to content

Commit

Permalink
Merge pull request #68 from NoahTheDuke/watch
Browse files Browse the repository at this point in the history
tests: improve `just watch`
  • Loading branch information
laniakea64 authored Jan 12, 2024
2 parents c2c785b + a20e2a3 commit e955341
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 9 deletions.
58 changes: 52 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,55 @@ Run `just deps` to install the cargo dev dependencies, which right now is only

### Test Suite

To run the tests, run `just run` in tests/. Cargo will build and run the project, which
is a simple test-runner in the `main` fn. 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. If you want to only run or watch a single test file, you
can specify the name by passing an argument to `run` or `watch`: `just run
recipe-dependency`.
`vim-just` includes automated tests of its syntax highlighting and filetype detection.
Running the tests invokes Cargo to build and run the project, which
is a simple test-runner in the `main` fn.

To run the syntax highlighting tests, run `just run` in tests/.
If you want to run only a subset of the syntax highlighting tests,
you can pass an optional regex parameter to `just run` matching the filenames you want to include:

```bash
# run only the 'kitchen-sink.just' syntax highlighting test
$ just run kitchen-sink
...
test kitchen-sink…
ok

# run the syntax highlighting tests with base filenames matching the regex ^\w+$
$ just run '^\w+$'
...
test comment…
ok
test deprecated_obsolete…
ok
test invalid…
ok
test set…
ok
test tricky…
ok
```

Note that the `.just` extension is trimmed off before matching against the regex.

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:

```bash
# watch all syntax highlighting tests (default)
$ just watch

# watch ftdetect tests
$ just watch ftdetect

# watch all tests
$ just watch ftdetect run

# watch syntax highlighting tests with filenames matching the regex ^r.*s$
$ just watch run '^r.*s$'
```
10 changes: 7 additions & 3 deletions tests/justfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,16 @@ set fallback
run FILTER='':
cargo run {{ if FILTER == '' { '' } else { '-- ' + quote(FILTER) } }}

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

# run tests whenever a file changes
watch FILTER='':
watch RECIPE='run' FILTER='': build
cargo watch \
--clear \
--debug \
--exec "run {{FILTER}}" \
--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 ..

# run ftdetect tests
Expand Down

0 comments on commit e955341

Please sign in to comment.