Skip to content

Commit

Permalink
READY(proper_path_tools): tests fix (#1425)
Browse files Browse the repository at this point in the history
* tests fix

* fixed fmt
  • Loading branch information
Sakapoi authored Aug 30, 2024
1 parent 47408cc commit ba1a066
Show file tree
Hide file tree
Showing 8 changed files with 39 additions and 10 deletions.
1 change: 1 addition & 0 deletions module/core/proper_path_tools/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ mod_interface!

#[ cfg( feature = "path_utf8" ) ]
own use ::camino::{ Utf8Path, Utf8PathBuf };
#[ cfg( not( feature = "no_std" ) ) ]
own use ::std::path::{ PathBuf, Path };

}
5 changes: 4 additions & 1 deletion module/core/proper_path_tools/src/path/absolute_path.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,11 @@ mod private
},
};

#[cfg(feature="no_std")]
#[ cfg( feature="no_std" ) ]
extern crate std;

#[ cfg( feature="no_std" ) ]
use alloc::string::String;

#[ cfg( feature = "derive_serde" ) ]
use serde::{ Serialize, Deserialize };
Expand Down
5 changes: 4 additions & 1 deletion module/core/proper_path_tools/src/path/canonical_path.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,12 @@ mod private
},
};

#[cfg(feature="no_std")]
#[ cfg( feature="no_std" ) ]
extern crate std;

#[ cfg( feature="no_std" ) ]
use alloc::string::String;

#[ cfg( feature = "derive_serde" ) ]
use serde::{ Serialize, Deserialize };

Expand Down
10 changes: 9 additions & 1 deletion module/core/proper_path_tools/src/path/current_path.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,18 @@ mod private
{

use crate::*;
#[ cfg( not( feature = "no_std" ) ) ]
use std::env;

/// Symbolize current path.
#[ derive( Clone, Copy, Debug, Default, PartialEq, Eq ) ]
pub struct CurrentPath;

#[ cfg( feature = "path_utf8" ) ]
#[ cfg( not( feature = "no_std" ) ) ]
impl TryFrom< CurrentPath > for Utf8PathBuf
{
#[ cfg( not( feature = "no_std" ) ) ]
type Error = std::io::Error;

#[ inline ]
Expand All @@ -22,6 +25,7 @@ mod private
(
| err |
{
#[ cfg( not( feature = "no_std" ) ) ]
std::io::Error::new
(
std::io::ErrorKind::NotFound,
Expand All @@ -32,8 +36,10 @@ mod private
}
}

#[ cfg( not( feature = "no_std" ) ) ]
impl TryFrom< CurrentPath > for PathBuf
{
#[ cfg( not( feature = "no_std" ) ) ]
type Error = std::io::Error;

#[ inline ]
Expand All @@ -42,9 +48,11 @@ mod private
env::current_dir()
}
}


#[ cfg( not( feature = "no_std" ) ) ]
impl TryFrom< CurrentPath > for AbsolutePath
{
#[ cfg( not( feature = "no_std" ) ) ]
type Error = std::io::Error;

#[ inline ]
Expand Down
5 changes: 4 additions & 1 deletion module/core/proper_path_tools/src/path/native_path.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,12 @@ mod private
},
};

#[cfg(feature="no_std")]
#[ cfg( feature="no_std" ) ]
extern crate std;

#[ cfg( feature="no_std" ) ]
use alloc::string::String;

#[ cfg( feature = "derive_serde" ) ]
use serde::{ Serialize, Deserialize };

Expand Down
8 changes: 8 additions & 0 deletions module/core/proper_path_tools/tests/inc/absolute_path.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
#[ allow( unused_imports ) ]
use super::*;

#[ cfg( not( feature="no_std" ) ) ]
use the_module::
{
AbsolutePath,
Path,
PathBuf,
};

#[ cfg( feature="no_std" ) ]
use crate::the_module::AbsolutePath;

// #[ cfg( feature = "path_utf8" ) ]
// use the_module::Utf8PathBuf;

Expand Down Expand Up @@ -37,6 +41,7 @@ fn test_to_string_lossy_hard()
}

#[test]
#[ cfg( not( feature="no_std" ) ) ]
fn test_try_from_pathbuf()
{

Expand All @@ -46,6 +51,7 @@ fn test_try_from_pathbuf()
}

#[test]
#[ cfg( not( feature="no_std" ) ) ]
fn test_try_from_path()
{
let path = Path::new( "/path/to/some/file.txt" );
Expand Down Expand Up @@ -79,6 +85,7 @@ fn test_relative_path_try_from_str()
}

#[test]
#[ cfg( not( feature="no_std" ) ) ]
fn test_relative_path_try_from_pathbuf()
{
let rel_path_buf = PathBuf::from( "src/main.rs" );
Expand All @@ -87,6 +94,7 @@ fn test_relative_path_try_from_pathbuf()
}

#[test]
#[ cfg( not( feature="no_std" ) ) ]
fn test_relative_path_try_from_path()
{
let rel_path = Path::new( "src/main.rs" );
Expand Down
3 changes: 3 additions & 0 deletions module/core/proper_path_tools/tests/inc/current_path.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#[ allow( unused_imports ) ]
use super::*;

#[ cfg( not( feature="no_std" ) ) ]
use the_module::
{
AbsolutePath,
Expand All @@ -12,6 +13,7 @@ use the_module::
use the_module::Utf8PathBuf;

#[ test ]
#[ cfg( not( feature="no_std" ) ) ]
fn basic()
{

Expand All @@ -24,6 +26,7 @@ fn basic()
println!( "absolute_path : {absolute_path:?}" );

#[ cfg( feature = "path_utf8" ) ]
#[ cfg( not( feature="no_std" ) ) ]
{
let cd = the_module::CurrentPath;
let utf8_path : Utf8PathBuf = cd.try_into().unwrap();
Expand Down
12 changes: 6 additions & 6 deletions module/core/proper_path_tools/tests/inc/path_canonicalize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ use the_module::path;
fn assumptions()
{

assert_eq!( PathBuf::from( "c:/src/" ).is_absolute(), true );
assert_eq!( PathBuf::from( "/c/src/" ).is_absolute(), false );
assert_eq!( PathBuf::from( "/c:/src/" ).is_absolute(), false );
assert_eq!( PathBuf::from( "/c/src/" ).is_absolute(), false );
assert_eq!( PathBuf::from( "c:/src/" ).is_absolute(), false );
assert_eq!( PathBuf::from( "/c/src/" ).is_absolute(), true );
assert_eq!( PathBuf::from( "/c:/src/" ).is_absolute(), true );
assert_eq!( PathBuf::from( "/c/src/" ).is_absolute(), true );

}

Expand All @@ -23,11 +23,11 @@ fn basic()
assert_eq!( got.unwrap(), exp );

let got = path::canonicalize( PathBuf::from( "\\src" ) );
let exp = PathBuf::from( "/src" );
let exp = PathBuf::from( "\\src" );
assert_eq!( got.unwrap(), exp );

let got = path::canonicalize( PathBuf::from( "\\src\\" ) );
let exp = PathBuf::from( "/src/" );
let exp = PathBuf::from( "\\src\\" );
assert_eq!( got.unwrap(), exp );

let got = path::canonicalize( PathBuf::from( "/src" ) );
Expand Down

0 comments on commit ba1a066

Please sign in to comment.