Files
zig/test/cases
Justus Klausecker 6d0b887972 Sema: disallow pointer cast from pointer to opaque type to slice
Fixes a regression where this conversion crashes. When the conversion was
still possible it would produce a slice with a length of zero, which doesn't
really make a lot of sense either. There's no way to determine the length
of the destination slice from a pointer to an opaque type, so it's a compile
error now. Users should just cast to a many-item pointer and slice to the
desired length manually instead.
2026-05-07 06:25:43 +02:00
..
2024-09-26 21:02:14 -07:00
2025-09-24 20:01:17 -07:00

Test Case Quick Reference

Use comments at the end of the file to indicate metadata about the test case. Here are examples of different kinds of tests:

Compile Error Test

If you want it to be run with zig test and match expected error messages:

// error
// is_test=true
//
// :4:13: error: 'try' outside function scope

Execution

This will do zig run on the code and expect exit code 0.

// run

Incremental Compilation

Make multiple files that have ".", and then an integer, before the ".zig" extension, like this:

hello.0.zig
hello.1.zig
hello.2.zig

Each file can be a different kind of test, such as expecting compile errors, or expecting to be run and exit(0). The test harness will use these to simulate incremental compilation.

At the time of writing there is no way to specify multiple files being changed as part of an update.

Subdirectories

Subdirectories do not have any semantic meaning but they can be used for organization since the test harness will recurse into them. The full directory path will be prepended as a prefix on the test case name.

Limiting which Backends and Targets are Tested

// run
// backend=selfhosted,llvm
// target=x86_64-linux,x86_64-macos

Possible backends are:

  • auto: the default; compiler picks the backend based on robustness.
  • selfhosted: equivalent to passing -fno-llvm -fno-lld.
  • llvm: equivalent to -fllvm.