Skip to content

Allow ./x test to run tests without doc tests and without benchmarks#153143

Open
Urhengulas wants to merge 6 commits intorust-lang:mainfrom
ferrocene:jh/bootstrap-test-targets
Open

Allow ./x test to run tests without doc tests and without benchmarks#153143
Urhengulas wants to merge 6 commits intorust-lang:mainfrom
ferrocene:jh/bootstrap-test-targets

Conversation

@Urhengulas
Copy link
Contributor

@Urhengulas Urhengulas commented Feb 26, 2026

Problem

For Ferrocene we would like to run only the coretests and alloctests test suites when measuring code coverage. Running corebenches and allocbenches would alter the numbers, which is not compliant with the certification.

This is currently not possible in bootstrap. By default ./x test runs unit, integration and doc tests. ./x test --doc only runs doc tests. So far, so good.

The problem is that while ./x test --no-doc stops bootstrap from executing doc tests, it surprisingly starts executing benchmarks (next to examples and bins as well). It basically behaves like cargo test --all-targets.

Solution

This PR renames the existing --no-doc flag to --all-targets and keeps the same behaviour as before. Unfortunately it is not possible to internally switch from cargo --bins --examples --tests --benches to cargo --all-targets because it will fail e.g. ./x test library/alloc --all-targets with an error like "use of unstable library feature test".

Additionally, this PR add a ./x test --tests flag (equivalent to cargo test --tests) that only executes unit and integration tests.

Both changes we are doing in https://github.com/ferrocene/ferrocene anyways, but believe that they may be useful for other people as well and therefore would like to contribute them.

Note that this PR does not change the behaviour of either ./x test or ./x test --doc.

Note on test = true

While this change enables bootstrap to run tests without doc tests and without benchmarks, executing ./x test library/core library/alloc --tests will still build and execute corebenches and allocbenches.

What?! 😱 Why all of this effort to enable it then?

Good question! The reason they are still executed is, that they are marked with test = true in their respective Cargo.toml (corebenches, allocbenches).

@bjorn3 mentioned that it is important for upstream that those benchmarks are executed by default, even if no ./x --all-targets is passed. This is perfectly possible with this PR. Benchmarks marked with test = true will be executed when calling either of ./x test, ./x test --tests or ./x --all-targets. Therefore this PR does not include a commit to change that. We will just do this change in https://github.com/ferrocene/ferrocene.

Open questions

Error message

I added one commit that adds an error message if a user passes --no-doc and points them to --all-targets and --tests. I think it might be nice to have, but if you think it is not necessary, I can remove it.

How to test this change

You can see the change in action by running ./x test library/alloc --tests and ./x test library/alloc --all-targets. The first will execute alloctests and allocbenches (which is marked with test = true), while the second will additionally run benches/vec_deque_append.rs (which is not marked with test = true).

@rustbot
Copy link
Collaborator

rustbot commented Feb 26, 2026

The rustc-dev-guide subtree was changed. If this PR only touches the dev guide consider submitting a PR directly to rust-lang/rustc-dev-guide otherwise thank you for updating the dev guide with your changes.

cc @BoxyUwU, @jieyouxu, @Kobzol, @tshepang

@rustbot rustbot added A-rustc-dev-guide Area: rustc-dev-guide A-testsuite Area: The testsuite used to check the correctness of rustc S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-bootstrap Relevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap) T-libs Relevant to the library team, which will review and decide on the PR/issue. labels Feb 26, 2026
@rustbot
Copy link
Collaborator

rustbot commented Feb 26, 2026

r? @jieyouxu

rustbot has assigned @jieyouxu.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

Why was this reviewer chosen?

The reviewer was selected based on:

  • Owners of files modified in this PR: bootstrap
  • bootstrap expanded to 6 candidates
  • Random selection from Mark-Simulacrum, clubby789, jieyouxu

@Urhengulas Urhengulas force-pushed the jh/bootstrap-test-targets branch from 772d7dc to 52327a7 Compare February 26, 2026 16:57
@Urhengulas
Copy link
Contributor Author

Urhengulas commented Feb 27, 2026

I am pretty sure that following workaround will also become unnecessary when running ./x library/alloc --tests:

if cfg!(miri) {
// Don't benchmark Miri...
// (Due to bootstrap quirks, this gets picked up by `x.py miri library/alloc --no-doc`.)
return;
}

@jieyouxu
Copy link
Member

jieyouxu commented Mar 3, 2026

@rustbot reroll

@rustbot rustbot assigned Mark-Simulacrum and unassigned jieyouxu Mar 3, 2026
@Mark-Simulacrum
Copy link
Member

r=me with commits squashed a bit (or fully)

Copy link
Member

@Kobzol Kobzol left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you please add a change tracker entry to change_tracker.rs, telling people that there is a new flag and --doc is deprecated? Thanks!

View changes since this review

///
/// By default all build output will be placed in the current directory.
pub fn new(mut config: Config) -> Build {
if config.cmd.no_doc() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the code panics, then it's not really a deprecation :) Let's just print a warning, and move this to config parsing from here.

@rustbot rustbot added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Mar 9, 2026
@rustbot
Copy link
Collaborator

rustbot commented Mar 9, 2026

Reminder, once the PR becomes ready for a review, use @rustbot ready.

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

Labels

A-rustc-dev-guide Area: rustc-dev-guide A-testsuite Area: The testsuite used to check the correctness of rustc S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. T-bootstrap Relevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap) T-libs Relevant to the library team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants