Skip to content
Agentmart
Submit a tool

zig-testing

Zig 测试与调试技能。涉及 std.testing 的断言、测试组织、内存泄漏检测、以及 std.debug 的日志、堆栈回溯。在需要编写测试、调试代码、诊断问题时调用。

Skill by Yabuku-xD

IndexedMIT
Write a review

Install

Works with Claude Code, Claude apps, Codex, Cursor, Gemini CLI, GitHub Copilot, VS Code, OpenCode, Goose, Windsurf. Read the repository before you give any tool access to your data.

npx agentmarket install skill/yabuku-xd-zig-testing-6c6fa8

Asks which of your tools to add it to (Claude Code, Codex, Cursor, VS Code, Windsurf, Gemini CLI, Claude Desktop) and shows the change first. See https://agentmart.dev/cli.

Get the weekly diff

The weekly diff: one email a week with new agent tools, notable updates and grade changes, plus security alerts for tools you follow. Double opt-in, one-click unsubscribe.

We use your email only for this newsletter. Privacy

About

Zig 测试与调试技能。涉及 std.testing 的断言、测试组织、内存泄漏检测、以及 std.debug 的日志、堆栈回溯。在需要编写测试、调试代码、诊断问题时调用。

Use cases: testing

No reviews yet. Installed it? Reviews come from verified installers only. How reviews work

Permissions

What this skill can do and what it asks for, from its SKILL.md. Checked Oct 25, 2026.

Tools
No tools found
Secrets
None asked for
Install scripts
None found

Network hosts it talks to 1

  • codeload.github.com · found in install command

Files it touches

  • ~/.claude/skills/zig-testing

What's inside

Skill name
zig-testing
Description
Zig 测试与调试技能。涉及 std.testing 的断言、测试组织、内存泄漏检测、以及 std.debug 的日志、堆栈回溯。在需要编写测试、调试代码、诊断问题时调用。
License
MIT
Instructions
272 lines in SKILL.md · view on GitHub

Files (1)

  • SKILL.md

SKILL.md (first lines)

# Zig 测试与调试

> 基于 std.testing 和 std.debug 的质量保障工具(Zig 0.16.0)。

## Capability Boundaries

### ✅ 强项
1. 单元测试编写与断言
2. 测试组织(test 声明、doctest、测试过滤器)
3. 内存泄漏检测
4. 日志输出(std.log)
5. 调试工具(panic、断言、堆栈回溯、hex dump)

### ⚠️ 前置要求
1. 确认 Zig 版本(`zig version`)

### ❌ 不适用范围
1. 构建系统测试配置 → 使用 `zig-build-system` 技能
2. 集成测试框架 → 使用 `zig-0.16` 技能
3. 性能基准测试 → 暂不涉及(Zig 尚未内置 benchmark)

## 何时使用

- "帮我写单元测试"
- "调试这个函数的输出"
- "检查内存泄漏"

## Data Privacy

本技能不收集、存储或传输任何用户数据。

## Workflow — 测试

步骤 1. **声明测试** — `test "name" { ... }`
步骤 2. **使用断言** — `expect`, `expectEqual`, `expectEqualStrings`
步骤 3. **运行测试** — `zig test src/main.zig` 或 `zig build test`
步骤 4. **检查结果** — 通过/失败/泄漏

## 断言速查

| 断言 | 用途 |
|------|------|
| `expect(bool)` | 条件为真 |
| `expectEqual(expected, actual)` | 浅相等(peer type) |
| `expectEqualDeep(expected, actual)` | 深相等(递归比较) |
| `expectEqualStrings(expected, actual)` | 字符串相等(带 diff) |
| `expectEqualSlices(T, expected, actual)` | 切片相等 |
| `expectError(error, result)` | 返回特定错误 |
| `expectApproxEqAbs(expected, actual, eps)` | 浮点近似(绝对误差) |
| `expectApproxEqRel(expected, actual, eps)` | 浮点近似(相对误差) |
| `expectFmt(expected, template, args)` | 格式化输出匹配 |
| `expectStringStartsWith(actual, prefix)` | 字符串前缀 |
| `expectStringEndsWith(actual, suffix)` | 字符串后缀 |

## 基本断言

```zig
test "basic assertions" {
    try std.testing.expect(true);

    try std.testing.expectEqual(@as(u32, 42), @as(u32, 42));

    try std.testing.expectEqualStrings("hello", "hello");

    try std.testing.expectEqualSlices(u8, &[_]u8{ 1, 2 }, &[_]u8{ 1, 2 });

    try std.testing.expectEqualDeep(
        struct{ x: i32, y: i32 }{ .x = 1, .y = 2 },
        struct{ x: i32, y: i32 }{ .x = 1, .y = 2 },
    );
}
```

### 浮点比较
```zig
test "float comparison" {
    try std.testing.expectApproxEqAbs(@as(f32, 1.0), 1.0001, 0.001);
    try std.testing.expectApproxEqRel(@as(f64, 100.0), 99.5, 0.01);
}
```

### 错误检查
```zig
test "error handling" {
    const result: anyerror!i32 = error.SomeError;
    try std.testing.expectError(error.SomeError, result);
}
```

## 测试组织

### 内联测试
```zig
const std = @import("std");
const expect = std.testing.expect;

test "inline test" {
    try expect(1 + 1 == 2);
}
```

### doctest(文档中的测试)
```zig
/// Adds two numbers.
///
/// ```
/// const result = add(2, 3);
/// try std.testing.expectEqual(@as(i32, 5), result);
/// ```
fn add(a: i32, b: i32) i32 {
    return a + b;
}
```

### 测试过滤器
```bash
# 运行名称包含 "http" 的测试
zig test src/main.zig --test-filter "http"

From Yabuku-xD/omfx, MIT.

More from Yabuku-xD/omfx

Signals

Stars
0
Forks
0
Open issues
0
Last commit (this folder)
Aug 24, 2026 (2 months ago)

From GitHub (fetched Oct 24, 2026).

Details

License
MIT
First seen
Oct 24, 2026
Last checked
Oct 24, 2026

More from Yabuku-xD

Cite this page

zig-testing skill. Agent Mart. https://agentmart.dev/skills/yabuku-xd-zig-testing-6c6fa8 (last updated 2026-10-24)