about summary refs log tree commit diff
path: root/library/test
AgeCommit message (Collapse)AuthorLines
2025-08-29Update getopts to remove unicode-width dependencybjorn3-1/+1
2025-08-11Deprecate RUST_TEST_* env variablesEd Page-9/+8
This is a documentation-only deprecation for now. Over time, we can - warn and then remove on use of unstable environment variables - warn on use of stable environment variables (no plan to remove due to compatibility) Longer term, we expect test runners, like `cargo test`, to provide the necessary mechanisms for environmental or persistent configuration (e.g. using cargo config which supports `.cargo/config.toml` as well as environment variables). This would include: - `RUST_TEST_THREADS` - `RUST_TEST_NOCAPTURE` - `RUST_TEST_SHUFFLE` (unstable) - `RUST_TEST_SHUFFLE_SEED` (unstable) The primary outcomes for this change are - Reducing the scope of what is expected for custom test harnesses to implement - Reduce the mechanisms that test runners, like `cargo test`, are expected to track when they are being bypassed to protect against negative interactions, e.g. `RUST_TEST_NOCAPTURE=1` when json output is being read.
2025-08-04Add new `test::print_merged_doctests_times` used by rustdoc to display more ↵Guillaume Gomez-11/+76
detailed time information and add new `OutputFormatter::write_merged_doctests_times` method to handle it
2025-07-31Make `libtest::ERROR_EXIT_CODE` const public to not redefine it in rustdocGuillaume Gomez-2/+2
2025-05-06Add new `test_main_with_exit_callback` public function in `libtest` to allow ↵Guillaume Gomez-0/+10
a callback to be called before exiting
2025-04-28Remove backticks from `ShouldPanic::YesWithMessage`'s `TrFailedMsg`Lieselotte-8/+7
2025-04-17fix(test): Expose '--no-capture', deprecating '--nocapture'Ed Page-4/+7
This improves consistency with commonly expected CLI conventions, avoiding a common stutter people make when running tests (trying what they expect and then having to check the docs to then user whats accepted). An alternative could have been to take a value, like `--capture <value>` (e.g. `pytest` does this). Overall, we're shifting focus for features to custom test harnesses (see #134283). Most of `pytest`s modes will likely be irrelevant in that situation. As for the rest, its too early to tell which, if any, may be relevant, so we're sticking with this small, quality of life improvement. By deprecating `--nocapture`, we intend that custom test harnesses do not need to support it for reasons outside of their own compatibility requirements, much like the deprecation in #134283 I'm punting for now on the naming of `RUST_TEST_NOCAPTURE`. I feel like T-testing-devex should do a wider look at environment variables role in lib`test` before evaluating whether to - Deprecate it in favor of the user passing CLI flags or the test runner providing its own config - Deprecate in favor of `RUST_TEST_NO_CAPTURE` - Deprecate in favor of `RUST_TEST_CAPTURE` Other CLI flags were evaluated for casing consistency: - `--logfile` has the same problem but was deprecated in #134283 Fixes #133073
2025-04-17refactor(test): Decouple parsing from help generationEd Page-1/+1
This will help with hiding some options in `--help`
2025-04-14Report span of test when should_panic test failedxizheyin-1/+6
Signed-off-by: xizheyin <xizheyin@smail.nju.edu.cn>
2025-04-08libtest: Pass the test's panic payload as Option instead of ResultZalathar-15/+20
Passing a `Result<(), &dyn Any>` to `calc_result` requires awkward code at both call sites, for no real benefit. It's much easier to just pass the payload as `Option<&dyn Any>`. No functional change, except that the owned payload is dropped slightly later.
2025-03-11Migrate test to Rust 2024Eric Huss-1/+1
2025-02-28Use correct error message casing for `io::const_error`sNoratrieb-3/+3
Error messages are supposed to start with lowercase letters, but a lot of `io::const_error` messages did not. This fixes them to start with a lowercase letter. I did consider adding a const check for this to the macro, but some of them start with proper nouns that make sense to uppercase them. See https://doc.rust-lang.org/1.85.0/std/error/trait.Error.html
2025-02-21Use `public-dependencies` in all sysroot cratesTrevor Gross-2/+4
In [1], most dependencies of `std` and other sysroot crates were marked private, but this did not happen for `alloc` and `test`. Update these here, marking public standard library crates as the only non-private dependencies. [1]: https://github.com/rust-lang/rust/pull/111076
2025-02-17Rollup merge of #136844 - thaliaarchi:const-io-error, r=ChrisDentonMatthias Krüger-5/+6
Use `const_error!` when possible Replace usages of `io::Error::new(io::ErrorKind::Variant, "constant string")` with `io::const_error!(io::ErrorKind::Variant, "constant string")` to avoid allocations when possible. Additionally, fix `&&str` error messages in SGX and missing/misplaced trailing commas in `const_error!`.
2025-02-13test: Apply deprecated_safe_2024Eric Huss-2/+6
2025-02-10Use io::const_error! when possible over io::Error::newThalia Archibald-5/+6
2025-02-10Rollup merge of #136705 - compiler-errors:edition-library, r=jhprattJubilee-3/+7
Some miscellaneous edition-related library tweaks Some library edition tweaks that can be done separately from upgrading the whole standard library to edition 2024 (which is blocked on getting the submodules upgraded, for example)
2025-02-09fix(libtest): Enable Instant on Emscripten targetsAlisa Sireneva-2/+3
`Instant::now()` works correctly on Emscripten since https://github.com/rust-lang/libc/pull/3962. All wasm-family targets with OS support can now handle instants.
2025-02-09Fix pattern matching mode changes and unsafe_op_in_unsafe_fnMichael Goulet-2/+6
2025-02-09Mark extern blocks as unsafeMichael Goulet-1/+1
2025-01-25Rollup merge of #135948 - bjorn3:update_emscripten_std_tests, r=Mark-SimulacrumJacob Pratt-10/+0
Update emscripten std tests This disables a bunch of emscripten tests that test things emscripten doesn't support and re-enables a whole bunch of tests which now work just fine on emscripten. Tested with `EMCC_CFLAGS="-s MAXIMUM_MEMORY=2GB" ./x.py test library/ --target wasm32-unknown-emscripten`.
2025-01-24fix(libtest): Deprecate '--logfile'Ed Page-2/+6
rust-lang/testing-devex-team#9 proposed changing the behavior of `--logfile`. The given reasons were: (1) Bazel can't programmatically process stdout. This seems like a limitation in Bazel and we recommend focusing on that. If we look at the wider Rust ecosystem, Rustc and Cargo don't support any such mechanism and the Cargo team rejected having one. Expecting this in libtest when its not supported elsewhere seems too specialized. (2) Tests that leak out non-programmatic output that intermixes with programmatic output. We acknowledge this is a problem to be evaluated but we need to make sure we are stepping back and gathering requirements, rather than assuming `--logfile` will fit the needs. Independent of the motive, regarding using or changing `--logfile` (1) Most ways to do it would be a breaking change, like if we respect any stable `--format`. As suggested above, we could specialize this to new `--format` values but that would be confusing for some values to apply but not others. (2) Other ways of solving this add new features to lib`test` when we are instead wanting to limit the feature set it has to minimize the compatibility surface that has to be maintained and the burden it would put on third party harnesses which are a focus area. Examples include `--format compact` or a `--log-format` flag (3) The existence of `--logfile` dates back quite a ways (https://github.com/rust-lang/rust/commit/5cc050b265509c19717e11e12dd785d8c73f5b11, rust-lang/rust#2127) and the history gives the impression this more of slipped through rather than being an intended feature (see also https://github.com/rust-lang/rust/pull/82350#discussion_r579732071). Deprecation would better match to how it has been treated. By deprecating this, we do not expect custom test harnesses (rust-lang/testing-devex-team#2) to implement this. T-testing-devex held an FCP for deprecating in rust-lang/testing-devex-team#9 though according to [RFC #3455](https://rust-lang.github.io/rfcs/3455-t-test.html), this is still subject to final approval from T-libs-api.
2025-01-24Remove a bunch of emscripten test ignoresbjorn3-10/+0
They are either outdated as emscripten now supports i128 or they are subsumed by #[cfg_attr(not(panic = "unwind"), ignore]
2025-01-20test: add `#![warn(unreachable_pub)]`Urgau-79/+80
2024-11-19Update thread spawn hooks.Mara Bos-2/+2
1. Make the effect thread local. 2. Don't return a io::Result from hooks.
2024-11-19Use add_spawn_hook for libtest's output capturing.Mara Bos-0/+11
2024-10-08Change a few `&Option<T>` into `Option<&T>`Yuri Astrakhan-9/+10
2024-09-24Dogfood `feature(file_buffered)`Josh Stone-4/+3
2024-09-22Reformat using the new identifier sorting from rustfmtMichael Goulet-11/+11
2024-08-13Reduce merged doctest source code sizeGuillaume Gomez-0/+34
2024-07-29Rollup merge of #128307 - ojeda:unescaped_backticks, r=GuillaumeGomezMatthias Krüger-0/+1
Clean and enable `rustdoc::unescaped_backticks` for `core/alloc/std/test/proc_macro` I am not sure if the lint is supposed to be "ready enough" (since it is `allow` by default), but it does catch a couple issues in `core` (`alloc`, `std`, `test` and `proc_macro` are already clean), so I propose making it `warn` in all the crates rendered in the website. Cc: `@GuillaumeGomez`
2024-07-29Warn on `rustdoc::unescaped_backticks` for `core/alloc/std/test/proc_macro`Miguel Ojeda-0/+1
They are all clean now, so enable the lint to keep them clean going forward. Signed-off-by: Miguel Ojeda <ojeda@kernel.org>
2024-07-29Reformat `use` declarations.Nicholas Nethercote-124/+107
The previous commit updated `rustfmt.toml` appropriately. This commit is the outcome of running `x fmt --all` with the new formatting options.
2024-07-26Fix doc nitsJohn Arundel-2/+2
Many tiny changes to stdlib doc comments to make them consistent (for example "Returns foo", rather than "Return foo", per RFC1574), adding missing periods, paragraph breaks, backticks for monospace style, and other minor nits. https://github.com/rust-lang/rfcs/blob/master/text/1574-more-api-documentation-conventions.md#appendix-a-full-conventions-text
2024-07-18Rollup merge of #127594 - c6c7:fuchsia-status-code-match-arm, r=tmandryMatthias Krüger-2/+13
Fuchsia status code match arm Adds a match arm for the Fuchsia status code upon a process abort. An additional change moves the Windows status code down into the match arm itself instead of being defined as a constant elsewhere. r​? tmandry
2024-07-17Avoid comments that describe multiple `use` items.Nicholas Nethercote-1/+0
There are some comments describing multiple subsequent `use` items. When the big `use` reformatting happens some of these `use` items will be reordered, possibly moving them away from the comment. With this additional level of formatting it's not really feasible to have comments of this type. This commit removes them in various ways: - merging separate `use` items when appropriate; - inserting blank lines between the comment and the first `use` item; - outright deletion (for comments that are relatively low-value); - adding a separate "top-level" comment. We also entirely skip formatting for four library files that contain nothing but `pub use` re-exports, where reordering would be painful.
2024-07-15Update name of Windows abort constant to match platform documentationCharles Celerier-2/+2
2024-07-15Add match arm for Fuchsia status code upon an abort in a testCharles Celerier-0/+11
This change adds ZX_TASK_RETCODE_EXCEPTION_KILL as an expected status code upon an abort in a test on Fuchsia. Tests fixes #127539
2024-06-20Add blank lines after module-level `//!` comments.Nicholas Nethercote-0/+3
Most modules have such a blank line, but some don't. Inserting the blank line makes it clearer that the `//!` comments are describing the entire module, rather than the `use` declaration(s) that immediately follows.
2024-06-11Rename std::panic::PanicInfo to PanicHookInfo.Mara Bos-3/+3
2024-06-10Remove some unused crate dependencies.Nicholas Nethercote-2/+0
I found these by setting the `unused_crate_dependencies` lint temporarily to `Warn`.
2024-05-30Apply x clippy --fix and x fmtr0cky-2/+2
2024-05-26use proper name instead of magic numberLzu Tao-8/+6
2024-05-06emit fractional benchmark nanoseconds in libtest's JSON output formatThe 8472-2/+2
2024-05-06print walltime benchmarks with subnanosecond precisionThe 8472-10/+13
example results when benchmarking 1-4 serialized ADD instructions ``` running 4 tests test add ... bench: 0.24 ns/iter (+/- 0.00) test add2 ... bench: 0.48 ns/iter (+/- 0.01) test add3 ... bench: 0.72 ns/iter (+/- 0.01) test add4 ... bench: 0.96 ns/iter (+/- 0.01) ```
2024-05-03Rollup merge of #124681 - risc0:erik/fix-test, r=joboetMichael Goulet-1/+3
zkvm: fix run_tests `zkvm` is single-threaded, similar to `emscripten` and `wasm`. The `cfg` for `zkvm` seems to have been dropped. This PR adds the `cfg` again.
2024-05-03zkvm: fix run_testsErik Kaneda-1/+3
zkvm is single-threaded, similar to emscripten and wasm.
2024-04-22Stabilize generic `NonZero`.Markus Reiter-1/+0
2024-04-15Rollup merge of #123548 - RalfJung:what-is-time, r=joboet许杰友 Jieyou Xu (Joe)-4/+2
libtest: also measure time in Miri A long time ago we disabled timekeeping of the default test harness in Miri, as otherwise it would fail to run without `-Zmiri-disable-isolation`. However, since then Miri gained a "fake clock" that lets it present some deterministic notion of time when isolation is enabled. So we could now let libtest do timekeeping again when running in Miri. That's nice as it can help detect tests that run too long. However it can also be confusing as the results with isolation can be quite different than the real time. ``@rust-lang/miri`` what do you think?
2024-04-15libtest: also measure time in MiriRalf Jung-4/+2