aboutsummaryrefslogtreecommitdiff
path: root/TESTING.md
blob: 7178006113720da1a69659a4bf0c56df2f87b5f2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
# Manual Test Cases

Run these against the extension loaded from `Zig.novaextension/` with Nova in
development mode. Each case lists the example project to open (under `examples/`),
the steps to follow, and the expected result.

---

## Setup

Before running any case:

1. Confirm the extension is active: **Nova → Extensions → Extension Library →
   Zig** shows as installed and enabled.
2. Confirm `zig` and `zls` are on `PATH` (or configured in global preferences).
3. Unless stated otherwise, open the project folder directly as a Nova workspace
   (not a single file).

---

## T01 — Activation

**Project:** any `.zig` file or workspace containing one

| Step | Expected |
|---|---|
| Open a `.zig` file cold (no prior Nova session) | Extension Console shows ZLS starting; no error dialogs |
| Check the task list | **Current Zig File** is present |
| Open a workspace with `build.zig` | After a few seconds, **Zig Build: \<step\>** tasks appear |
| Open a folder with no `.zig` files | Extension does not activate; no ZLS process |

---

## T02 — Syntax highlighting

**Project:** `examples/snippets`

Open each file and verify highlighting is applied:

| File | Check |
|---|---|
| `syntax-tour.zig` | Keywords (`fn`, `const`, `pub`), string literals, comments, numeric literals all coloured distinctly |
| `fibonacci.zig` | Function signatures, control flow (`if`, `while`), types (`u64`) highlighted |
| `error-example.zig` | Error set declarations, `try`, `catch` highlighted |
| `examples/zon-examples/full-types.zon` | `.field = value` pairs highlighted; strings and numbers coloured |
| `examples/zon-examples/invalid.zon` | File opens without Nova crashing |

---

## T03 — Code folding

**Project:** `examples/snippets/syntax-tour.zig`

| Step | Expected |
|---|---|
| Click the fold widget next to a `fn` body | Function body collapses |
| Click the fold widget next to a `struct` or `union` | Declaration collapses |
| Click the fold widget next to a `if`/`for`/`while` block | Block collapses |

---

## T04 — ZLS: completion and hover

**Project:** `examples/multi-step` (open workspace root)

| Step | Expected |
|---|---|
| Open `src/main.zig`, type `std.` | Completion popover appears with `std` members |
| Hover over `std.debug.print` | Documentation tooltip appears |
| Place cursor on a symbol and press **⌥F12** (Find References) or use the menu | References panel lists results |
| Place cursor on a function call and press **⌘↓** (Go to Definition) | Navigates to the definition site |
| Save a file with trailing whitespace | File is formatted on save (if Build On Save is off, trigger Format Document manually) |

---

## T05 — ZLS: inline diagnostics

**Project:** `examples/snippets/error-example.zig` (open as a single file)

| Step | Expected |
|---|---|
| Open the file | ZLS highlights the intentional error with a red underline |
| Hover over the underlined region | Error message appears in the tooltip |
| Fix the error and save | Red annotation disappears |

---

## T06 — Auto-discovered tasks: basic

**Project:** `examples/multi-step`

| Step | Expected |
|---|---|
| Open the workspace | Task list eventually contains **Zig Build: install**, **run**, **test**, **check-fmt**, **gen-docs**, **run\_server**, **bench**, **release-macos** |
| Select **Zig Build: run** and press ▶ | `zig build run` executes; output appears in the task report |
| Select **Zig Build: bench** and press ▶ | `zig build bench` executes successfully |
| Select **Zig Build: check-fmt** and press ▶ | Exits cleanly (sources are already formatted) |

---

## T07 — Auto-discovered tasks: cache invalidation

**Project:** `examples/multi-step`

| Step | Expected |
|---|---|
| Note the current discovered step list | Baseline |
| Add a new step to `build.zig` (e.g. a blank `b.step("smoke", "…")`) and save | Within a few seconds the task list updates; **Zig Build: smoke** appears |
| Revert the change and save | **Zig Build: smoke** disappears from the list |

---

## T08 — Auto-discovered tasks: discovery disabled

**Project:** `examples/multi-step`

| Step | Expected |
|---|---|
| Open **Project Settings → Zig → Tasks → Discover Build Steps** and set to Disabled | **Zig Build: \<step\>** tasks all disappear from the list |
| **Current Zig File** task | Still present and functional |
| Re-enable discovery | **Zig Build: \<step\>** tasks reappear |

---

## T09 — Current Zig File: run

**Project:** `examples/snippets/fibonacci.zig` (open as a single file, or with the file active in any workspace)

| Step | Expected |
|---|---|
| Select **Current Zig File** and press ▶ | `zig run fibonacci.zig` executes; program output appears in the task report |
| Switch to a different `.zig` file | The task now targets the new file (name in the task report changes) |

---

## T10 — Current Zig File: clean

**Project:** `examples/multi-step`, open `src/main.zig`

| Step | Expected |
|---|---|
| Ensure `.zig-cache` exists in `examples/multi-step/` (run any build first) | Baseline |
| Select **Current Zig File** and trigger Clean | `.zig-cache` and `zig-out` inside `examples/multi-step/` are removed; no warning dialog |

---

## T11 — Zig Package: build and run

**Project:** `examples/multi-step`, using the pre-configured task in `.nova/Tasks/Zig Package.json` (Run Step = `run`)

| Step | Expected |
|---|---|
| Press ⌘B (Build) | `zig build` runs; exits 0; binary appears in `zig-out/bin/` |
| Press ▶ (Run) | `zig build run` runs; program output appears in task report |
| Set **Optimize** to `ReleaseFast` and press ▶ | Command contains `-Doptimize=ReleaseFast` (visible in task report header or Extension Console) |
| Set **Target** to `aarch64-macos` and press ⌘B | Command contains `-Dtarget=aarch64-macos` |
| Add `verbose` to **User Options** and press ▶ | Command contains `-Dverbose` |
| Add `--verbose` to **Build Arguments** and press ▶ | Command contains `--verbose` after the `-D` flags |
| Add `--help` to **Program Arguments** and press ▶ | `--` separator and `--help` appear after the step name |
| Set **Console** to External Terminal and press ▶ | macOS Terminal opens a new window/tab and runs the program |

---

## T12 — Zig Package: build-options project

**Project:** `examples/build-options`

| Step | Expected |
|---|---|
| Create a **Zig Package** task with **Run Step** blank | ▶ runs `zig build`; program prints using the default option values |
| Add a User Option matching one of the options declared in `build.zig` | Re-run; program output reflects the new value |

---

## T13 — Zig Test: all tests

**Project:** `examples/test-suite`, using one of the pre-configured tasks

| Step | Expected |
|---|---|
| Select **Zig Test (all)** and press ▶ | `zig build test` runs; both math and strings tests pass; no inline errors in editor |
| Select **Zig Test (all)** and press ⌘B | Same command without `--summary` or `--test-filter`; exits 0 |
| Set **Summary** to **All** and press ▶ | Output is more verbose (every step printed) |

---

## T14 — Zig Test: filtered

**Project:** `examples/test-suite`, **Zig Test (math)** task (Test Filter = `math`)

| Step | Expected |
|---|---|
| Press ▶ | Only math tests run; strings tests are skipped |
| Change the filter to a string that matches no test name (e.g. `zzz`) | Task exits 0 but reports 0 tests run |

---

## T15 — Zig Test: inline error annotations

**Project:** `examples/test-suite`

| Step | Expected |
|---|---|
| Introduce a deliberate test failure in `src/math.zig` (e.g. change an expected value) and save | |
| Run **Zig Test (all)** | Task exits non-zero; the failing line in `math.zig` gets a red gutter annotation |
| Click the annotation | Error message is shown |
| Revert the change and re-run | Annotation clears |

---

## T16 — Zig Watch

**Project:** `examples/multi-step`, pre-configured **Zig Watch** task

| Step | Expected |
|---|---|
| Press ⌘B (Build) | `zig build --watch` starts; task report shows initial build output and then idles |
| Edit `src/lib.zig` (e.g. change a return value) and save | Zig detects the change and rebuilds automatically; new output appears in the task report |
| Stop the task | Process terminates cleanly |
| Set **Debounce** to `500` and restart | `--debounce 500` appears in the command |
| Set **Incremental** to **On** and restart | `-fincremental` appears in the command |

---

## T17 — Zig Debug: auto-detection

**Project:** `examples/multi-step` — create a **Zig Debug** task with **Program** blank

| Step | Expected |
|---|---|
| Press ▶ (Run/Debug) | Extension reads `build.zig.zon`, finds `.name = "multi-step"`, probes `zig-out/bin/multi-step` |
| If binary exists (run Build first) | Debugger launches and the program runs under lldb-dap |
| If binary does not exist | Warning dialog asks you to fill in the Program field manually |

---

## T18 — Zig Debug: breakpoints

**Project:** `examples/multi-step` — **Zig Debug** task, **Optimize** = Debug

| Step | Expected |
|---|---|
| Set a breakpoint in `src/main.zig` by clicking the gutter | Red dot appears |
| Press ▶ | Program pauses at the breakpoint; Variables panel shows local state |
| Step over (F10) | Execution advances one line |
| Continue (F5) | Program runs to completion or the next breakpoint |

---

## T19 — Zig Debug: stop on entry

**Project:** `examples/multi-step` — **Zig Debug** task

| Step | Expected |
|---|---|
| Enable **Stop On Entry** | |
| Press ▶ | Debugger pauses at the very first instruction before any user code runs |

---

## T20 — Clean: safety guards

Create a **Zig Package** task in any project and test each guard:

| Scenario | How to trigger | Expected |
|---|---|---|
| Working Directory = `/` | Set the field to `/` | Clean shows a warning and does nothing |
| Working Directory = `$HOME` | Set the field to your home directory | Clean shows a warning and does nothing |
| Working Directory outside workspace | Set an absolute path outside the open folder | Clean shows a warning and does nothing |
| Valid cwd | Normal configuration | `.zig-cache`, `zig-cache`, `zig-out` are removed |

---

## T21 — Clean: zig build uninstall

**Project:** a project whose `build.zig` registers an `uninstall` step (add one temporarily if needed)

| Step | Expected |
|---|---|
| Run Build once to populate the step cache | |
| Trigger Clean | Extension Console shows `zig build uninstall` was called before `rm -rf` |

---

## T22 — Monorepo: sub-package working directory

**Project:** `examples/monorepo` (open workspace root)

| Step | Expected |
|---|---|
| Discover tasks at root | **Zig Build: run**, **test-all**, **gen-docs** appear |
| Create a **Zig Package** task; set **Working Directory** to `packages/alpha` | Build/Run operates on `packages/alpha/build.zig` |
| Create a **Zig Test** task; set **Working Directory** to `packages/beta` | Tests run from `packages/beta/` |

---

## T23 — Inline compiler errors

**Project:** `examples/snippets/error-example.zig` via a **Zig Package** or **Current Zig File** task

| Step | Expected |
|---|---|
| Run the task against a file with a compile error | Error annotation appears at the correct line and column in the editor |
| The annotation text | Matches the `error:` message from the compiler |
| Fix the error and re-run | Annotation clears |

---

## T24 — Settings: custom executable paths

**Scope:** Nova Preferences → Extensions → Zig

| Step | Expected |
|---|---|
| Set **Zig Executable** to an absolute path (e.g. `/usr/local/bin/zig`) | Tasks use that binary instead of PATH discovery |
| Set it to a non-existent path | First task run shows a warning about missing `zig` |
| Clear the field | PATH discovery resumes |

---

## T25 — Settings: workspace overrides global

**Project:** any workspace

| Step | Expected |
|---|---|
| Set a global preference (e.g. Discover Build Steps = disabled) | Workspace inherits; no discovered tasks |
| In Project Settings, set Discover Build Steps to **Enabled** | Discovered tasks reappear for this workspace only |
| Open a different workspace | Still uses the global disabled setting |