@@ -103,11 +103,35 @@ mod tests {
103103 use super :: { deduplicate_arguments, remove_items_from_vec_by_indices, Api } ;
104104 use maplit:: hashset;
105105 use normalize_path:: NormalizePath ;
106+ use pipe_trait:: Pipe ;
106107 use pretty_assertions:: assert_eq;
107108 use std:: { collections:: HashSet , convert:: Infallible , path:: PathBuf } ;
108109
109110 const MOCKED_CURRENT_DIR : & str = "/home/user/current-dir" ;
110111
112+ const MOCKED_SYMLINKS : & [ ( & str , & str ) ] = & [
113+ ( "/home/usr/current-dir/link-to-current-dir" , "." ) ,
114+ ( "/home/usr/current-dir/link-to-parent-dir" , ".." ) ,
115+ ( "/home/usr/current-dir/link-to-root" , "/" ) ,
116+ ( "/home/usr/current-dir/link-to-bin" , "/usr/bin" ) ,
117+ ( "/home/usr/current-dir/link-to-foo" , "foo" ) ,
118+ ( "/home/usr/current-dir/link-to-bar" , "bar" ) ,
119+ ( "/home/usr/current-dir/link-to-012" , "0/1/2" ) ,
120+ ] ;
121+
122+ fn resolve_symlink ( absolute_path : PathBuf ) -> PathBuf {
123+ assert ! ( absolute_path. is_absolute( ) ) ;
124+ for & ( link_path, link_target) in MOCKED_SYMLINKS {
125+ if let Ok ( suffix) = absolute_path. strip_prefix ( link_path) {
126+ return link_target
127+ . pipe ( PathBuf :: from)
128+ . join ( suffix)
129+ . pipe ( resolve_symlink) ;
130+ }
131+ }
132+ absolute_path
133+ }
134+
111135 /// Mocked implementation of [`Api`] for testing purposes.
112136 struct MockedApi ;
113137 impl Api for MockedApi {
@@ -116,16 +140,12 @@ mod tests {
116140 type RealPathError = Infallible ;
117141
118142 fn canonicalize ( path : & Self :: Argument ) -> Result < Self :: RealPath , Self :: RealPathError > {
119- Ok ( match * path {
120- "link-to-current-dir" => Self :: canonicalize ( & "." ) ?,
121- "link-to-parent-dir" => Self :: canonicalize ( & ".." ) ?,
122- "link-to-root" => PathBuf :: from ( "/" ) ,
123- "link-to-bin" => PathBuf :: from ( "/usr/bin" ) ,
124- "link-to-foo" => Self :: canonicalize ( & "foo" ) ?,
125- "link-to-bar" => Self :: canonicalize ( & "bar" ) ?,
126- "link-to-012" => Self :: canonicalize ( & "0/1/2" ) ?,
127- _ => PathBuf :: from ( MOCKED_CURRENT_DIR ) . join ( path) . normalize ( ) ,
128- } )
143+ MOCKED_CURRENT_DIR
144+ . pipe ( PathBuf :: from)
145+ . join ( path)
146+ . normalize ( )
147+ . pipe ( resolve_symlink)
148+ . pipe ( Ok )
129149 }
130150
131151 fn starts_with ( a : & Self :: RealPath , b : & Self :: RealPath ) -> bool {
0 commit comments