zig-testing
Skill4 starsChanged 4 months agoApache-2.0View on GitHub
Testing in Zig including test blocks, assertions, memory leak detection, doctests, and fuzz testing. Use when writing or running tests for Zig code.
1 other project uses a version of this.
Adopted by
Most recently taken up by
- mohitmishra786/low-level-dev-skillstheir own version, first seen Nov 15, 2026
Other versions1 project uses a version of this.
Word for word · 0
None found.
Edited · 0
None found.
Wrote their own version · 1
- mohitmishra786/low-level-dev-skills★ 290same name
How matches are found. Word for word: the exact same text. Edited: shares passages with this file (“99% same” means 99% of its five-word phrases also appear here; 10% or more counts). Their own version: similar meaning, or, weakest, the same name. We can’t tell which project had it first. Projects are counted among the 200 most-starred candidates, and mentions are links to the repository we found, up to 50 per site, so both counts are a floor.
In this repository80 other files it gives its agents.
- a11y-accessibility-designSkill
- agentic-ui-patternsSkill
- ai-native-ui-designSkill
- ai-ui-anti-patternsSkill
- ai-ui-heuristicsSkill
- calm-technology-uiSkill
- conversion-growth-designSkill
- cross-platform-designSkill
- dark-mode-designSkill
- data-visualizationSkill
- design-systemsSkill
- design-thinking-processSkill
- error-empty-statesSkill
- ethical-design-patternsSkill
- form-uxSkill
- information-architectureSkill
- interaction-design-patternsSkill
- internationalization-uiSkill
- mobile-touch-designSkill
- modal-classes-lifecycleSkill
- modal-container-imagesSkill
- modal-dicts-queuesSkill
- modal-endpointsSkill
- modal-fundamentalsSkill
- modal-gpu-computeSkill
- modal-networkingSkill
- modal-observabilitySkill
- modal-parallel-executionSkill
- modal-sandboxesSkill
- modal-scaling-performanceSkill
- modal-schedulingSkill
- modal-secretsSkill
- modal-serversSkill
- modal-storageSkill
- modal-web-servingSkill
- modal-workspace-adminSkill
- motion-design-principlesSkill
- notifications-permissionsSkill
- onboarding-uxSkill
- rust-api-designSkill
- rust-async-programmingSkill
- rust-cargo-masterySkill
- rust-cli-applicationsSkill
- rust-clippy-lintsSkill
- rust-closures-iteratorsSkill
- rust-compiler-internalsSkill
- rust-concurrencySkill
- rust-design-patternsSkill
- rust-editionsSkill
- rust-embeddedSkill
- rust-error-handlingSkill
- rust-game-developmentSkill
- rust-lifetimes-borrowingSkill
- rust-macrosSkill
- rust-performanceSkill
- rust-rustdocSkill
- rust-rustup-toolchainSkill
- rust-smart-pointersSkill
- rust-testing-benchmarkingSkill
- rust-type-systemSkill
- The first 60 shown.
The file
We split this skill into the rules it gives an agent
5 rules. About 0 are common, 1 is distinctive, and 4 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈1
Distinctive · estimate
This author's own choices. Worth a look.
4
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 8
Use this skill when writing tests, configuring test runners, or leveraging Zig's built-in testing infrastructure.
- Very specific: line 195
Always use std.testing.allocator when a test allocates — catch leaks early
- Very specific: line 197
Put tests next to the code under test.
- Very specific: line 198
Treat --fuzz as experimental.
- Very specific: line 199
Prefer expectEqual(expected, actual) argument order
≈ “Common” is an estimate: at least 1 in 5 of the 350,495 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Zig Testing
Use this skill when writing tests, configuring test runners, or leveraging Zig's built-in testing infrastructure.
When to Use This Skill
- Writing unit tests with
testblocks - Using the testing allocator for leak detection
- Writing doc tests (doctests)
- Running tests with
zig testorzig build test - Fuzz testing
- Skipping or filtering tests
- Detecting memory leaks
Test Declarations
const std = @import("std");
const expect = std.testing.expect;
const expectEqual = std.testing.expectEqual;
test "addition works" {
try expectEqual(4, add(2, 2));
}
test "handles zero" {
try expectEqual(0, add(0, 0));
}
fn add(a: i32, b: i32) i32 {
return a + b;
}Run with:
zig test src/lib.zig
# or via build system:
zig build testTesting Assertions
const testing = std.testing;
test "assertion examples" {
try testing.expect(true); // assert truthy
try testing.expectEqual(42, getValue()); // equal
try testing.expectEqualSlices(u8, "hello", slice); // slice equal
try testing.expectEqualStrings("abc", str); // string equal
try testing.expectError(error.BadInput, failingFn()); // expect error
try testing.expectApproxEqAbs(3.14, pi, 0.01); // float approx
}Memory Leak Detection
std.testing.allocator fails the test if any allocation is not freed:
test "no memory leaks" {
const allocator = std.testing.allocator;
const list = try allocator.alloc(u8, 100);
defer allocator.free(list);
// If you forget `defer allocator.free(list)`, the test fails with:
// "Test leaked memory"
}Doc Tests
Tests in doc comments are run with zig test:
/// Computes the absolute value.
///
/// ```
/// const result = abs(-5);
/// try std.testing.expectEqual(5, result);
/// ```
pub fn abs(x: i32) i32 {
return if (x < 0) -x else x;
}Test Failure
test "demonstrating failure" {
// Explicit failure
if (condition) return error.TestUnexpectedResult;
// Or using std.testing
if (!valid) {
std.debug.print("state was: {}\n", .{state});
return error.TestExpectedEqual;
}
}Skipping Tests
test "requires network" {
if (!networkAvailable()) return error.SkipZigTest;
// ... test body
}Skipped tests are reported separately in output.
Fuzz Testing
Built-in fuzzing exists but is experimental in 0.15.x:
test "fuzz parser" {
const input = std.testing.fuzzInput(.{});
// Verify invariants — errors on bad input are OK
_ = parse(input) catch {};
}zig build test --fuzz
# or: zig test src/parser.zig --fuzzSee references/fuzz-testing.md for callback-style std.testing.fuzz and promotion tips.
Build System Testing
// build.zig
const tests = b.addTest(.{
.root_module = b.createModule(.{
.root_source_file = b.path("src/lib.zig"),
.target = b.graph.host,
}),
});
const run_tests = b.addRunArtifact(tests);
run_tests.has_side_effects = true; // always run, don't cache
const test_step = b.step("test", "Run unit tests");
test_step.dependOn(&run_tests.step);Test Organization
Tests can be in any file. Convention:
// src/parser.zig
pub fn parse(input: []const u8) !AST {
// implementation
}
// Tests at bottom of same file
test "parse empty input" {
const result = parse("");
try std.testing.expectError(error.EmptyInput, result);
}
test "parse valid expression" {
const ast = try parse("1 + 2");
try std.testing.expectEqual(.add, ast.root.op);
}Test Filtering
# Run only tests matching a substring
zig test src/lib.zig --test-filter "parse"Reference Map
references/test-patterns.md— table-driven, errors, threads, snapshotsreferences/expect-and-allocators.md— expect helpers, testing allocator, ArrayListreferences/fuzz-testing.md—fuzzInput/fuzz,--fuzz, caveats
Guardrails
- Always use
std.testing.allocatorwhen a test allocates — catch leaks early - On 0.15+,
ArrayListis unmanaged:.empty, pass allocator toappend/deinit - Put tests next to the code under test; use
--test-filterfor focus - Treat
--fuzzas experimental; promote failing inputs to ordinary unit tests - Prefer
expectEqual(expected, actual)argument order
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

