zig/test/cases
Alex Rønne Petersen 2e3fac3626
test: rename backend=stage2 to backend=selfhosted, and add backend=auto
backend=auto (now the default if backend is omitted) means to let the compiler
pick whatever backend it wants as the default. This is important for platforms
where we don't yet have a self-hosted backend, such as loongarch64.

Also purge a bunch of redundant target=native.
2025-09-16 23:39:26 +02:00
..
compile_errors test: rename backend=stage2 to backend=selfhosted, and add backend=auto 2025-09-16 23:39:26 +02:00
llvm test: rename backend=stage2 to backend=selfhosted, and add backend=auto 2025-09-16 23:39:26 +02:00
run_translated_c translate-c: fix referencing extern locals from nested blocks 2025-03-31 20:22:03 +03:00
safety test: rename backend=stage2 to backend=selfhosted, and add backend=auto 2025-09-16 23:39:26 +02:00
translate_c translate-c: fix callconv attribute in macro 2025-05-07 16:15:51 +03:00
address_of_extern_var_as_const.zig test: rename backend=stage2 to backend=selfhosted, and add backend=auto 2025-09-16 23:39:26 +02:00
ambiguous_reference.zig
array_in_anon_struct.zig test: rename backend=stage2 to backend=selfhosted, and add backend=auto 2025-09-16 23:39:26 +02:00
compile_error.zig
comptime_aggregate_print.zig compiler: improve "... contains reference to comptime var" errors 2025-01-11 08:54:47 +00:00
decl_value_arena.zig
error_in_nested_declaration.zig test: rename backend=stage2 to backend=selfhosted, and add backend=auto 2025-09-16 23:39:26 +02:00
exit.zig
export_from_body_of_coerced_fn.zig frontend: fix reference tracking through coerced function bodies 2025-09-15 11:29:31 +01:00
f32_passed_to_variadic_fn.zig test: rename backend=stage2 to backend=selfhosted, and add backend=auto 2025-09-16 23:39:26 +02:00
float_mode_optimized_reduce.zig test: rename backend=stage2 to backend=selfhosted, and add backend=auto 2025-09-16 23:39:26 +02:00
fn_typeinfo_passed_to_comptime_fn.zig test: rename backend=stage2 to backend=selfhosted, and add backend=auto 2025-09-16 23:39:26 +02:00
function_pointers.zig
function_redeclaration.zig compiler: allow files with AstGen errors to undergo semantic analysis 2024-12-05 19:58:38 +00:00
global_variable_redeclaration.zig
inherit_want_safety.zig test: Set emit_bin=false for some safety tests. 2024-11-24 22:11:17 +01:00
inner_func_accessing_outer_var.zig
large_add_function.zig test: rename backend=stage2 to backend=selfhosted, and add backend=auto 2025-09-16 23:39:26 +02:00
maximum_sized_integer_literal.zig test: rename backend=stage2 to backend=selfhosted, and add backend=auto 2025-09-16 23:39:26 +02:00
no_compile_panic_for_unchecked_arith.zig test: Set emit_bin=false for some safety tests. 2024-11-24 22:11:17 +01:00
non_leaf_functions.zig
passing_u0_to_function.zig
pic_freestanding.zig test: rename backend=stage2 to backend=selfhosted, and add backend=auto 2025-09-16 23:39:26 +02:00
pic_linux.zig test: rename backend=stage2 to backend=selfhosted, and add backend=auto 2025-09-16 23:39:26 +02:00
pie_freestanding.zig
pie_linux.zig
print_u32s.zig
README.md test: rename backend=stage2 to backend=selfhosted, and add backend=auto 2025-09-16 23:39:26 +02:00
recursive_fibonacci.zig
returning_undefined_sentinel_terminated_const_u8_slice.zig test: rename backend=stage2 to backend=selfhosted, and add backend=auto 2025-09-16 23:39:26 +02:00
returns_in_try.zig
runtime_bitwise_and.zig
runtime_bitwise_or.zig
save_function_return_values_in_callee_preserved_register.zig
setting_an_address_space_on_a_local_variable.zig
spirv_mergable_pointers.zig test: rename backend=stage2 to backend=selfhosted, and add backend=auto 2025-09-16 23:39:26 +02:00
tail_call_noreturn.zig
taking_pointer_of_global_tagged_union.zig test: rename backend=stage2 to backend=selfhosted, and add backend=auto 2025-09-16 23:39:26 +02:00
try_in_comptime_in_struct_in_test.zig
type_names.zig test: Restore and fix deleted tests that relied on intern pool types (#24422) 2025-07-17 22:07:50 +00:00
union_unresolved_layout.zig test: rename backend=stage2 to backend=selfhosted, and add backend=auto 2025-09-16 23:39:26 +02:00
unused_vars.zig compiler: allow files with AstGen errors to undergo semantic analysis 2024-12-05 19:58:38 +00: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

Translate-c

If you want to test translating C code to Zig use translate-c:

// translate-c
// c_frontend=aro,clang
// target=x86_64-linux
//
// pub const foo = 1;
// pub const immediately_after_foo = 2;
//
// pub const somewhere_else_in_the_file = 3:

Run Translated C

If you want to test translating C code to Zig and then executing it use run-translated-c:

// run-translated-c
// c_frontend=aro,clang
// target=x86_64-linux
//
// Hello world!

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.
  • stage1: equivalent to -fstage1.
  • selfhosted: equivalent to passing -fno-llvm -fno-lld.
  • llvm: equivalent to -fllvm.