Back to list
acmiyaguchi

zig-testing

by acmiyaguchi

A small LLM agent in zig

1🍴 0📅 Jan 24, 2026

SKILL.md


name: Zig Testing description: Run zig build/test cycles and fix errors iteratively. Use this skill when you need to build Zig code, run Zig tests, fix compile errors, or write new Zig tests.

Zig Testing Loop

You are running the Zig build and test cycle. Follow these steps EXACTLY.

Step 1: Run Build First

zig build 2>&1

If build succeeds (no output or just warnings): Go to Step 2.

If build fails: Fix the errors shown, then re-run zig build 2>&1. Repeat until it passes.

Step 2: Run Tests

zig build test 2>&1

If tests pass (shows only test output, no errors): You're done!

If tests fail: Read the error output, fix the failing test or code, then re-run zig build test 2>&1. Repeat until all tests pass.


Common Zig Error Patterns and Fixes

Compile Errors

ErrorFix
error: expected ',' after argumentYou have a trailing argument without comma - check function call syntax
error: expected type 'X', found 'Y'Type mismatch - use @as(X, value) or @intCast for coercion
error: cannot assign to constantVariable was declared const, use var if you need to mutate
error: unused variableEither use _ = variable; to discard, or remove the variable
error: undefined referenceMissing import or the symbol is not public (pub fn)

Test-Specific Errors

ErrorFix
error.TestExpectedEqualValues don't match - check expected vs actual order
error: memory leak detectedAdd missing defer thing.deinit() after allocation
error: double free detectedRemove duplicate deinit() call or check ownership

Type Coercion Fixes

// Integer literal to specific type
try std.testing.expectEqual(@as(i32, 5), myFunc());

// Compare optionals
try std.testing.expectEqual(@as(?i32, null), result);

// Compare slices/strings (use expectEqualStrings)
try std.testing.expectEqualStrings("expected", actual);

Writing New Tests

Tests go at the bottom of the source file they test:

// === Production code above ===

test "descriptive name of what is tested" {
    const allocator = std.testing.allocator;  // Always use this - detects leaks

    // Setup
    var thing = try MyThing.init(allocator);
    defer thing.deinit();  // ALWAYS defer cleanup

    // Act
    const result = thing.doSomething();

    // Assert
    try std.testing.expectEqual(@as(ExpectedType, expected), result);
}

Test Assertions Quick Reference

// Boolean check
try std.testing.expect(condition);

// Equality (order: expected, actual)
try std.testing.expectEqual(@as(i32, 5), getValue());

// String equality
try std.testing.expectEqualStrings("expected", actual);

// Error expected
try std.testing.expectError(error.InvalidInput, mightFail());

// Approximate equality for floats
try std.testing.expectApproxEqAbs(@as(f32, 1.0), result, 0.001);

Test Discovery

Tests are discovered through imports in src/main.zig:

test {
    _ = @import("api/client.zig");
    _ = @import("api/types.zig");
    // Add new modules here
}

If your new tests don't run: Ensure the file is imported in src/main.zig's test block.


Project-Specific Commands

CommandPurpose
zig buildBuild the project
zig build testRun all tests
zig build runBuild and run the app
zig test src/path/file.zigRun tests for single file (may fail if file has dependencies)

Workflow Summary

1. zig build 2>&1        → Fix any compile errors
2. zig build test 2>&1   → Fix any test failures
3. Repeat until both pass

IMPORTANT: Always run zig build before zig build test. A failing build means tests won't run.

Score

Total Score

50/100

Based on repository quality metrics

SKILL.md

SKILL.mdファイルが含まれている

+20
LICENSE

ライセンスが設定されている

0/10
説明文

100文字以上の説明がある

0/10
人気

GitHub Stars 100以上

0/15
最近の活動

3ヶ月以内に更新がある

0/10
フォーク

10回以上フォークされている

0/5
Issue管理

オープンIssueが50未満

+5
言語

プログラミング言語が設定されている

+5
タグ

1つ以上のタグが設定されている

0/5

Reviews

💬

Reviews coming soon