-
Book Overview & Buying
-
Table Of Contents
Systems Programming with Zig
By :
We are going to create tests for the zwhich command-line tool we created in the previous chapter. But first, we are going to explain the way testing works in Zig.
In Zig, testing is not a secondary concern delegated to external frameworks but is directly integrated into the core of the language. The std.testing namespace provides the essential primitives for verification, allowing you to assert conditions and compare values using functions like expect(), expectEqual(), and expectError(). Instead of maintaining separate directory trees for tests that can easily drift out of sync, Zig encourages you to write test blocks within the same source files as your implementation code. These blocks are strictly compile-time constructs; they are only compiled and run when you explicitly issue the zig test command, ensuring that your production binaries are lean and optimized. We showcase testing by writing tests for zwhich.