testing

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Testing

测试

Test-driven by default. Prove the problem before solving it.
默认采用测试驱动模式,解决问题前先验证问题真实存在。

Core Workflow: Bug First

核心工作流:Bug 优先

  1. Reproduce — Run the failing scenario and observe the actual behavior
  2. Write a failing test — Minimal reproduction as a test case
  3. Commit the failing test — Use
    Skill(commit)
    with message like
    test: reproduce #issue-description
  4. Fix the code — Only now attempt the fix
  5. Verify — Run
    pnpm test
    and confirm the test passes
  6. Commit the fix — Separate commit from the test
This applies to all bug fixes. The failing test proves the bug exists and prevents regressions.
  1. 复现 — 运行失败场景,观察实际行为
  2. 编写失败测试 — 以最小化复现代码编写测试用例
  3. 提交失败测试 — 使用
    Skill(commit)
    ,提交信息格式类似
    test: reproduce #issue-description
  4. 修复代码 — 仅在这一步尝试修复
  5. 验证 — 运行
    pnpm test
    确认测试通过
  6. 提交修复 — 修复代码单独提交,与测试提交分开
该流程适用于所有 Bug 修复。失败的测试既能证明 Bug 真实存在,也能防止后续出现回归问题。

Fixture Tests

Fixture 测试

Noodle uses directory-based fixtures in
testdata/
. Read references/fixtures.md for full format, helper API, and code patterns.
Noodle 在
testdata/
目录下使用基于目录的 Fixture。完整格式、辅助 API 及代码模式请查阅 references/fixtures.md。

Creating a New Fixture

创建新 Fixture

sh
./scripts/scaffold-fixture.sh <package-dir> <fixture-name> [state-count]
Fill in the generated
input.json
/
input.ndjson
and
expected.md
, then:
sh
pnpm fixtures:hash:sync
sh
./scripts/scaffold-fixture.sh <package-dir> <fixture-name> [state-count]
填写生成的
input.json
/
input.ndjson
和
expected.md
,然后执行:
sh
pnpm fixtures:hash:sync

Bug Fixtures

Bug Fixture

See references/fixtures.md for full bug fixture format (frontmatter fields, expected error sections, and the fix workflow).
完整的 Bug Fixture 格式(frontmatter 字段、预期错误部分、修复工作流)请查阅 references/fixtures.md。

Key Commands

常用命令

CommandPurpose
pnpm test
Run all tests
pnpm test:short
Skip integration tests
pnpm check
Full local CI (test + vet + lint + fixtures)
pnpm bugs
List fixtures marked as known bugs
pnpm fixtures:loop
Verify loop fixtures match expected
pnpm fixtures:loop:record
Regenerate loop fixture expected output
pnpm fixtures:hash
Verify fixture input hashes
pnpm fixtures:hash:sync
Update fixture input hashes
pnpm vet
Run
go vet
pnpm lint:arch
Architecture lint (file sizes, legacy patterns)
命令用途
pnpm test
运行所有测试
pnpm test:short
跳过集成测试
pnpm check
完整本地 CI 检查(测试 + vet + lint + Fixture 校验)
pnpm bugs
列出标记为已知 Bug 的 Fixture
pnpm fixtures:loop
验证循环 Fixture 与预期结果一致
pnpm fixtures:loop:record
重新生成循环 Fixture 的预期输出
pnpm fixtures:hash
验证 Fixture 输入哈希
pnpm fixtures:hash:sync
更新 Fixture 输入哈希
pnpm vet
运行
go vet
pnpm lint:arch
架构 Lint 检查(文件大小、遗留模式)

Running Specific Tests

运行指定测试

sh
undefined
sh
undefined

Single package

Single package

go test ./loop
go test ./loop

Single test

Single test

go test ./loop -run TestLoopDirectoryFixtures
go test ./loop -run TestLoopDirectoryFixtures

Bypass cache

Bypass cache

go test -count=1 ./parse
go test -count=1 ./parse

With race detector

With race detector

go test -race ./...
go test -race ./...

Verbose

Verbose

go test -v ./tui
undefined
go test -v ./tui
undefined

Integration Tests

集成测试

Long-running or external-dependency tests use
testing.Short()
:
go
if testing.Short() {
    t.Skip("skipping integration test in short mode")
}
pnpm test:short
skips these.
pnpm test
runs everything.
运行时间长或依赖外部资源的测试使用
testing.Short()
:
go
if testing.Short() {
    t.Skip("skipping integration test in short mode")
}
pnpm test:short
会跳过这类测试,
pnpm test
会运行全部测试。