File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -8,22 +8,17 @@ pub struct Harness {
88}
99
1010impl Harness {
11- pub fn with_args ( args : impl IntoIterator < Item = impl Into < std:: ffi:: OsString > > ) -> Self {
12- let raw = expand_args ( args) ;
13- Self { raw, cases : vec ! [ ] }
14- }
15-
1611 pub fn with_env ( ) -> Self {
1712 let raw = std:: env:: args_os ( ) ;
18- let raw = expand_args ( raw) ;
19- Self { raw, cases : vec ! [ ] }
13+ Self :: with_args ( raw)
2014 }
2115
22- pub fn case ( & mut self , case : impl Case + ' static ) {
23- self . cases . push ( Box :: new ( case) ) ;
16+ pub fn with_args ( args : impl IntoIterator < Item = impl Into < std:: ffi:: OsString > > ) -> Self {
17+ let raw = expand_args ( args) ;
18+ Self { raw, cases : vec ! [ ] }
2419 }
2520
26- pub fn cases ( & mut self , cases : impl IntoIterator < Item = impl Case + ' static > ) {
21+ pub fn discover ( & mut self , cases : impl IntoIterator < Item = impl Case + ' static > ) {
2722 for case in cases {
2823 self . cases . push ( Box :: new ( case) ) ;
2924 }
Original file line number Diff line number Diff line change @@ -5,11 +5,13 @@ use libtest2_mimic::Trial;
55
66fn main ( ) {
77 libtest2_mimic:: Harness :: with_env ( )
8- . case ( Trial :: test ( "check_toph" , check_toph) )
9- . case ( Trial :: test ( "check_katara" , check_katara) )
10- . case ( Trial :: test ( "check_sokka" , check_sokka) )
11- . case ( Trial :: test ( "long_computation" , long_computation) )
12- . case ( Trial :: test ( "compile_fail_dummy" , compile_fail_dummy) )
8+ . discover ( [
9+ Trial :: test ( "check_toph" , check_toph) ,
10+ Trial :: test ( "check_katara" , check_katara) ,
11+ Trial :: test ( "check_sokka" , check_sokka) ,
12+ Trial :: test ( "long_computation" , long_computation) ,
13+ Trial :: test ( "compile_fail_dummy" , compile_fail_dummy) ,
14+ ] )
1315 . main ( ) ;
1416}
1517
Original file line number Diff line number Diff line change @@ -4,7 +4,7 @@ use libtest2_mimic::Trial;
44
55fn main ( ) -> std:: io:: Result < ( ) > {
66 let tests = collect_tests ( ) ?;
7- libtest2_mimic:: Harness :: with_env ( ) . cases ( tests) . main ( )
7+ libtest2_mimic:: Harness :: with_env ( ) . discover ( tests) . main ( )
88}
99
1010/// Creates one test for each `.rs` file in the current directory or
Original file line number Diff line number Diff line change @@ -43,14 +43,9 @@ impl Harness {
4343 }
4444 }
4545
46- pub fn case ( mut self , case : Trial ) -> Self {
47- self . harness . case ( TrialCase { inner : case } ) ;
48- self
49- }
50-
51- pub fn cases ( mut self , cases : impl IntoIterator < Item = Trial > ) -> Self {
46+ pub fn discover ( mut self , cases : impl IntoIterator < Item = Trial > ) -> Self {
5247 self . harness
53- . cases ( cases. into_iter ( ) . map ( |c| TrialCase { inner : c } ) ) ;
48+ . discover ( cases. into_iter ( ) . map ( |c| TrialCase { inner : c } ) ) ;
5449 self
5550 }
5651
Original file line number Diff line number Diff line change @@ -10,7 +10,7 @@ fn test_cmd() -> snapbox::cmd::Command {
1010fn main() {
1111 use libtest2_mimic::Trial;
1212 libtest2_mimic::Harness::with_env()
13- .cases(vec! [
13+ .discover( [
1414 Trial::test("foo", |_| Ok(())),
1515 Trial::test("bar", |_| Ok(())),
1616 Trial::test("barro", |_| Ok(())),
Original file line number Diff line number Diff line change @@ -11,7 +11,7 @@ fn main() {
1111 use libtest2_mimic::Trial;
1212 use libtest2_mimic::RunError;
1313 libtest2_mimic::Harness::with_env()
14- .cases(vec! [
14+ .discover( [
1515 Trial::test("one", |_| Ok(())),
1616 Trial::test("two", |_| Ok(())),
1717 Trial::test("three", |_| Ok(())),
Original file line number Diff line number Diff line change @@ -8,7 +8,7 @@ fn main() {
88 use libtest2_mimic::Trial;
99 let outer_thread = std::thread::current().id();
1010 libtest2_mimic::Harness::with_env()
11- .cases(vec! [
11+ .discover( [
1212 Trial::test("check", move |_| {
1313 assert_eq!(outer_thread, std::thread::current().id());
1414 Ok(())
Original file line number Diff line number Diff line change @@ -11,7 +11,7 @@ fn main() {
1111 use libtest2_mimic::Trial;
1212 use libtest2_mimic::RunError;
1313 libtest2_mimic::Harness::with_env()
14- .cases(vec! [
14+ .discover( [
1515 Trial::test("cat", |_| Ok(())),
1616 Trial::test("dog", |_| Err(RunError::fail("was not a good boy"))),
1717 Trial::test("fox", |_| Ok(())),
Original file line number Diff line number Diff line change @@ -10,7 +10,7 @@ fn test_cmd() -> snapbox::cmd::Command {
1010fn main() {
1111 use libtest2_mimic::Trial;
1212 libtest2_mimic::Harness::with_env()
13- .cases(vec! [
13+ .discover( [
1414 Trial::test("passes", |_| Ok(())),
1515 Trial::test("panics", |_| panic!("uh oh")),
1616 ])
Original file line number Diff line number Diff line change @@ -5,7 +5,7 @@ use libtest2::Trial;
55fn main ( ) -> std:: io:: Result < ( ) > {
66 let tests = collect_tests ( ) ?;
77 let mut harness = libtest2:: Harness :: with_env ( ) ;
8- harness. cases ( tests) ;
8+ harness. discover ( tests) ;
99 harness. main ( )
1010}
1111
You can’t perform that action at this time.
0 commit comments