about summary refs log tree commit diff
path: root/library/test/src/lib.rs
AgeCommit message (Collapse)AuthorLines
2025-08-04Add new `test::print_merged_doctests_times` used by rustdoc to display more ↵Guillaume Gomez-0/+15
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-08libtest: Pass the test's panic payload as Option instead of ResultZalathar-8/+6
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-02-10Use io::const_error! when possible over io::Error::newThalia Archibald-0/+1
2025-02-09Fix pattern matching mode changes and unsafe_op_in_unsafe_fnMichael Goulet-2/+6
2025-01-20test: add `#![warn(unreachable_pub)]`Urgau-0/+1
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-5/+6
2024-09-24Dogfood `feature(file_buffered)`Josh Stone-0/+1
2024-09-22Reformat using the new identifier sorting from rustfmtMichael Goulet-5/+5
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-27/+22
The previous commit updated `rustfmt.toml` appropriately. This commit is the outcome of running `x fmt --all` with the new formatting options.
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-06-11Rename std::panic::PanicInfo to PanicHookInfo.Mara Bos-3/+3
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-06Drop panic hook after running testsTal Gelbard-1/+4
Previously we left the panic hook we allocated on main termination. Doing so makes Valgrind report it as a reachable unfreed block. In order to fix that use `panic::take_hook()` before examining test results. Example backtrace: ``` ==146594== 16 bytes in 1 blocks are still reachable in loss record 1 of 1 ==146594== at 0x4A390C5: malloc (vg_replace_malloc.c:442) ==146594== by 0x151336: alloc (alloc.rs:98) ==146594== by 0x151336: alloc_impl (alloc.rs:181) ==146594== by 0x151336: allocate (alloc.rs:241) ==146594== by 0x151336: exchange_malloc (alloc.rs:330) ==146594== by 0x151336: new<test::test_main::{closure_env#0}> (boxed.rs:217) ==146594== by 0x151336: test::test_main (lib.rs:124) ==146594== by 0x1522F9: test::test_main_static (lib.rs:160) ==146594== by 0x11E102: reachable_block_with_cargo_test::main (lib.rs:1) ==146594== by 0x11EABA: core::ops::function::FnOnce::call_once (function.rs:250) ==146594== by 0x11E76D: std::sys_common::backtrace::__rust_begin_short_backtrace (backtrace.rs:154) ==146594== by 0x11DFC0: std::rt::lang_start::{{closure}} (rt.rs:166) ==146594== by 0x177D3A: call_once<(), (dyn core::ops::function::Fn<(), Output=i32> + core::marker::Sync + core::panic::unwind_safe::RefUnwindSafe)> (function.rs:284) ==146594== by 0x177D3A: do_call<&(dyn core::ops::function::Fn<(), Output=i32> + core::marker::Sync + core::panic::unwind_safe::RefUnwindSafe), i32> (panicking.rs:504) ==146594== by 0x177D3A: try<i32, &(dyn core::ops::function::Fn<(), Output=i32> + core::marker::Sync + core::panic::unwind_safe::RefUnwindSafe)> (panicking.rs:468) ==146594== by 0x177D3A: catch_unwind<&(dyn core::ops::function::Fn<(), Output=i32> + core::marker::Sync + core::panic::unwind_safe::RefUnwindSafe), i32> (panic.rs:142) ==146594== by 0x177D3A: {closure#2} (rt.rs:148) ==146594== by 0x177D3A: do_call<std::rt::lang_start_internal::{closure_env#2}, isize> (panicking.rs:504) ==146594== by 0x177D3A: try<isize, std::rt::lang_start_internal::{closure_env#2}> (panicking.rs:468) ==146594== by 0x177D3A: catch_unwind<std::rt::lang_start_internal::{closure_env#2}, isize> (panic.rs:142) ==146594== by 0x177D3A: std::rt::lang_start_internal (rt.rs:148) ==146594== by 0x11DF99: std::rt::lang_start (rt.rs:165) ``` Signed-off-by: Tal Gelbard <talgelbard1@gmail.com>
2024-02-22Use generic `NonZero` everywhere else.Markus Reiter-0/+1
2024-01-30Actually abort in panic-abort-testsTyler Mandry-13/+2
2024-01-22rustc: implement support for `riscv32im_risc0_zkvm_elf`Erik Kaneda-1/+1
This also adds changes in the rust test suite in order to get a few of them to pass. Co-authored-by: Frank Laub <flaub@risc0.com> Co-authored-by: Urgau <3616612+Urgau@users.noreply.github.com>
2023-12-07libtest: Fix padding of benchmarks run as testsMartin Nordholts-14/+8
Before this fix we applied padding before manually doing what `convert_benchmarks_to_tests()` does. Instead use `convert_benchmarks_to_tests()` if applicable and then apply padding afterwards so it becomes correct. (Benches should only be padded when run as benches to make it easy to compare the benchmark numbers.)
2023-11-15Bump cfg(bootstrap)sMark Rousskov-2/+2
2023-11-02Add insta-stable std::hash::{DefaultHasher, RandomState} exportsltdk-3/+2
2023-11-02Move RandomState and DefaultHasher into std::hash, but don't export for nowltdk-3/+3
2023-10-08rustdoc: remove rust logo from non-Rust cratesMichael Howell-0/+2
2023-08-23Bump cfg(bootstrap)Mark Rousskov-1/+1
2023-08-03Add `internal_features` lintNilstrieb-0/+1
It lints against features that are inteded to be internal to the compiler and standard library. Implements MCP #596. We allow `internal_features` in the standard library and compiler as those use many features and this _is_ the standard library from the "internal to the compiler and standard library" after all. Marking some features as internal wasn't exactly the most scientific approach, I just marked some mostly obvious features. While there is a categorization in the macro, it's not very well upheld (should probably be fixed in another PR). We always pass `-Ainternal_features` in the testsuite About 400 UI tests and several other tests use internal features. Instead of throwing the attribute on each one, just always allow them. There's nothing wrong with testing internal features^^
2023-07-23fix couple of clippy findings:Matthias Krüger-2/+1
filter_map_identity iter_kv_map needless_question_mark redundant_at_rest_pattern filter_next derivable_impls
2023-05-26convert benches to tests in subprocess if we're not benchmarkingPietro Albini-2/+17
2023-05-26add StaticBenchAsTestFn and DynBenchAsTestFn to convert benches to testsPietro Albini-18/+4
Before this commit, both static and dynamic benches were converted to a DynTestFn, with a boxed closure that ran the benchmarks exactly once. While this worked, it conflicted with -Z panic-abort-tests as the flag does not support dynamic tests. With this change, a StaticBenchFn is converted to a StaticBenchAsTestFn, avoiding any dynamic test creation. DynBenchFn is also converted to DynBenchAsTestFn for completeness.
2023-05-26remove nested function from run_testPietro Albini-63/+47
The inner function is not needed anymore as it's only called once after the previous commit's refactoring.
2023-05-26refactor executing tests to centralize actually invoking testsPietro Albini-41/+28
Before this commit, tests were invoked in multiple places, especially due to `-Z panic-abort-tests`, and adding a new test kind meant having to chase down and update all these places. This commit creates a new Runnable enum, and its children RunnableTest and RunnableBench. The rest of the harness will now pass around the enum rather than constructing and passing around boxed functions. The enum has two children enums because invoking tests and invoking benchmarks requires different parameters.
2023-04-14Rollup merge of #110154 - DaniPopes:library-typos, r=JohnTitorMatthias Krüger-5/+5
Fix typos in library I ran [`typos -w library`](https://github.com/crate-ci/typos) to fix typos in the `library` directory. Refs #110150
2023-04-10Fix typos in libraryDaniPopes-5/+5
2023-04-10Stabilize IsTerminalJosh Triplett-1/+0
closes: https://github.com/rust-lang/rust/issues/98070
2023-03-03Match unmatched backticks in library/est31-1/+1
2023-01-14Remove various double spaces in source comments.André Vennberg-1/+1
2023-01-03Fix a few clippy lints in libtestJoshua Nelson-1/+1
- Remove unnecessary references and dereferences - Use `.contains` instead of `a <= x && x <= b` - Use `mem::take` instead of `mem::replace` where possible
2022-12-19Fix `uninlined_format_args` in libtestnils-3/+2
2022-12-01Create a hacky fail-fast mode that stops tests at the first failureOli Scherer-0/+20
2022-11-04Rollup merge of #103681 - RalfJung:libtest-thread, r=thomccMatthias Krüger-30/+28
libtest: run all tests in their own thread, if supported by the host This reverts the threading changes of https://github.com/rust-lang/rust/pull/56243, which made it so that with `-j1`, the test harness does not spawn any threads. Those changes were done to enable Miri to run the test harness, but Miri supports threads nowadays, so this is no longer needed. Using a thread for each test is useful because the thread's name can be set to the test's name which makes panic messages consistent between `-j1` and `-j2` runs and also a bit more readable. I did not revert the HashMap changes of https://github.com/rust-lang/rust/pull/56243; using a deterministic map seems fine for the test harness and the more deterministic testing is the better. Fixes https://github.com/rust-lang/rust/issues/59122 Fixes https://github.com/rust-lang/rust/issues/70492
2022-10-31Include both benchmarks and tests in the numbers given to `TeFiltered{,Out}`Thom Chiovoloni-2/+5
2022-10-28libtest: run all tests in their own thread, if supported by the hostRalf Jung-30/+28
2022-10-27Do fewer passes and generally be more efficient when filtering testsBen Kimock-25/+62
2022-10-26Print the precondition we violated, and visible through output captureBen Kimock-0/+25
Co-authored-by: Ralf Jung <post@ralfj.de>
2022-10-24Rollup merge of #99939 - saethlin:pre-sort-tests, r=thomcc,jackh726Yuki Okushi-10/+7
Sort tests at compile time, not at startup Recently, another Miri user was trying to run `cargo miri test` on the crate `iced-x86` with `--features=code_asm,mvex`. This configuration has a startup time of ~18 minutes. That's ~18 minutes before any tests even start to run. The fact that this crate has over 26,000 tests and Miri is slow makes a lot of code which is otherwise a bit sloppy but fine into a huge runtime issue. Sorting the tests when the test harness is created instead of at startup time knocks just under 4 minutes out of those ~18 minutes. I have ways to remove most of the rest of the startup time, but this change requires coordinating changes of both the compiler and libtest, so I'm sending it separately. (except for doctests, because there is no compile-time harness)