Skip to content

cargo test --examples does not work exactly as advertised #5177

@infinity0

Description

@infinity0

cargo test --help says:

    --example NAME ...           Check that the specified examples compile
    --examples                   Check that all examples compile

but what actually happens when you run cargo test --examples is that the examples are compiled and tested just like any other test, and the binary written to target/debug/examples/$NAME is a test-runner rather than the actual example binary.

This may seem harmless but it causes a surprising difference in behaviour when e.g. running cargo test && target/debug/examples/$NAME vs cargo test --examples && target/debug/examples/$NAME.

Uncovered by a proposed addition to #5146.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions