Skip to content

Commit de25052

Browse files
authored
Fixes failing tests on macOS due to file loading (#8742)
Fixes failing tests due to the usage of URL(fileURLWithPath:isDirectory:) instead of URL(string:)
1 parent 95053e6 commit de25052

File tree

1 file changed

+16
-15
lines changed

1 file changed

+16
-15
lines changed

tests/swift/Tests/Flatbuffers/FlatBuffersMonsterWriterTests.swift

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,24 @@ class FlatBuffersMonsterWriterTests: XCTestCase {
4848
}
4949

5050
func testReadFromOtherLanguages() {
51-
let url = URL(fileURLWithPath: path, isDirectory: true)
51+
let path = {
52+
#if os(macOS)
53+
// Gets the current path of this test file then
54+
// strips out the nested directories.
55+
let filePath = URL(filePath: #file)
56+
.deletingLastPathComponent()
57+
return filePath.absoluteString
58+
#else
59+
return FileManager.default.currentDirectoryPath
60+
.appending("/tests/swift/Tests/Flatbuffers")
61+
#endif
62+
}()
63+
64+
let url = URL(string: path)!
5265
.appendingPathComponent("monsterdata_test")
5366
.appendingPathExtension("mon")
54-
let data = try! Data(contentsOf: url)
67+
68+
let data = FileManager.default.contents(atPath: url.path)!
5569
let _data = ByteBuffer(data: data)
5670

5771
readVerifiedMonster(fb: _data)
@@ -646,19 +660,6 @@ class FlatBuffersMonsterWriterTests: XCTestCase {
646660
"""
647661
}
648662

649-
private var path: String {
650-
#if os(macOS)
651-
// Gets the current path of this test file then
652-
// strips out the nested directories.
653-
let filePath = URL(filePath: #file)
654-
.deletingLastPathComponent()
655-
return filePath.absoluteString
656-
#else
657-
return FileManager.default.currentDirectoryPath
658-
.appending("/tests/swift/Tests/Flatbuffers")
659-
#endif
660-
}
661-
662663
func testContiguousBytes() {
663664
let byteArray: [UInt8] = [3, 1, 4, 1, 5, 9]
664665
var fbb = FlatBufferBuilder(initialSize: 1)

0 commit comments

Comments
 (0)