Skip to content

Flag for stop interpreting code blocks as doctests #63193

Open
@hghwng

Description

@hghwng

Code blocks inside documentation are interpreted as doctests by default. Sometimes the code is not for testing at all (for example, writing pseudo-code for an algorithm), and we can add ignore at the beginning of the code block.

However, even if ignore is added, cargo test still interprets the code block as doctest, and prints "... ignored" on each occurrence of ignore-tagged code blocks. In fact, those code blocks should not be interpreted as doctest, and cargo test should silently ignore those code blocks.

For example, the following code is a snippet of my current project.

/// Minimize the input size while preserving the coverage.
///
/// The algorithm trims by trying to remove chunks, starting from large chunks
/// to small chunks.
///
/// # Algorithm
/// ```ignore
/// for round in rounds {
///     for chunk_index in buffer {
///         let new_buffer = remove_chunk(chunk_index, round_size);
///         if run(new_buffer).coverage == known_coverage {
///             buffer = new_buffer;
///         }
///     }
/// }
/// ```
pub struct Trim {
...
}

cargo test generates the following output:

[...]
   Doc-tests dfuzz

running 4 tests
test src/algorithm/pass/mod.rs - algorithm::pass::Trim (line 17) ... ignored
test src/tracer/function.rs - tracer::function (line 18) ... ignored
test src/tracer/function.rs - tracer::function (line 23) ... ignored
test src/tracer/function.rs - tracer::function (line 5) ... ignored

Is it possible to add a flag in the code block to suppress such "ignored" messages?

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-doctestsArea: Documentation tests, run by rustdocC-feature-requestCategory: A feature request, i.e: not implemented / a PR.T-rustdocRelevant to the rustdoc team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    Status

    No status

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions