From de25052c7270006c60ea257b4d0e65ff36f17fbf Mon Sep 17 00:00:00 2001 From: mustiikhalil <26250654+mustiikhalil@users.noreply.github.com> Date: Wed, 29 Oct 2025 19:36:47 +0100 Subject: [PATCH] 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:) --- .../FlatBuffersMonsterWriterTests.swift | 31 ++++++++++--------- 1 file changed, 16 insertions(+), 15 deletions(-) diff --git a/tests/swift/Tests/Flatbuffers/FlatBuffersMonsterWriterTests.swift b/tests/swift/Tests/Flatbuffers/FlatBuffersMonsterWriterTests.swift index 386298e2e..580307c78 100644 --- a/tests/swift/Tests/Flatbuffers/FlatBuffersMonsterWriterTests.swift +++ b/tests/swift/Tests/Flatbuffers/FlatBuffersMonsterWriterTests.swift @@ -48,10 +48,24 @@ class FlatBuffersMonsterWriterTests: XCTestCase { } func testReadFromOtherLanguages() { - let url = URL(fileURLWithPath: path, isDirectory: true) + let path = { + #if os(macOS) + // Gets the current path of this test file then + // strips out the nested directories. + let filePath = URL(filePath: #file) + .deletingLastPathComponent() + return filePath.absoluteString + #else + return FileManager.default.currentDirectoryPath + .appending("/tests/swift/Tests/Flatbuffers") + #endif + }() + + let url = URL(string: path)! .appendingPathComponent("monsterdata_test") .appendingPathExtension("mon") - let data = try! Data(contentsOf: url) + + let data = FileManager.default.contents(atPath: url.path)! let _data = ByteBuffer(data: data) readVerifiedMonster(fb: _data) @@ -646,19 +660,6 @@ class FlatBuffersMonsterWriterTests: XCTestCase { """ } - private var path: String { - #if os(macOS) - // Gets the current path of this test file then - // strips out the nested directories. - let filePath = URL(filePath: #file) - .deletingLastPathComponent() - return filePath.absoluteString - #else - return FileManager.default.currentDirectoryPath - .appending("/tests/swift/Tests/Flatbuffers") - #endif - } - func testContiguousBytes() { let byteArray: [UInt8] = [3, 1, 4, 1, 5, 9] var fbb = FlatBufferBuilder(initialSize: 1)