@@ -28,41 +28,45 @@ impl Settings {
2828 /// # Returns
2929 ///
3030 /// The program settings as a `Settings` struct or an error if the file is invalid
31- pub fn from_path < P : AsRef < Path > > ( model_dir : P ) -> Result < Settings > {
32- let file_path = model_dir . as_ref ( ) . join ( SETTINGS_FILE_NAME ) ;
31+ pub fn load ( ) -> Result < Settings > {
32+ let file_path = Path :: new ( SETTINGS_FILE_NAME ) ;
3333 if !file_path. is_file ( ) {
3434 return Ok ( Settings :: default ( ) ) ;
3535 }
3636
37- read_toml ( & file_path)
37+ read_toml ( file_path)
3838 }
3939}
4040
4141#[ cfg( test) ]
4242mod tests {
4343 use super :: * ;
44+ use current_dir:: Cwd ;
4445 use std:: fs:: File ;
4546 use std:: io:: Write ;
4647 use tempfile:: tempdir;
4748
4849 #[ test]
4950 fn test_settings_from_path_no_file ( ) {
5051 let dir = tempdir ( ) . unwrap ( ) ;
51- assert_eq ! (
52- Settings :: from_path( dir. path( ) ) . unwrap( ) ,
53- Settings :: default ( )
54- ) ;
52+ let mut cwd = Cwd :: mutex ( ) . lock ( ) . unwrap ( ) ;
53+ cwd. set ( dir. path ( ) ) . unwrap ( ) ;
54+ assert_eq ! ( Settings :: load( ) . unwrap( ) , Settings :: default ( ) ) ;
5555 }
5656
5757 #[ test]
5858 fn test_settings_from_path ( ) {
5959 let dir = tempdir ( ) . unwrap ( ) ;
60+ let mut cwd = Cwd :: mutex ( ) . lock ( ) . unwrap ( ) ;
61+ cwd. set ( dir. path ( ) ) . unwrap ( ) ;
62+
6063 {
61- let mut file = File :: create ( dir . path ( ) . join ( SETTINGS_FILE_NAME ) ) . unwrap ( ) ;
64+ let mut file = File :: create ( Path :: new ( SETTINGS_FILE_NAME ) ) . unwrap ( ) ;
6265 writeln ! ( file, "log_level = \" warn\" " ) . unwrap ( ) ;
6366 }
67+
6468 assert_eq ! (
65- Settings :: from_path ( dir . path ( ) ) . unwrap( ) ,
69+ Settings :: load ( ) . unwrap( ) ,
6670 Settings {
6771 log_level: Some ( "warn" . to_string( ) ) ,
6872 debug_model: false
0 commit comments