@@ -166,6 +166,8 @@ pub fn collect_file_paths(paths: Vec<String>) -> (Vec<String>, Vec<Errors>) {
166166
167167#[ cfg( test) ]
168168mod tests {
169+ use std:: path:: PathBuf ;
170+
169171 use super :: * ;
170172 use crate :: test_utils:: Context ;
171173
@@ -190,18 +192,21 @@ mod tests {
190192 #[ test]
191193 fn collect_all_documents ( ) {
192194 let context = Context :: new ( ) ;
193- context. touch ( "bar/baz.rb" ) ;
194- context. touch ( "bar/qux.rb" ) ;
195- context. touch ( "foo/bar.rb" ) ;
195+ let baz = Path :: new ( "bar" ) . join ( "baz.rb" ) ;
196+ let qux = Path :: new ( "bar" ) . join ( "qux.rb" ) ;
197+ let bar = Path :: new ( "foo" ) . join ( "bar.rb" ) ;
198+ context. touch ( & baz) ;
199+ context. touch ( & qux) ;
200+ context. touch ( & bar) ;
196201
197202 let ( paths, errors) = collect_document_paths ( & context, & [ "foo" , "bar" ] ) ;
198203
199204 assert_eq ! (
200205 paths,
201206 vec![
202- "bar/ baz.rb" . to_string( ) ,
203- "bar/ qux.rb" . to_string( ) ,
204- "foo/ bar.rb" . to_string( )
207+ baz. to_str ( ) . unwrap ( ) . to_string( ) ,
208+ qux. to_str ( ) . unwrap ( ) . to_string( ) ,
209+ bar. to_str ( ) . unwrap ( ) . to_string( )
205210 ]
206211 ) ;
207212 assert ! ( errors. is_empty( ) ) ;
@@ -210,13 +215,19 @@ mod tests {
210215 #[ test]
211216 fn collect_some_documents_based_on_paths ( ) {
212217 let context = Context :: new ( ) ;
213- context . touch ( "bar/ baz.rb" ) ;
214- context . touch ( "bar/ qux.rb" ) ;
215- context . touch ( "foo/ bar.rb" ) ;
218+ let baz = Path :: new ( "bar" ) . join ( " baz.rb") ;
219+ let qux = Path :: new ( "bar" ) . join ( " qux.rb") ;
220+ let bar = Path :: new ( "foo" ) . join ( " bar.rb") ;
216221
222+ context. touch ( & baz) ;
223+ context. touch ( & qux) ;
224+ context. touch ( & bar) ;
217225 let ( paths, errors) = collect_document_paths ( & context, & [ "bar" ] ) ;
218226
219- assert_eq ! ( paths, vec![ "bar/baz.rb" . to_string( ) , "bar/qux.rb" . to_string( ) ] ) ;
227+ assert_eq ! (
228+ paths,
229+ vec![ baz. to_str( ) . unwrap( ) . to_string( ) , qux. to_str( ) . unwrap( ) . to_string( ) ]
230+ ) ;
220231 assert ! ( errors. is_empty( ) ) ;
221232 }
222233
@@ -239,30 +250,31 @@ mod tests {
239250 . map( std:: string:: ToString :: to_string)
240251 . collect:: <Vec <String >>( ) ,
241252 vec![ format!(
242- "File read error: Path '{}/non_existing_path ' does not exist" ,
243- context. absolute_path ( ) . display( )
253+ "File read error: Path '{}' does not exist" ,
254+ context. absolute_path_to ( "non_existing_path" ) . display( )
244255 ) ]
245256 ) ;
246257 }
247258
248259 #[ test]
249260 fn index_relative_paths ( ) {
261+ let relative_path = Path :: new ( "foo" ) . join ( "bar.rb" ) ;
250262 let context = Context :: new ( ) ;
251- context. touch ( "foo/bar.rb" ) ;
263+ context. touch ( & relative_path ) ;
252264
253265 let working_directory = std:: env:: current_dir ( ) . unwrap ( ) ;
266+ let absolute_path = context. absolute_path_to ( "foo/bar.rb" ) ;
254267
255- let dotdots = "../" . repeat ( working_directory . components ( ) . count ( ) ) ;
268+ let mut dots = PathBuf :: from ( ".." ) ;
256269
257- let relative_path = dotdots
258- + context
259- . absolute_path_to ( "foo/bar.rb" )
260- . to_string_lossy ( )
261- . into_owned ( )
262- . as_str ( ) ;
270+ for _ in 0 ..working_directory. components ( ) . count ( ) - 1 {
271+ dots = dots. join ( ".." ) ;
272+ }
273+
274+ let relative_to_pwd = & dots. join ( absolute_path) ;
263275
264276 let mut graph = Graph :: new ( ) ;
265- let errors = index_in_parallel ( & mut graph, vec ! [ relative_path ] ) ;
277+ let errors = index_in_parallel ( & mut graph, vec ! [ relative_to_pwd . to_str ( ) . unwrap ( ) . to_string ( ) ] ) ;
266278
267279 assert ! ( errors. is_ok( ) ) ;
268280 assert_eq ! ( graph. documents( ) . len( ) , 1 ) ;
0 commit comments