@@ -6,7 +6,7 @@ use camino::{Utf8Component, Utf8Path, Utf8PathBuf};
6
6
#[ derive( Debug ) ]
7
7
#[ doc( hidden) ]
8
8
pub enum DataSource {
9
- // This is relative to the crate root, and stored with forward slashes .
9
+ // The path has had normalize_slashes applied to it .
10
10
Directory ( Utf8PathBuf ) ,
11
11
#[ cfg( feature = "include-dir" ) ]
12
12
IncludeDir ( std:: borrow:: Cow < ' static , include_dir:: Dir < ' static > > ) ,
@@ -40,7 +40,7 @@ impl DataSource {
40
40
) ;
41
41
match self {
42
42
DataSource :: Directory ( path) => Some ( TestEntry {
43
- source : TestSource :: Path ( rel_path_to_forward_slashes ( & path. join ( & rel_path) ) ) ,
43
+ source : TestSource :: Path ( normalize_slashes ( & path. join ( & rel_path) ) ) ,
44
44
rel_path,
45
45
} ) ,
46
46
#[ cfg( feature = "include-dir" ) ]
@@ -152,7 +152,7 @@ pub(crate) struct TestEntry {
152
152
153
153
impl TestEntry {
154
154
pub ( crate ) fn from_full_path ( root : & Utf8Path , path : Utf8PathBuf ) -> Self {
155
- let path = rel_path_to_forward_slashes ( & path) ;
155
+ let path = normalize_slashes ( & path) ;
156
156
let rel_path =
157
157
rel_path_to_forward_slashes ( path. strip_prefix ( root) . unwrap_or_else ( |_| {
158
158
panic ! ( "failed to strip root '{}' from path '{}'" , root, path)
@@ -241,13 +241,29 @@ impl TestEntry {
241
241
}
242
242
}
243
243
244
+ #[ cfg( windows) ]
245
+ #[ track_caller]
246
+ fn normalize_slashes ( path : & Utf8Path ) -> Utf8PathBuf {
247
+ if is_truly_relative ( path) {
248
+ rel_path_to_forward_slashes ( path)
249
+ } else {
250
+ path. as_str ( ) . replace ( '/' , "\\ " ) . into ( )
251
+ }
252
+ }
253
+
244
254
#[ cfg( windows) ]
245
255
#[ track_caller]
246
256
fn rel_path_to_forward_slashes ( path : & Utf8Path ) -> Utf8PathBuf {
247
257
assert ! ( is_truly_relative( path) , "path {path} must be relative" ) ;
248
258
path. as_str ( ) . replace ( '\\' , "/" ) . into ( )
249
259
}
250
260
261
+ #[ cfg( not( windows) ) ]
262
+ #[ track_caller]
263
+ fn normalize_slashes ( path : & Utf8Path ) -> Utf8PathBuf {
264
+ path. to_owned ( )
265
+ }
266
+
251
267
#[ cfg( not( windows) ) ]
252
268
#[ track_caller]
253
269
fn rel_path_to_forward_slashes ( path : & Utf8Path ) -> Utf8PathBuf {
@@ -309,11 +325,7 @@ pub mod data_source_kinds {
309
325
let s = self . to_string ( ) ;
310
326
let path = Utf8Path :: new ( & s) ;
311
327
312
- if !is_truly_relative ( path) {
313
- panic ! ( "data source path must be relative: '{}'" , s) ;
314
- }
315
-
316
- DataSource :: Directory ( rel_path_to_forward_slashes ( path) )
328
+ DataSource :: Directory ( normalize_slashes ( path) )
317
329
}
318
330
}
319
331
@@ -347,12 +359,6 @@ pub mod data_source_kinds {
347
359
mod tests {
348
360
use super :: * ;
349
361
350
- #[ test]
351
- #[ should_panic = "data source path must be relative: '/absolute/path'" ]
352
- fn data_source_absolute_path_panics ( ) {
353
- data_source_kinds:: AsDirectory :: resolve_data_source ( "/absolute/path" ) ;
354
- }
355
-
356
362
#[ test]
357
363
fn missing_test_name ( ) {
358
364
assert_eq ! ( derive_test_path( "root" . into( ) , "file" , "test_name" ) , None ) ;
0 commit comments