Skip to content

Commit ad057c1

Browse files
committed
fix(test2): Allow const FnCase
1 parent 0336ea1 commit ad057c1

File tree

2 files changed

+6
-7
lines changed

2 files changed

+6
-7
lines changed

crates/libtest2/examples/tidy.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
use std::borrow::Cow;
2+
13
use libtest2::Case;
24
use libtest2::FnCase;
35
use libtest2::RunError;
@@ -45,7 +47,7 @@ fn collect_tests() -> std::io::Result<Vec<Box<dyn Case>>> {
4547
.to_string_lossy()
4648
.into_owned();
4749

48-
let test = FnCase::test(name, move |_| check_file(&path));
50+
let test = FnCase::test(Cow::Owned(name), move |_| check_file(&path));
4951
tests.push(Box::new(test));
5052
}
5153
} else if file_type.is_dir() {

crates/libtest2/src/case.rs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,19 +28,16 @@ impl Case for DynCase {
2828
}
2929

3030
pub struct FnCase<R> {
31-
name: String,
31+
name: std::borrow::Cow<'static, str>,
3232
runner: R,
3333
}
3434

3535
impl<R> FnCase<R>
3636
where
3737
R: Fn(&TestContext) -> RunResult + Send + Sync + 'static,
3838
{
39-
pub fn test(name: impl Into<String>, runner: R) -> Self {
40-
Self {
41-
name: name.into(),
42-
runner,
43-
}
39+
pub const fn test(name: std::borrow::Cow<'static, str>, runner: R) -> Self {
40+
Self { name, runner }
4441
}
4542
}
4643

0 commit comments

Comments
 (0)