Skip to content

Add mechanism to verify that source code in documentation is valid #7951

Description

@andygrove

Is your feature request related to a problem or challenge?

Our user guide and library guide contain code samples, but these can quickly become outdated and stop compiling and we have to automated way to check if they still compile.

Describe the solution you'd like

I propose that code samples be written as unit tests and that we then use a script to insert these code samples into the documentation when we publish the docs.

Describe alternatives you've considered

No response

Additional context

No response

Activity

  1. self-assigned this
    on Oct 27, 2023
  2. changed the title [-]Make sure that all code samples in the documentation are tested automatically[/-] [+]Add mechanism to verify that source code in documentation is valid[/+] on Oct 28, 2023
  3. alamb commented on Aug 20, 2024

    @alamb
    Contributor

    I believe this is now handled via the doctest macro, for example:

    // Instructions for Documentation Examples
    //
    // The following commands test the examples from the user guide as part of
    // `cargo test --doc`
    //
    // # Adding new tests:
    //
    // Simply add code like this to your .md file and ensure your md file is
    // included in the lists below.
    //
    // ```rust
    // <code here will be tested>
    // ```
    //
    // Note that sometimes it helps to author the doctest as a standalone program
    // first, and then copy it into the user guide.
    //
    // # Debugging Test Failures
    //
    // Unfortunately, the line numbers reported by doctest do not correspond to the
    // line numbers of in the .md files. Thus, if a doctest fails, use the name of
    // the test to find the relevant file in the list below, and then find the
    // example in that file to fix.
    //
    // For example, if `user_guide_expressions(line 123)` fails,
    // go to `docs/source/user-guide/expressions.md` to find the relevant problem.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

documentationImprovements or additions to documentationenhancementNew feature or request

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions