1# Test Case Quick Reference
2
3Use comments at the **end of the file** to indicate metadata about the test
4case. Here are examples of different kinds of tests:
5
6## Compile Error Test
7
8If you want it to be run with `zig test` and match expected error messages:
9
10```zig
11// error
12// is_test=true
13//
14// :4:13: error: 'try' outside function scope
15```
16
17## Execution
18
19This will do `zig run` on the code and expect exit code 0.
20
21```zig
22// run
23```
24
25## Incremental Compilation
26
27Make multiple files that have ".", and then an integer, before the ".zig"
28extension, like this:
29
30```
31hello.0.zig
32hello.1.zig
33hello.2.zig
34```
35
36Each file can be a different kind of test, such as expecting compile errors,
37or expecting to be run and exit(0). The test harness will use these to simulate
38incremental compilation.
39
40At the time of writing there is no way to specify multiple files being changed
41as part of an update.
42
43## Subdirectories
44
45Subdirectories do not have any semantic meaning but they can be used for
46organization since the test harness will recurse into them. The full directory
47path will be prepended as a prefix on the test case name.
48
49## Limiting which Backends and Targets are Tested
50
51```zig
52// run
53// backend=selfhosted,llvm
54// target=x86_64-linux,x86_64-macos
55```
56
57Possible backends are:
58
59 * `auto`: the default; compiler picks the backend based on robustness.
60 * `selfhosted`: equivalent to passing `-fno-llvm -fno-lld`.
61 * `llvm`: equivalent to `-fllvm`.