| 1 | # Test Case Quick Reference |
| 2 | |
| 3 | Use comments at the **end of the file** to indicate metadata about the test |
| 4 | case. Here are examples of different kinds of tests: |
| 5 | |
| 6 | ## Compile Error Test |
| 7 | |
| 8 | If 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 | |
| 19 | This will do `zig run` on the code and expect exit code 0. |
| 20 | |
| 21 | ```zig |
| 22 | // run |
| 23 | ``` |
| 24 | |
| 25 | ## Incremental Compilation |
| 26 | |
| 27 | Make multiple files that have ".", and then an integer, before the ".zig" |
| 28 | extension, like this: |
| 29 | |
| 30 | ``` |
| 31 | hello.0.zig |
| 32 | hello.1.zig |
| 33 | hello.2.zig |
| 34 | ``` |
| 35 | |
| 36 | Each file can be a different kind of test, such as expecting compile errors, |
| 37 | or expecting to be run and exit(0). The test harness will use these to simulate |
| 38 | incremental compilation. |
| 39 | |
| 40 | At the time of writing there is no way to specify multiple files being changed |
| 41 | as part of an update. |
| 42 | |
| 43 | ## Subdirectories |
| 44 | |
| 45 | Subdirectories do not have any semantic meaning but they can be used for |
| 46 | organization since the test harness will recurse into them. The full directory |
| 47 | path 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 | |
| 57 | Possible 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`. |