You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+12-3Lines changed: 12 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -30,14 +30,23 @@ Language Server Protocol (LSP) implementation targeting Avrae-style draconic ali
30
30
- Tests only (with coverage): `make test` or `uv run pytest tests --cov=src`.
31
31
- CLI smoke test without installing: `uv run python -m avrae_ls --analyze path/to/alias.txt`.
32
32
33
-
## Alias tests
33
+
## Alias and gvar tests
34
34
35
-
- Create files ending with `.alias-test` (or `.aliastest`) next to your alias file. Each test starts with an invocation, followed by `---` and the expected result; you can stack multiple tests in one file by repeating this pattern (optional metadata after a second `---` per test).
35
+
-`avrae-ls --run-tests [path]` discovers both alias tests and gvar tests and exits non-zero on failures.
36
+
- Alias tests use `.alias-test` or `.aliastest` next to your alias file. Each test starts with an invocation, followed by `---` and the expected result; you can stack multiple tests in one file by repeating this pattern (optional metadata after a second `---` per test).
36
37
```
37
38
!my-alias -b example args
38
39
---
39
40
expected text or number
40
41
```
42
+
- Gvar tests use `.gvar-test` or `.gvartest` next to a sibling `.gvar` file with the same stem. The test body runs after an implicit `using(...)` import of that module under a sanitized local binding name.
43
+
```
44
+
return my_module.constant
45
+
---
46
+
expected value
47
+
```
48
+
- A gvar named `foo-bar.gvar` is exposed to tests as `foo_bar`; a leading digit becomes `gvar_<stem>`.
49
+
- Multi-case `.gvar-test` files are supported. Separate cases with a second `---`, then a blank line before the next test body. Metadata after the second `---` is optional.
41
50
- For embed aliases, put a YAML/JSON dictionary after the separator to compare against the embed preview (partial dictionaries are allowed).
42
51
```
43
52
!embedtest
@@ -57,7 +66,7 @@ Language Server Protocol (LSP) implementation targeting Avrae-style draconic ali
57
66
name: Tester
58
67
```
59
68
`name` is a label for reporting, `vars` are merged into cvars/uvars/svars/gvars, and `character` keys are deep-merged into the mock character.
60
-
-Run them with `avrae-ls --run-tests [path]` (defaults to the current directory); non-zero exit codes indicate failures.
69
+
-Gvar tests compare the direct execution result of the test body, not alias preview/embed output.
Copy file name to clipboardExpand all lines: docs/alias-tests.md
+82-10Lines changed: 82 additions & 10 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,11 +1,11 @@
1
-
# Alias tests
1
+
# Alias and gvar tests
2
2
3
-
Alias tests let you run a mock alias and compare the result to what you expect. They are small text files that live next to your alias files and can contain many tests per file.
3
+
Alias tests and gvar tests let you run mock Avrae code and compare the result to what you expect. They are small text files that live next to your alias or gvar files.
4
4
5
5
## Quick start
6
6
7
-
1. Create an alias file (for example`greet.alias`).
8
-
2. Create a test file next to it (for example`greet.alias-test`).
7
+
1. Create an alias file such as`greet.alias`, or a gvar module such as `helpers.gvar`.
8
+
2. Create a test file next to it such as`greet.alias-test` or `helpers.gvar-test`.
9
9
3. Run tests:
10
10
11
11
```bash
@@ -14,16 +14,19 @@ avrae-ls --run-tests
14
14
15
15
## File layout and discovery
16
16
17
-
Alias tests are discovered by filename. The runner scans for:
17
+
Tests are discovered by filename. The runner scans for:
18
18
19
19
-`*.alias-test`
20
20
-`*.aliastest`
21
+
-`*.gvar-test`
22
+
-`*.gvartest`
21
23
22
24
You can run tests in a folder or point to a single test file:
23
25
24
26
```bash
25
27
avrae-ls --run-tests .
26
28
avrae-ls --run-tests path/to/greet.alias-test
29
+
avrae-ls --run-tests path/to/helpers.gvar-test
27
30
```
28
31
29
32
Example layout:
@@ -33,6 +36,8 @@ my-aliases/
33
36
.avraels.json
34
37
greet.alias
35
38
greet.alias-test
39
+
helpers.gvar
40
+
helpers.gvar-test
36
41
combat/
37
42
roll.alias
38
43
roll.alias-test
@@ -47,6 +52,14 @@ The test file sits next to the alias file it targets. The test command decides w
47
52
48
53
If you keep aliases and tests side by side, you rarely need to think about this.
49
54
55
+
### How the gvar file is chosen
56
+
57
+
The gvar test file targets a sibling `.gvar` file with the same stem:
58
+
59
+
-`helpers.gvar-test` loads `helpers.gvar`
60
+
-`foo-bar.gvar-test` loads `foo-bar.gvar`
61
+
62
+
50
63
## Test file format
51
64
52
65
Each test has three sections:
@@ -170,17 +183,72 @@ If you just want to make sure the alias runs without error, leave the expected s
170
183
name: "no-output-check"
171
184
```
172
185
186
+
## Gvar test format
187
+
188
+
Each gvar test file contains draconic code that runs after the sibling gvar module is implicitly imported with `using(...)`.
189
+
190
+
```
191
+
return helpers.constant
192
+
---
193
+
"Constant Gvar value"
194
+
```
195
+
196
+
- The sibling `.gvar` stem becomes the imported gvar id.
197
+
- The local binding uses the sanitized form of that stem.
198
+
`foo-bar.gvar` becomes `foo_bar`
199
+
`123mod.gvar` becomes `gvar_123mod`
200
+
- Gvar tests compare the direct execution result of the test body.
201
+
202
+
### Multiple gvar tests per file
203
+
204
+
Use the same repeated block layout, but because there is no `!command` sentinel, include a second `---` before the blank line that separates cases.
205
+
206
+
```
207
+
return helpers.constant
208
+
---
209
+
"one"
210
+
---
211
+
212
+
return helpers.other
213
+
---
214
+
"two"
215
+
```
216
+
217
+
- Metadata after the second `---` is optional.
218
+
- Leave a blank line between cases.
219
+
220
+
### Gvar metadata
221
+
222
+
Gvar tests support the same metadata mapping as alias tests:
223
+
224
+
-`name`
225
+
-`vars`
226
+
-`character`
227
+
228
+
```
229
+
return helpers.answer + get('bonus')
230
+
---
231
+
12
232
+
---
233
+
name: "adds-bonus"
234
+
vars:
235
+
cvars:
236
+
bonus: 7
237
+
```
238
+
173
239
## Common tips
174
240
175
241
- Expected output cannot include a line that starts with `!` because that marks the next test. If you need to check a `!` line, use a single-line string like `"line1\n!line2"` or a regex like `re:^!`.
176
242
- If you want a number treated as text, wrap it in quotes (YAML reads bare numbers as numbers).
177
243
- The mock context comes from `.avraels.json` and any var files you configure there (including gvar `{ filePath: ... }` entries). Metadata `vars` and `character` values are merged on top of those defaults for the test only.
178
244
- Each test runs independently, so one test does not affect another.
179
-
- The expected section is compared against the alias result or embed preview, not against stdout. Stdout is shown in the test report to help debug.
245
+
- Alias tests compare against the alias result or embed preview, not stdout.
246
+
- Gvar tests compare against the direct test-body result, not stdout.
247
+
- Stdout is still shown in the test report to help debug.
180
248
181
249
## GitHub Actions
182
250
183
-
This repo ships a composite action that installs `avrae-ls` and runs alias tests.
251
+
This repo ships a composite action that installs `avrae-ls` and runs alias and gvar tests.
184
252
185
253
1. Create a minimal config file for CI (for example `.github/avrae/ci.avraels.json`):
186
254
@@ -196,7 +264,7 @@ This repo ships a composite action that installs `avrae-ls` and runs alias tests
196
264
2. Add a workflow that uses the action:
197
265
198
266
```yaml
199
-
name: Alias Tests
267
+
name: Alias And Gvar Tests
200
268
201
269
on:
202
270
pull_request:
@@ -224,22 +292,26 @@ Use the file path:
224
292
225
293
```bash
226
294
avrae-ls --run-tests path/to/greet.alias-test
295
+
avrae-ls --run-tests path/to/helpers.gvar-test
227
296
```
228
297
229
298
**Can I put many tests in one file?**
230
-
Yes. Repeat the `command`, `---`, and `expected` blocks as many times as you want.
299
+
Yes. Alias tests can repeat the `command`, `---`, and `expected` blocks. Gvar tests can repeat `body`, `---`, and `expected`, but multi-case gvar files should include the second `---` and a blank line between cases.
231
300
232
301
**What if I do not care about the output, only that it runs?**
233
302
Leave the expected section empty (see "Run-only tests"). That will pass as long as the alias runs without errors.
234
303
235
304
**How does it find the alias file?**
236
305
It looks in the same folder as the test file for the alias name in your command (for example `!greet` matches `greet`, `greet.alias`, or `greet.txt`). If your test file is named `test-greet.alias-test`, it will also try `greet`.
237
306
307
+
**How does it find the gvar file?**
308
+
It loads the sibling `.gvar` file with the same stem as the `.gvar-test` file.
309
+
238
310
**Can I use JSON instead of YAML?**
239
311
Yes. JSON is valid YAML, so JSON objects and lists work in the expected and metadata sections.
240
312
241
313
**Why is a gvar missing or `using(...)` failing?**
242
-
Make sure `.avraels.json` enables gvar fetch and sets a token, or provide the gvar in your var files (inline or with `{ filePath: ... }`) or test metadata under `vars.gvars`.
314
+
Make sure `.avraels.json` enables gvar fetch and sets a token, or provide the dependency gvar in your var files (inline or with `{ filePath: ... }`) or test metadata under `vars.gvars`. The module under test itself comes from the sibling `.gvar` file.
243
315
244
316
**How do I ignore gvar fetch failures in CLI runs?**
245
317
Use `avrae-ls --run-tests --silent-gvar-fetch` to treat remote gvar fetch failures as `None` without warnings.
0 commit comments