Skip to content

Commit 0fc785f

Browse files
committed
feat(harness): Allow Box, Arc Cases
1 parent ba228ff commit 0fc785f

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed

crates/libtest2-harness/src/case.rs

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,44 @@ pub trait Case: Send + Sync + 'static {
1515
fn run(&self, state: &TestContext) -> Result<(), RunError>;
1616
}
1717

18+
impl Case for Box<dyn Case> {
19+
fn name(&self) -> &str {
20+
self.as_ref().name()
21+
}
22+
fn kind(&self) -> TestKind {
23+
self.as_ref().kind()
24+
}
25+
fn source(&self) -> Option<&Source> {
26+
self.as_ref().source()
27+
}
28+
fn exclusive(&self, state: &TestContext) -> bool {
29+
self.as_ref().exclusive(state)
30+
}
31+
32+
fn run(&self, state: &TestContext) -> Result<(), RunError> {
33+
self.as_ref().run(state)
34+
}
35+
}
36+
37+
impl Case for std::sync::Arc<dyn Case> {
38+
fn name(&self) -> &str {
39+
self.as_ref().name()
40+
}
41+
fn kind(&self) -> TestKind {
42+
self.as_ref().kind()
43+
}
44+
fn source(&self) -> Option<&Source> {
45+
self.as_ref().source()
46+
}
47+
fn exclusive(&self, state: &TestContext) -> bool {
48+
self.as_ref().exclusive(state)
49+
}
50+
51+
fn run(&self, state: &TestContext) -> Result<(), RunError> {
52+
self.as_ref().run(state)
53+
}
54+
}
55+
1856
/// Type of the test according to the [rust book](https://doc.rust-lang.org/cargo/guide/tests.html)
1957
/// conventions.
2058
#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)]

0 commit comments

Comments
 (0)