File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ use libtest2:: Case ;
12use libtest2:: FnCase ;
23use libtest2:: RunError ;
34use libtest2:: RunResult ;
@@ -23,8 +24,8 @@ fn main() -> std::io::Result<()> {
2324
2425/// Creates one test for each `.rs` file in the current directory or
2526/// sub-directories of the current directory.
26- fn collect_tests ( ) -> std:: io:: Result < Vec < FnCase > > {
27- fn visit_dir ( path : & std:: path:: Path , tests : & mut Vec < FnCase > ) -> std:: io:: Result < ( ) > {
27+ fn collect_tests ( ) -> std:: io:: Result < Vec < Box < dyn Case > > > {
28+ fn visit_dir ( path : & std:: path:: Path , tests : & mut Vec < Box < dyn Case > > ) -> std:: io:: Result < ( ) > {
2829 let current_dir = std:: env:: current_dir ( ) ?;
2930 for entry in std:: fs:: read_dir ( path) ? {
3031 let entry = entry?;
@@ -45,7 +46,7 @@ fn collect_tests() -> std::io::Result<Vec<FnCase>> {
4546 . into_owned ( ) ;
4647
4748 let test = FnCase :: test ( name, move |_| check_file ( & path) ) ;
48- tests. push ( test) ;
49+ tests. push ( Box :: new ( test) ) ;
4950 }
5051 } else if file_type. is_dir ( ) {
5152 // Handle directories
Original file line number Diff line number Diff line change @@ -27,25 +27,27 @@ impl Case for DynCase {
2727 }
2828}
2929
30- pub struct FnCase {
30+ pub struct FnCase < R > {
3131 name : String ,
32- #[ allow( clippy:: type_complexity) ]
33- runner : Box < dyn Fn ( & TestContext ) -> RunResult + Send + Sync > ,
32+ runner : R ,
3433}
3534
36- impl FnCase {
37- pub fn test (
38- name : impl Into < String > ,
39- runner : impl Fn ( & TestContext ) -> RunResult + Send + Sync + ' static ,
40- ) -> Self {
35+ impl < R > FnCase < R >
36+ where
37+ R : Fn ( & TestContext ) -> RunResult + Send + Sync + ' static ,
38+ {
39+ pub fn test ( name : impl Into < String > , runner : R ) -> Self {
4140 Self {
4241 name : name. into ( ) ,
43- runner : Box :: new ( runner ) ,
42+ runner,
4443 }
4544 }
4645}
4746
48- impl Case for FnCase {
47+ impl < R > Case for FnCase < R >
48+ where
49+ R : Fn ( & TestContext ) -> RunResult + Send + Sync + ' static ,
50+ {
4951 fn name ( & self ) -> & str {
5052 & self . name
5153 }
Original file line number Diff line number Diff line change @@ -59,7 +59,6 @@ pub mod panic;
5959pub mod _private {
6060 pub use distributed_list:: push;
6161 pub use distributed_list:: DistributedList ;
62- pub use libtest2_harness:: Case ;
6362 pub use libtest2_harness:: Source ;
6463 pub use libtest2_harness:: TestKind ;
6564
@@ -72,6 +71,7 @@ pub mod _private {
7271
7372pub use case:: main;
7473pub use case:: FnCase ;
74+ pub use libtest2_harness:: Case ;
7575pub use libtest2_harness:: IntoRunResult ;
7676pub use libtest2_harness:: RunError ;
7777pub use libtest2_harness:: RunResult ;
Original file line number Diff line number Diff line change @@ -106,7 +106,7 @@ macro_rules! _test_parse {
106106 #[ allow( non_camel_case_types) ]
107107 struct $name;
108108
109- impl $crate:: _private :: Case for $name {
109+ impl $crate:: Case for $name {
110110 fn name( & self ) -> & str {
111111 $crate:: _private:: push!( crate :: TESTS , _: $crate:: _private:: DynCase = $crate:: _private:: DynCase ( & $name) ) ;
112112
You can’t perform that action at this time.
0 commit comments