From 805f1af874214f64dee234dd6e51982a5e40f426 Mon Sep 17 00:00:00 2001 From: Travis Gockel Date: Wed, 8 Feb 2023 11:56:24 -0700 Subject: [PATCH] Fixes test signatures for Rust 1.69 The main change is Rust test function shifting from `() -> ()` to `() -> Result<(), String>`. This wraps test generated test functions in closures which return `Ok` results. --- src/lib.rs | 1 - src/runner.rs | 26 +++++++++++++++----------- 2 files changed, 15 insertions(+), 12 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 34d6e6a..65764e6 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,7 +1,6 @@ #![feature(test)] #![allow(incomplete_features)] #![feature(specialization)] -#![feature(termination_trait_lib)] #![feature(unboxed_closures)] #![feature(fn_traits)] //! Crate for supporting data-driven tests. diff --git a/src/runner.rs b/src/runner.rs index 5b23513..59c68d6 100644 --- a/src/runner.rs +++ b/src/runner.rs @@ -31,7 +31,7 @@ impl From for ShouldPanic { pub struct RegularTestDesc { pub name: &'static str, pub ignore: bool, - pub testfn: fn(), + pub testfn: fn() -> Result<(), String>, pub should_panic: RegularShouldPanic, pub source_file: &'static str, } @@ -125,21 +125,21 @@ impl rustc_test::TDynBenchFn for FilesBenchFn { } impl<'r> Fn<(&'r mut Bencher,)> for FilesBenchFn { - extern "rust-call" fn call(&self, (bencher,): (&'r mut Bencher,)) { - (self.0)(bencher, &self.1[..]); + extern "rust-call" fn call(&self, (bencher,): (&'r mut Bencher,)) -> Self::Output { + Ok((self.0)(bencher, &self.1[..])) } } impl<'r> FnOnce<(&'r mut Bencher,)> for FilesBenchFn { - type Output = (); - extern "rust-call" fn call_once(self, harness: (&'r mut Bencher,)) { - (self.0)(harness.0, &self.1) + type Output = Result<(), String>; + extern "rust-call" fn call_once(self, harness: (&'r mut Bencher,)) -> Self::Output { + Ok((self.0)(harness.0, &self.1)) } } impl<'r> FnMut<(&'r mut Bencher,)> for FilesBenchFn { - extern "rust-call" fn call_mut(&mut self, harness: (&'r mut Bencher,)) { - (self.0)(harness.0, &self.1) + extern "rust-call" fn call_mut(&mut self, harness: (&'r mut Bencher,)) -> Self::Output { + Ok((self.0)(harness.0, &self.1)) } } @@ -183,7 +183,9 @@ fn render_files_test(desc: &FilesTestDesc, rendered: &mut Vec) { .map_or(false, |ignore_func| ignore_func(&path)); let testfn = match desc.testfn { - FilesTestFn::TestFn(testfn) => TestFn::DynTestFn(Box::new(move || testfn(&paths))), + FilesTestFn::TestFn(testfn) => { + TestFn::DynTestFn(Box::new(move || Ok(testfn(&paths)))) + } FilesTestFn::BenchFn(benchfn) => { TestFn::DynBenchFn(Box::new(FilesBenchFn(benchfn, paths))) } @@ -235,8 +237,10 @@ fn render_data_test(desc: &DataTestDesc, rendered: &mut Vec) { }; let testfn = match case.case { - DataTestFn::TestFn(testfn) => TestFn::DynTestFn(testfn), - DataTestFn::BenchFn(benchfn) => TestFn::DynBenchFn(benchfn), + DataTestFn::TestFn(testfn) => TestFn::DynTestFn(Box::new(move || Ok(testfn()))), + DataTestFn::BenchFn(benchfn) => { + TestFn::DynBenchFn(Box::new(move |bencher| Ok(benchfn(bencher)))) + } }; // Generate a standard test descriptor