4
4
#![ allow( clippy:: integer_arithmetic) ]
5
5
6
6
use crate :: { utils, Result } ;
7
+ use camino:: { Utf8Path , Utf8PathBuf } ;
7
8
use libtest_mimic:: { Arguments , Trial } ;
8
- use std:: path:: Path ;
9
9
10
10
#[ doc( hidden) ]
11
11
pub fn runner ( requirements : & [ Requirements ] ) {
@@ -19,18 +19,18 @@ pub fn runner(requirements: &[Requirements]) {
19
19
20
20
#[ doc( hidden) ]
21
21
pub struct Requirements {
22
- test : fn ( & Path ) -> Result < ( ) > ,
22
+ test : fn ( & Utf8Path ) -> Result < ( ) > ,
23
23
test_name : String ,
24
- root : String ,
24
+ root : Utf8PathBuf ,
25
25
pattern : String ,
26
26
}
27
27
28
28
impl Requirements {
29
29
#[ doc( hidden) ]
30
30
pub fn new (
31
- test : fn ( & Path ) -> Result < ( ) > ,
31
+ test : fn ( & Utf8Path ) -> Result < ( ) > ,
32
32
test_name : String ,
33
- root : String ,
33
+ root : Utf8PathBuf ,
34
34
pattern : String ,
35
35
) -> Self {
36
36
Self {
@@ -44,17 +44,15 @@ impl Requirements {
44
44
/// Scans all files in a given directory, finds matching ones and generates a test descriptor
45
45
/// for each of them.
46
46
fn expand ( & self ) -> Vec < Trial > {
47
- let root = Path :: new ( & self . root ) . to_path_buf ( ) ;
48
-
49
47
let re = regex:: Regex :: new ( & self . pattern )
50
48
. unwrap_or_else ( |_| panic ! ( "invalid regular expression: '{}'" , self . pattern) ) ;
51
49
52
- let tests: Vec < _ > = utils:: iterate_directory ( & root)
53
- . filter_map ( |path | {
54
- let input_path = path . to_string_lossy ( ) ;
55
- if re. is_match ( & input_path ) {
50
+ let tests: Vec < _ > = utils:: iterate_directory ( & self . root )
51
+ . filter_map ( |path_res | {
52
+ let path = path_res . expect ( "error while iterating directory" ) ;
53
+ if re. is_match ( path . as_str ( ) ) {
56
54
let testfn = self . test ;
57
- let name = utils:: derive_test_name ( & root, & path, & self . test_name ) ;
55
+ let name = utils:: derive_test_name ( & self . root , & path, & self . test_name ) ;
58
56
Some ( Trial :: test ( name, move || {
59
57
( testfn) ( & path) . map_err ( |err| format ! ( "{:?}" , err) . into ( ) )
60
58
} ) )
0 commit comments