File tree Expand file tree Collapse file tree 4 files changed +18
-15
lines changed Expand file tree Collapse file tree 4 files changed +18
-15
lines changed 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 @@ -55,7 +55,6 @@ mod macros;
5555pub mod _private {
5656 pub use distributed_list:: push;
5757 pub use distributed_list:: DistributedList ;
58- pub use libtest2_harness:: Case ;
5958 pub use libtest2_harness:: Source ;
6059 pub use libtest2_harness:: TestKind ;
6160
@@ -67,6 +66,7 @@ pub mod _private {
6766
6867pub use case:: main;
6968pub use case:: FnCase ;
69+ pub use libtest2_harness:: Case ;
7070pub use libtest2_harness:: IntoRunResult ;
7171pub use libtest2_harness:: RunError ;
7272pub use libtest2_harness:: RunResult ;
Original file line number Diff line number Diff line change @@ -33,7 +33,7 @@ macro_rules! _test_parse {
3333 #[ allow( non_camel_case_types) ]
3434 struct $name;
3535
36- impl $crate:: _private :: Case for $name {
36+ impl $crate:: Case for $name {
3737 fn name( & self ) -> & str {
3838 $crate:: _private:: push!( crate :: TESTS , _: $crate:: _private:: DynCase = $crate:: _private:: DynCase ( & $name) ) ;
3939
You can’t perform that action at this time.
0 commit comments