Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
iamroot99 opened this issue Feb 24, 2025 · 1 comment
Open

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

iamroot99 opened this issue Feb 24, 2025 · 1 comment
Labels
C-feature-request Category: proposal for a feature. Before PR, ping rust-lang/cargo if this is not `Feature accepted` Command-test S-triage Status: This issue is waiting on initial triage.

Comments

@iamroot99
Copy link

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

@iamroot99 iamroot99 added C-feature-request Category: proposal for a feature. Before PR, ping rust-lang/cargo if this is not `Feature accepted` S-triage Status: This issue is waiting on initial triage. labels Feb 24, 2025
@weihanglo
Copy link
Member

There is already an open PR #14163, though the target selection discussion is still in discussion in #10958.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-feature-request Category: proposal for a feature. Before PR, ping rust-lang/cargo if this is not `Feature accepted` Command-test S-triage Status: This issue is waiting on initial triage.
Projects
Status: No status
Development

No branches or pull requests

3 participants