Skip to content

Commit ac8481f

Browse files
authored
fix(harness)!: Clean up presentation of API (#115)
This is prep for making putting discovery more in the hands of the user
2 parents c181108 + bd412c4 commit ac8481f

11 files changed

Lines changed: 25 additions & 31 deletions

File tree

crates/libtest2-harness/src/harness.rs

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,22 +8,17 @@ pub struct Harness {
88
}
99

1010
impl 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
}

crates/libtest2-mimic/examples/mimic-simple.rs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,13 @@ use libtest2_mimic::Trial;
55

66
fn 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

crates/libtest2-mimic/examples/mimic-tidy.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use libtest2_mimic::Trial;
44

55
fn 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

crates/libtest2-mimic/src/lib.rs

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff 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

crates/libtest2-mimic/tests/testsuite/all_passing.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ fn test_cmd() -> snapbox::cmd::Command {
1010
fn 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(())),

crates/libtest2-mimic/tests/testsuite/argfile.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff 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(())),

crates/libtest2-mimic/tests/testsuite/main_thread.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff 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(())

crates/libtest2-mimic/tests/testsuite/mixed_bag.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff 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(())),

crates/libtest2-mimic/tests/testsuite/panic.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ fn test_cmd() -> snapbox::cmd::Command {
1010
fn 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
])

crates/libtest2/examples/tidy.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use libtest2::Trial;
55
fn 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

0 commit comments

Comments
 (0)