Skip to content

zig_test

Zig test target.

Description

Compiles a Zig test binary with zig test --test-no-exec, then runs that binary through Once's generic test capability. Once writes a normalized test result file with one suite-level case and stores the native Zig test output as a log artifact.

The root can be set with main, or omitted when deps contains exactly one Zig module dependency. Test execution is host-only. Cross-target test binaries can still be built, but running them needs a platform runner outside this target kind.

Canonical module names are generated from target labels with collision-safe escaping. import_names keys must match exactly one Zig module dependency by full label, short label name, import name, or canonical name; ambiguous or unknown keys fail validation.

Attributes

AttributeTypeRequiredDefaultDescription
zigstringnozig on PATHZig compiler path
zig_versionstringnoemptyExpected zig version output
bootstrappedintno-1Compatibility selector for bootstrapped Zig toolchains; choose the compiler with zig
mainstringnoPackage-relative root module, or omit with one Zig module dependency
import_namestringnotarget nameName downstream modules use with @import
import_namesmap<string, string>no{}Rename dependency imports by dependency label, short name, or import name
extra_srcslist<string>no[]Extra source or data globs included in the compile input digest
extra_docslist<string>no[]Extra files included in the documentation action input digest
datalist<string>no[]Runtime data globs included in test run inputs
targetstringnohost targetZig target triple passed with -target
cpustringnoemptyProcessor setting passed with -mcpu
optimizestringnoemptyOptimization mode passed with -O
modestringnoemptyauto, debug, release_safe, release_small, or release_fast; maps to -O
host_modestringnoemptyAlias for mode when porting configured host targets
threadedstringnoemptymulti passes -fno-single-threaded; single passes -fsingle-threaded
host_threadedstringnoemptyAlias for threaded when porting configured host targets
stripboolnofalseAlias for strip_debug_symbols
strip_debug_symbolsboolnofalsePass -fstrip
compiler_runtimestringnodefaultdefault, include, or exclude for compiler runtime flags
zigoptlist<string>no[]Global Zig flags prepended before module-specific zigopts
host_zigoptlist<string>no[]Alias for zigopt when porting configured host targets
zigoptslist<string>no[]Extra flags attached to this module specification
linkoptslist<string>no[]Extra linker flags appended after Once-managed flags
use_cc_common_linkintno-1Compatibility setting for C provider linking; Once consumes C providers through its provider model
host_use_cc_common_linkintno-1Host compatibility setting for C provider linking
use_standalone_translate_cintno-1Set to 1 to use a standalone translate-c executable
translate_cstringnoemptyStandalone translate-c executable path
translate_c_identitystringnoemptyStable identity for the standalone translate-c executable, folded into translate action cache keys
csrcslist<string>no[]C source files passed to Zig through -cflags ... --
coptslist<string>no[]C compiler flags passed after -cflags
linker_scriptstringnoemptyPackage-relative linker script passed as -T
emit_asmboolnofalseEmit assembly output
emit_llvm_irboolnofalseEmit compiler intermediate representation output
emit_llvm_bcboolnofalseEmit compiler bitcode output
output_namestringnotarget nameOutput file name without platform extension
envmap<string, string>no{}Environment variables passed to the Zig test binary
env_inheritlist<string>no[]Host environment variable names inherited before explicit env and test_env values
argslist<string>no[]Arguments passed to the compiled Zig test binary
test_envmap<string, string>no{}Once-compatible alias for extra test execution environment variables
test_runnerstringnoemptyPackage-relative Zig file passed as --test-runner
labelslist<string>no[]Labels exposed through once_test_info for test discovery
timeout_msintnoOptional test timeout in milliseconds

Dependency Edges

EdgeAcceptsDescription
depszig_module, c_providerZig modules and C provider dependencies consumed by the test

Providers

The target emits zig_test and once_test_info.

Capabilities

CapabilityOutput groupsRequires
buildbinary, asm, llvm_ir, llvm_bc, zig_docs
testdefault, test_results, logsbinary

Example

toml
[[target]]
name = "math_tests"
kind = "zig_test"
srcs = ["src/**/*.zig"]

[target.attrs]
main = "src/math_test.zig"
labels = ["unit"]

Released under an open-source license.