Skip to content

cargo test --lib should not error when no lib is present #15231

Open
@iamroot99

Description

@iamroot99

Problem

This is somewhat related to what #10958 requests, but the target and use-case are different.

I need to run the unit tests in several workspaces. The only way I am aware of that can achieve this is via

cargo test --bins --lib

The problem is that I am running this command over arbitrary-structured workspaces that may have 0 or more binaries and 0 or more libraries within them. The scenarios boil down to the 3 cases below:

  • 0 bins, 1+ libs: cargo test completes with a warning
  • 1+bins, 1+libs: cargo test completes
  • 1+bins, 0 libs: cargo test fails

If there are 0 binaries, then the command completes with a warning, but if there are no libs in the workspace it will fail with the following error:

error: no library targets found in packages: bin1, bin2

Proposed Solution

I think there are two options here:

  1. Modify --lib to warn instead of error when no libraries are present.
  2. Introduce a --libs argument that warns when no libraries are present. This would keep the behaviour of --lib intact.

I would be happy to implement the change myself.

Notes

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-feature-requestCategory: proposal for a feature. Before PR, ping rust-lang/cargo if this is not `Feature accepted`Command-testS-triageStatus: This issue is waiting on initial triage.

    Type

    No type

    Projects

    Status

    No status

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions