Run Tests

作者 coralogixc0713729787b无许可证121 个星标收录于 2026年10月8日更新于 2026年10月8日仓库昨天更新

Use this skill when the user asks to "run tests", "test this", "check if tests pass", "cargo test", "run clippy", "lint this", "check formatting", "cargo fmt", "CI checks", "verify changes", "does this pass tests", "run the full check", "pre-commit check", or wants to verify that code changes are correct. Use this even when the user says something like "make sure this works" or "check for issues" in the context of code changes.

AI 生成的概览

为 cx CLI 运行 Rust 测试、代码检查和格式检查,并解读失败原因。

功能
该技能说明如何为 Rust 项目 cx CLI 运行测试、代码检查和验证。它列出用于单元测试与集成测试、格式检查、clippy 检查和构建的 cargo 命令,并给出 CI 使用的确切命令序列。它还说明不同改动后应运行哪些检查,并解释常见失败原因,例如 clippy 警告、格式问题和反序列化不匹配。
适用场景
当用户要求运行测试、检查测试是否通过、执行代码检查或格式检查,或验证代码改动是否正确时使用。它也适用于在该 Rust 代码库上运行完整 CI 检查或提交前检查的请求。
运行要求
需要 Rust 工具链,包含 cargo、rustfmt 和 clippy,以及项目依赖和锁文件。标记为 ignored 的集成测试依赖本地文件系统状态,例如 ~/.cx/ 配置目录。该技能不附带脚本,仅为说明文档。

Run Tests & Verify

How to run tests, lint, and verify changes in the cx CLI. This skill covers running only - for writing new tests, see the add-command skill.

Quick Reference

CommandWhat it does
cargo testRun all unit + integration tests
cargo test <name>Run tests matching a name substring
cargo test -- --ignoredRun integration tests (filesystem-dependent, skipped by default)
cargo fmt --checkCheck formatting (no changes)
cargo fmtAuto-fix formatting
cargo clippy --locked -- -D warningsLint with warnings-as-errors
cargo buildVerify compilation

Full CI Check

This is the exact sequence CI runs on every PR. Run it before committing or creating a PR:

bash
cargo fmt --check && cargo clippy --locked -- -D warnings && cargo test --locked

The --locked flag ensures the lockfile is respected - this matches .github/workflows/test.yml and lint.yml exactly. CI runs tests on Ubuntu, macOS, and Windows.

What to Run After a Change

Pick the right level of verification based on what changed:

  • Any .rs file - cargo test + cargo clippy --locked -- -D warnings
  • Formatting only - cargo fmt --check (or cargo fmt to auto-fix)
  • Cargo.toml - full CI check (dependency changes affect everything)
  • API types (src/commands/<cmd>/api.rs) - run that command's tests first (cargo test alerts, cargo test dataprime), then the full suite
  • Test files only - cargo test <relevant_test_name>

Running Specific Tests

Target tests efficiently instead of running the entire suite:

  • cargo test alerts - all tests with "alerts" in the name
  • cargo test --test dataprime - only the tests/dataprime/ integration test binary (input + output + query)
  • cargo test --test dataprime input - only the input submodule of that binary
  • cargo test config::tests - only the tests in the config module
  • cargo test metrics::tests - only metrics formatting tests

Interpreting Failures

Clippy warnings - treated as errors via -D warnings. Fix every warning before committing. Common ones: unused variables, unnecessary clones, missing error handling.

Format failures - run cargo fmt to auto-fix. These never need manual intervention.

Deserialization test failures - usually means struct field names don't match JSON keys. Check that #[serde(rename_all = "camelCase")] is on response types and that #[serde(default)] is on Vec fields (the API sometimes omits empty arrays).

Compilation errors in tests - likely caused by changing a public function signature. Check callers in both src/ and tests/ directories.

Integration test failures (--ignored) - these depend on filesystem state (~/.cx/ config directory). They may fail if the local environment isn't set up. This is expected in CI where no config exists.

来源与署名

来源:coralogix/cx-cli位于.claude/skills/run-tests提交c071372

许可证: 无许可证

内容归原作者所有。SourceWeft 从公开仓库中收录这些内容。

举报或申请下架