You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Rollup merge of rust-lang#153143 - ferrocene:jh/bootstrap-test-targets, r=Mark-Simulacrum,kobzol
Allow `./x test` to run tests without doc tests and without benchmarks
# 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](https://github.com/rust-lang/rust/blob/3f9853562c73af38a5e6af8b0da1b2734a327e19/library/coretests/Cargo.toml#L24), [allocbenches](https://github.com/rust-lang/rust/blob/3f9853562c73af38a5e6af8b0da1b2734a327e19/library/alloctests/Cargo.toml#L32)).
@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`).
Copy file name to clipboardExpand all lines: src/bootstrap/src/core/config/config.rs
+6Lines changed: 6 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -415,6 +415,12 @@ impl Config {
415
415
"flags.exclude" = ?flags_exclude
416
416
);
417
417
418
+
if flags_cmd.no_doc(){
419
+
eprintln!(
420
+
"WARN: `x.py test --no-doc` is renamed to `--all-targets`. `--no-doc` will be removed in the near future. Additionally `--tests` is added which only executes unit and integration tests."
Copy file name to clipboardExpand all lines: src/etc/completions/x.fish
+8-4Lines changed: 8 additions & 4 deletions
Original file line number
Diff line number
Diff line change
@@ -329,14 +329,16 @@ complete -c x -n "__fish_x_using_subcommand test" -l reproducible-artifact -d 'A
329
329
complete-c x -n"__fish_x_using_subcommand test"-lset-d'override options in bootstrap.toml'-r-f
330
330
complete-c x -n"__fish_x_using_subcommand test"-l ci -d'Make bootstrap to behave as it\'s running on the CI environment or not'-r-f-a"{true\t'',false\t''}"
331
331
complete-c x -n"__fish_x_using_subcommand test"-l no-fail-fast -d'run all tests regardless of failure'
332
-
complete-c x -n"__fish_x_using_subcommand test"-l no-doc -d'do not run doc tests'
333
-
complete-c x -n"__fish_x_using_subcommand test"-l doc -d'only run doc tests'
332
+
complete-c x -n"__fish_x_using_subcommand test"-l all-targets -d'Run all test targets (no doc tests)'
333
+
complete-c x -n"__fish_x_using_subcommand test"-l doc -d'Only run doc tests'
334
+
complete-c x -n"__fish_x_using_subcommand test"-l tests -d'Only run unit and integration tests'
334
335
complete-c x -n"__fish_x_using_subcommand test"-l bless -d'whether to automatically update stderr/stdout files'
335
336
complete-c x -n"__fish_x_using_subcommand test"-l force-rerun -d'rerun tests even if the inputs are unchanged'
336
337
complete-c x -n"__fish_x_using_subcommand test"-l only-modified -d'only run tests that result has been changed'
337
338
complete-c x -n"__fish_x_using_subcommand test"-l rustfix-coverage -d'enable this to generate a Rustfix coverage file, which is saved in `/<build_base>/rustfix_missing_coverage.txt`'
338
339
complete-c x -n"__fish_x_using_subcommand test"-l no-capture -d'don\'t capture stdout/stderr of tests'
339
340
complete-c x -n"__fish_x_using_subcommand test"-l bypass-ignore-backends -d'Ignore `//@ ignore-backends` directives'
341
+
complete-c x -n"__fish_x_using_subcommand test"-l no-doc -d'Deprecated. Use `--all-targets` or `--tests` instead'
340
342
complete-c x -n"__fish_x_using_subcommand test"-s v -l verbose -d'use verbose output (-vv for very verbose)'
341
343
complete-c x -n"__fish_x_using_subcommand test"-s i -l incremental -d'use incremental compilation'
342
344
complete-c x -n"__fish_x_using_subcommand test"-l include-default-paths -d'include default paths in addition to the provided ones'
@@ -374,8 +376,10 @@ complete -c x -n "__fish_x_using_subcommand miri" -l reproducible-artifact -d 'A
374
376
complete-c x -n"__fish_x_using_subcommand miri"-lset-d'override options in bootstrap.toml'-r-f
375
377
complete-c x -n"__fish_x_using_subcommand miri"-l ci -d'Make bootstrap to behave as it\'s running on the CI environment or not'-r-f-a"{true\t'',false\t''}"
376
378
complete-c x -n"__fish_x_using_subcommand miri"-l no-fail-fast -d'run all tests regardless of failure'
377
-
complete-c x -n"__fish_x_using_subcommand miri"-l no-doc -d'do not run doc tests'
378
-
complete-c x -n"__fish_x_using_subcommand miri"-l doc -d'only run doc tests'
379
+
complete-c x -n"__fish_x_using_subcommand miri"-l all-targets -d'Run all test targets (no doc tests)'
380
+
complete-c x -n"__fish_x_using_subcommand miri"-l doc -d'Only run doc tests'
381
+
complete-c x -n"__fish_x_using_subcommand miri"-l tests -d'Only run unit and integration tests'
382
+
complete-c x -n"__fish_x_using_subcommand miri"-l no-doc -d'Deprecated. Use `--all-targets` or `--tests` instead'
379
383
complete-c x -n"__fish_x_using_subcommand miri"-s v -l verbose -d'use verbose output (-vv for very verbose)'
380
384
complete-c x -n"__fish_x_using_subcommand miri"-s i -l incremental -d'use incremental compilation'
381
385
complete-c x -n"__fish_x_using_subcommand miri"-l include-default-paths -d'include default paths in addition to the provided ones'
[CompletionResult]::new('--set','--set', [CompletionResultType]::ParameterName,'override options in bootstrap.toml')
377
377
[CompletionResult]::new('--ci','--ci', [CompletionResultType]::ParameterName,'Make bootstrap to behave as it''s running on the CI environment or not')
378
378
[CompletionResult]::new('--no-fail-fast','--no-fail-fast', [CompletionResultType]::ParameterName,'run all tests regardless of failure')
379
-
[CompletionResult]::new('--no-doc','--no-doc', [CompletionResultType]::ParameterName,'do not run doc tests')
380
-
[CompletionResult]::new('--doc','--doc', [CompletionResultType]::ParameterName,'only run doc tests')
379
+
[CompletionResult]::new('--all-targets','--all-targets', [CompletionResultType]::ParameterName,'Run all test targets (no doc tests)')
380
+
[CompletionResult]::new('--doc','--doc', [CompletionResultType]::ParameterName,'Only run doc tests')
381
+
[CompletionResult]::new('--tests','--tests', [CompletionResultType]::ParameterName,'Only run unit and integration tests')
381
382
[CompletionResult]::new('--bless','--bless', [CompletionResultType]::ParameterName,'whether to automatically update stderr/stdout files')
382
383
[CompletionResult]::new('--force-rerun','--force-rerun', [CompletionResultType]::ParameterName,'rerun tests even if the inputs are unchanged')
383
384
[CompletionResult]::new('--only-modified','--only-modified', [CompletionResultType]::ParameterName,'only run tests that result has been changed')
384
385
[CompletionResult]::new('--rustfix-coverage','--rustfix-coverage', [CompletionResultType]::ParameterName,'enable this to generate a Rustfix coverage file, which is saved in `/<build_base>/rustfix_missing_coverage.txt`')
385
386
[CompletionResult]::new('--no-capture','--no-capture', [CompletionResultType]::ParameterName,'don''t capture stdout/stderr of tests')
0 commit comments