Skip to main content

rust-tests-guidelines

Guidelines for writing Rust tests. Use this when you want to write Rust tests.

Informações da origem

Repositório
RediSearch/RediSearch
Última atividade na origem
7 de outubro de 2026 às 07:09
Idioma detectado do SKILL.md
inglês
Estrelas
6.247
Forks
602

Opções de instalação

Por padrão, está selecionado o prompt que primeiro revisa a origem. Você pode mudar para um comando direto ou baixar uma cópia local.

Revise os arquivos de origem

Leia o SKILL.md e os arquivos complementares exibidos pelo SkillsMP antes de decidir se vai instalar.

Exibindo SKILL.md

SKILL.md
Instruções da origem · Visualização somente leitura
name
rust-tests-guidelines
description
Guidelines for writing Rust tests. Use this when you want to write Rust tests.
# Guidelines for Writing Rust Tests Guidelines for writing new tests for Rust code. ## Guidelines 1. Test against the public API of the code under test. 2. Test private APIs if and only if the private component is highly complex and difficult to test through the public API. 3. Use `insta` whenever you are testing output that is difficult to predict or compare. 4. Where appropriate, use `proptest` to add property-based tests for key invariants. 5. Testing code should be written with the same care reserved to production code. Avoid unnecessary duplication, introduce helpers to reduce boilerplate and ensure readability. The intent of a test should be obvious or, if not possible, clearly documented. 6. Do not reference exact line numbers in comments, as they may change over time. ## Code organization 1. Put tests for public (`pub`) items under the crate's `tests` directory. Two layouts are in use and both are fine — **match whichever the crate already has**: - **`tests/integration/`** — one test crate with its own `main.rs` and a module per area (`trie_rs`, `geo`, `query_eval`, …). Prefer this for a new crate: it compiles as a single unit instead of one binary per file. - **Cargo's default layout** — one integration binary per `tests/*.rs` file (`varint`, `fork_gc`, `rlookup`, …). 2. If the test *must* rely on private APIs, co-locate it with the code it tests, using a `#[cfg(test)]` module. Integration tests cannot reach `pub(crate)` or private items, so this is the only option for them — but prefer exercising the behavior through the public API where you can, per guideline 2 above. 3. Making an item `pub` solely so integration tests can reach it is acceptable. We own both the crate and its callers, so visibility hygiene is not worth a review round. ## Dealing with extern C symbols Check out [CONTRIBUTING.md](../../src/redisearch_rs/CONTRIBUTING.md) for instructions on how to deal with undefined C symbols in Rust tests.
Ver no GitHub