@@ -53,9 +53,14 @@ impl TestEnvironment {
5353 & [ "config" , "user.email" , "[email protected] " ] , 5454 ) ?;
5555
56- // Create initial commit to establish git history.
56+ // Create initial commit to establish git history, including disabling
57+ // Windows line endings.
58+ workspace_root. child ( ".gitattributes" ) . write_str ( "* -text\n " ) ?;
5759 workspace_root. child ( "README.md" ) . write_str ( "# Test workspace\n " ) ?;
58- Self :: run_git_command ( & workspace_root, & [ "add" , "README.md" ] ) ?;
60+ Self :: run_git_command (
61+ & workspace_root,
62+ & [ "add" , ".gitattributes" , "README.md" ] ,
63+ ) ?;
5964 Self :: run_git_command (
6065 & workspace_root,
6166 & [ "commit" , "-m" , "initial commit" ] ,
@@ -126,14 +131,16 @@ impl TestEnvironment {
126131 api_ident : & str ,
127132 version : & str ,
128133 ) -> bool {
129- // Versioned documents are stored in subdirectories like: documents/api/api-version-hash.json
134+ // Versioned documents are stored in subdirectories like:
135+ // documents/api/api-version-hash.json.
130136 let pattern =
131137 format ! ( "documents/{}/{}-{}-" , api_ident, api_ident, version) ;
132- if let Ok ( files) = self . list_document_files ( ) {
133- files. iter ( ) . any ( |f| f. to_string ( ) . starts_with ( & pattern) )
134- } else {
135- false
136- }
138+ let files = self
139+ . list_document_files ( )
140+ . expect ( "reading document files succeeded" ) ;
141+ files
142+ . iter ( )
143+ . any ( |f| rel_path_forward_slashes ( f. as_ref ( ) ) . starts_with ( & pattern) )
137144 }
138145
139146 /// Read the content of a versioned API document for a specific version.
@@ -149,7 +156,9 @@ impl TestEnvironment {
149156
150157 let matching_file = files
151158 . iter ( )
152- . find ( |f| f. to_string ( ) . starts_with ( & pattern) )
159+ . find ( |f| {
160+ rel_path_forward_slashes ( f. as_ref ( ) ) . starts_with ( & pattern)
161+ } )
153162 . ok_or_else ( || {
154163 anyhow ! (
155164 "No versioned document found for {} version {}" ,
@@ -171,7 +180,9 @@ impl TestEnvironment {
171180
172181 Ok ( files
173182 . into_iter ( )
174- . filter ( |f| f. to_string ( ) . starts_with ( & prefix) )
183+ . filter ( |f| {
184+ rel_path_forward_slashes ( f. as_ref ( ) ) . starts_with ( & prefix)
185+ } )
175186 . collect ( ) )
176187 }
177188
@@ -307,6 +318,16 @@ impl TestEnvironment {
307318 }
308319}
309320
321+ #[ cfg( windows) ]
322+ pub fn rel_path_forward_slashes ( path : & str ) -> String {
323+ path. replace ( '\\' , "/" )
324+ }
325+
326+ #[ cfg( not( windows) ) ]
327+ pub fn rel_path_forward_slashes ( path : & str ) -> String {
328+ path. to_string ( )
329+ }
330+
310331/// Create a versioned health API test configuration.
311332pub fn versioned_health_test_api ( ) -> ManagedApiConfig {
312333 ManagedApiConfig {
0 commit comments