From 75d8339cdd8c5b07982764a9b78952a67b7cd519 Mon Sep 17 00:00:00 2001 From: bjorn3 Date: Wed, 29 Dec 2021 16:16:18 +0100 Subject: [PATCH 1/4] Replace TDynBenchFn with Fn(&mut Bencher) --- library/test/src/lib.rs | 10 ++++------ library/test/src/types.rs | 7 +------ 2 files changed, 5 insertions(+), 12 deletions(-) diff --git a/library/test/src/lib.rs b/library/test/src/lib.rs index 2516f3452b1..17e15243afd 100644 --- a/library/test/src/lib.rs +++ b/library/test/src/lib.rs @@ -444,8 +444,8 @@ pub fn convert_benchmarks_to_tests(tests: Vec) -> Vec DynTestFn(Box::new(move || { - bench::run_once(|b| __rust_begin_short_backtrace(|| bench.run(b))) + DynBenchFn(benchfn) => DynTestFn(Box::new(move || { + bench::run_once(|b| __rust_begin_short_backtrace(|| benchfn(b))) })), StaticBenchFn(benchfn) => DynTestFn(Box::new(move || { bench::run_once(|b| __rust_begin_short_backtrace(|| benchfn(b))) @@ -544,11 +544,9 @@ pub fn run_test( TestRunOpts { strategy, nocapture: opts.nocapture, concurrency, time: opts.time_options }; match testfn { - DynBenchFn(bencher) => { + DynBenchFn(benchfn) => { // Benchmarks aren't expected to panic, so we run them all in-process. - crate::bench::benchmark(id, desc, monitor_ch, opts.nocapture, |harness| { - bencher.run(harness) - }); + crate::bench::benchmark(id, desc, monitor_ch, opts.nocapture, benchfn); None } StaticBenchFn(benchfn) => { diff --git a/library/test/src/types.rs b/library/test/src/types.rs index 3512a57e8e4..37bb38fb0df 100644 --- a/library/test/src/types.rs +++ b/library/test/src/types.rs @@ -74,11 +74,6 @@ impl fmt::Display for TestName { } } -/// Represents a benchmark function. -pub trait TDynBenchFn: Send { - fn run(&self, harness: &mut Bencher); -} - // A function that runs a test. If the function returns successfully, // the test succeeds; if the function panics then the test fails. We // may need to come up with a more clever definition of test in order @@ -87,7 +82,7 @@ pub enum TestFn { StaticTestFn(fn()), StaticBenchFn(fn(&mut Bencher)), DynTestFn(Box), - DynBenchFn(Box), + DynBenchFn(Box), } impl TestFn { From 1ea4810c84e0d496bf10ebccc7e2ae5de1fb3590 Mon Sep 17 00:00:00 2001 From: bjorn3 Date: Wed, 29 Dec 2021 16:36:08 +0100 Subject: [PATCH 2/4] Remove #![crate_name] attribute from libtest The crate name is already set in Cargo.toml. The comment says there is some logic in the compiler that reads #![crate_name] and not --crate-name, but I can't find it. Removing it seems to work fine. --- library/test/src/lib.rs | 5 ----- 1 file changed, 5 deletions(-) diff --git a/library/test/src/lib.rs b/library/test/src/lib.rs index 17e15243afd..1e8c63b69db 100644 --- a/library/test/src/lib.rs +++ b/library/test/src/lib.rs @@ -13,11 +13,6 @@ // running tests while providing a base that other test frameworks may // build off of. -// N.B., this is also specified in this crate's Cargo.toml, but librustc_ast contains logic specific to -// this crate, which relies on this attribute (rather than the value of `--crate-name` passed by -// cargo) to detect this crate. - -#![crate_name = "test"] #![unstable(feature = "test", issue = "50297")] #![doc(test(attr(deny(warnings))))] #![feature(libc)] From f710bc5fc03c6cf8c24ddae71b8ca05234104d44 Mon Sep 17 00:00:00 2001 From: bjorn3 Date: Wed, 29 Dec 2021 16:36:22 +0100 Subject: [PATCH 3/4] Remove unused feature gates from libtest --- library/test/src/lib.rs | 3 --- 1 file changed, 3 deletions(-) diff --git a/library/test/src/lib.rs b/library/test/src/lib.rs index 1e8c63b69db..608e587cf34 100644 --- a/library/test/src/lib.rs +++ b/library/test/src/lib.rs @@ -15,13 +15,10 @@ #![unstable(feature = "test", issue = "50297")] #![doc(test(attr(deny(warnings))))] -#![feature(libc)] -#![feature(rustc_private)] #![feature(nll)] #![feature(available_parallelism)] #![feature(bench_black_box)] #![feature(internal_output_capture)] -#![feature(panic_unwind)] #![feature(staged_api)] #![feature(termination_trait_lib)] #![feature(test)] From e015b9ee80af5cf0386e02477ec8c339e3801e64 Mon Sep 17 00:00:00 2001 From: bjorn3 Date: Wed, 29 Dec 2021 18:06:01 +0100 Subject: [PATCH 4/4] Remove unused allow deprecated --- library/test/src/stats.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/library/test/src/stats.rs b/library/test/src/stats.rs index 45fae9c76b4..40b05704b40 100644 --- a/library/test/src/stats.rs +++ b/library/test/src/stats.rs @@ -1,5 +1,4 @@ #![allow(missing_docs)] -#![allow(deprecated)] // Float use std::mem;