Skip to content

Commit 9a4086d

Browse files
committed
feat(test2): Make RunResult optional
1 parent babfaf5 commit 9a4086d

File tree

8 files changed

+36
-35
lines changed

8 files changed

+36
-35
lines changed

crates/libtest2-harness/src/error.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,3 +64,19 @@ impl std::fmt::Display for Message {
6464
}
6565

6666
impl std::error::Error for Message {}
67+
68+
pub trait IntoRunResult {
69+
fn into_run_result(self) -> RunResult;
70+
}
71+
72+
impl IntoRunResult for () {
73+
fn into_run_result(self) -> RunResult {
74+
Ok(())
75+
}
76+
}
77+
78+
impl IntoRunResult for RunResult {
79+
fn into_run_result(self) -> RunResult {
80+
self
81+
}
82+
}

crates/libtest2/examples/simple.rs

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,24 +8,17 @@ fn main() {}
88
// Tests
99

1010
#[libtest2::test]
11-
fn check_toph(_context: &TestContext) -> RunResult {
12-
Ok(())
13-
}
11+
fn check_toph(_context: &TestContext) {}
1412
#[libtest2::test]
15-
fn check_katara(_context: &TestContext) -> RunResult {
16-
Ok(())
17-
}
13+
fn check_katara(_context: &TestContext) {}
1814
#[libtest2::test]
1915
fn check_sokka(_context: &TestContext) -> RunResult {
2016
Err(RunError::fail("Sokka tripped and fell :("))
2117
}
2218
#[libtest2::test]
2319
#[ignore = "slow"]
24-
fn long_computation(_context: &TestContext) -> RunResult {
20+
fn long_computation(_context: &TestContext) {
2521
std::thread::sleep(std::time::Duration::from_secs(1));
26-
Ok(())
2722
}
2823
#[libtest2::test]
29-
fn compile_fail_dummy(_context: &TestContext) -> RunResult {
30-
Ok(())
31-
}
24+
fn compile_fail_dummy(_context: &TestContext) {}

crates/libtest2/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ pub mod _private {
5151

5252
pub use case::main;
5353
pub use case::FnCase;
54+
pub use libtest2_harness::IntoRunResult;
5455
pub use libtest2_harness::RunError;
5556
pub use libtest2_harness::RunResult;
5657
pub use libtest2_harness::TestContext;

crates/libtest2/src/macros.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,9 @@ macro_rules! _test_parse {
5858
}
5959
)*
6060

61-
run(context)
61+
use $crate::IntoRunResult;
62+
let result = run(context);
63+
IntoRunResult::into_run_result(result)
6264
}
6365
}
6466
};

crates/libtest2/tests/testsuite/all_passing.rs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,18 +11,15 @@ fn test_cmd() -> snapbox::cmd::Command {
1111
fn main() {}
1212
1313
#[libtest2::test]
14-
fn foo(_context: &libtest2::TestContext) -> libtest2::RunResult {
15-
Ok(())
14+
fn foo(_context: &libtest2::TestContext) {
1615
}
1716
1817
#[libtest2::test]
19-
fn bar(_context: &libtest2::TestContext) -> libtest2::RunResult {
20-
Ok(())
18+
fn bar(_context: &libtest2::TestContext) {
2119
}
2220
2321
#[libtest2::test]
24-
fn barro(_context: &libtest2::TestContext) -> libtest2::RunResult {
25-
Ok(())
22+
fn barro(_context: &libtest2::TestContext) {
2623
}
2724
"#,
2825
false,

crates/libtest2/tests/testsuite/argfile.rs

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,23 +11,19 @@ fn test_cmd() -> snapbox::cmd::Command {
1111
fn main() {}
1212
1313
#[libtest2::test]
14-
fn one(_context: &libtest2::TestContext) -> libtest2::RunResult {
15-
Ok(())
14+
fn one(_context: &libtest2::TestContext) {
1615
}
1716
1817
#[libtest2::test]
19-
fn two(_context: &libtest2::TestContext) -> libtest2::RunResult {
20-
Ok(())
18+
fn two(_context: &libtest2::TestContext) {
2119
}
2220
2321
#[libtest2::test]
24-
fn three(_context: &libtest2::TestContext) -> libtest2::RunResult {
25-
Ok(())
22+
fn three(_context: &libtest2::TestContext) {
2623
}
2724
2825
#[libtest2::test]
29-
fn one_two(_context: &libtest2::TestContext) -> libtest2::RunResult {
30-
Ok(())
26+
fn one_two(_context: &libtest2::TestContext) {
3127
}
3228
"#,
3329
false,

crates/libtest2/tests/testsuite/mixed_bag.rs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,7 @@ fn test_cmd() -> snapbox::cmd::Command {
1111
fn main() {}
1212
1313
#[libtest2::test]
14-
fn cat(_context: &libtest2::TestContext) -> libtest2::RunResult {
15-
Ok(())
14+
fn cat(_context: &libtest2::TestContext) {
1615
}
1716
1817
#[libtest2::test]
@@ -21,8 +20,7 @@ fn dog(_context: &libtest2::TestContext) -> libtest2::RunResult {
2120
}
2221
2322
#[libtest2::test]
24-
fn fox(_context: &libtest2::TestContext) -> libtest2::RunResult {
25-
Ok(())
23+
fn fox(_context: &libtest2::TestContext) {
2624
}
2725
2826
#[libtest2::test]
@@ -63,8 +61,7 @@ fn sheep(context: &libtest2::TestContext) -> libtest2::RunResult {
6361
6462
#[libtest2::test]
6563
#[ignore = "slow"]
66-
fn horse(context: &libtest2::TestContext) -> libtest2::RunResult {
67-
Ok(())
64+
fn horse(context: &libtest2::TestContext) {
6865
}
6966
"#,
7067
false,

crates/libtest2/tests/testsuite/panic.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,11 @@ fn test_cmd() -> snapbox::cmd::Command {
1111
fn main() {}
1212
1313
#[libtest2::test]
14-
fn passes(_context: &libtest2::TestContext) -> libtest2::RunResult {
15-
Ok(())
14+
fn passes(_context: &libtest2::TestContext) {
1615
}
1716
1817
#[libtest2::test]
19-
fn panics(_context: &libtest2::TestContext) -> libtest2::RunResult {
18+
fn panics(_context: &libtest2::TestContext) {
2019
panic!("uh oh")
2120
}
2221
"#,

0 commit comments

Comments
 (0)