@@ -152,16 +152,27 @@ final class CompilationDatabaseTests: XCTestCase {
152152 )
153153 }
154154
155- func testJSONCompilationDatabaseLookup( ) {
155+ func testJSONCompilationDatabaseLookup( ) throws {
156+ #if os(Windows)
157+ let fileSystemRoot = " c:/ "
158+ #else
159+ let fileSystemRoot = " / "
160+ #endif
161+
156162 let cmd1 = CompilationDatabase . Command ( directory: " a " , filename: " b " , commandLine: [ ] , output: nil )
157- let cmd2 = CompilationDatabase . Command ( directory: " /c " , filename: " b " , commandLine: [ ] , output: nil )
158- let cmd3 = CompilationDatabase . Command ( directory: " /c " , filename: " /b " , commandLine: [ ] , output: nil )
163+ let cmd2 = CompilationDatabase . Command ( directory: " \( fileSystemRoot) c " , filename: " b " , commandLine: [ ] , output: nil )
164+ let cmd3 = CompilationDatabase . Command (
165+ directory: " \( fileSystemRoot) c " ,
166+ filename: " \( fileSystemRoot) b " ,
167+ commandLine: [ ] ,
168+ output: nil
169+ )
159170
160171 let db = JSONCompilationDatabase ( [ cmd1, cmd2, cmd3] )
161172
162173 XCTAssertEqual ( db [ DocumentURI ( filePath: " b " , isDirectory: false ) ] , [ cmd1] )
163- XCTAssertEqual ( db [ DocumentURI ( filePath: " / c/b" , isDirectory: false ) ] , [ cmd2] )
164- XCTAssertEqual ( db [ DocumentURI ( filePath: " / b" , isDirectory: false ) ] , [ cmd3] )
174+ XCTAssertEqual ( db [ DocumentURI ( filePath: " \( fileSystemRoot ) c/b " , isDirectory: false ) ] , [ cmd2] )
175+ XCTAssertEqual ( db [ DocumentURI ( filePath: " \( fileSystemRoot ) b " , isDirectory: false ) ] , [ cmd3] )
165176 }
166177
167178 func testJSONCompilationDatabaseFromDirectory( ) throws {
@@ -250,19 +261,16 @@ final class CompilationDatabaseTests: XCTestCase {
250261 """
251262 )
252263
253- let db = try tryLoadCompilationDatabase (
254- directory: AbsolutePath ( validating: " /a " ) ,
255- fs
256- )
257- XCTAssertNotNil ( db)
264+ let db = try XCTUnwrap ( tryLoadCompilationDatabase ( directory: AbsolutePath ( validating: " /a " ) , fs) )
258265
266+ // Note: Use `AbsolutePath(validating:).pathString` to normalize forward slashes to backslashes on Windows
259267 XCTAssertEqual (
260- db! [ DocumentURI ( filePath: " /a/b " , isDirectory: false ) ] ,
268+ db [ DocumentURI ( filePath: " /a/b " , isDirectory: false ) ] ,
261269 [
262270 CompilationDatabase . Command (
263271 directory: try AbsolutePath ( validating: " /a " ) . pathString,
264- filename: " /a/b " ,
265- commandLine: [ " clang " , " -xc++ " , " -I " , " libwidget/include/ " , " /a/b " ] ,
272+ filename: try AbsolutePath ( validating : " /a/b " ) . pathString ,
273+ commandLine: [ " clang " , " -xc++ " , " -I " , " libwidget/include/ " , try AbsolutePath ( validating : " /a/b " ) . pathString ] ,
266274 output: nil
267275 )
268276 ]
0 commit comments