diff --git a/Tests/CryptoTests/Utils/RFCVector.swift b/Tests/CryptoTests/Utils/RFCVector.swift index edf5540c2..ea582b32a 100644 --- a/Tests/CryptoTests/Utils/RFCVector.swift +++ b/Tests/CryptoTests/Utils/RFCVector.swift @@ -29,8 +29,22 @@ struct RFCVectorDecoder { let bundle = Bundle(for: type(of: bundleType)) let fileURL = bundle.url(forResource: fileName, withExtension: "txt") #else - let testsDirectory: String = URL(fileURLWithPath: "\(#file)").pathComponents.dropLast(3).joined(separator: "/") - let fileURL: URL? = URL(fileURLWithPath: "\(testsDirectory)/Test Vectors/\(fileName).txt") + var fileURL: URL? = URL(fileURLWithPath: "\(#file)") + for _ in 0..<3 { + fileURL!.deleteLastPathComponent() + } + #if compiler(>=6.0) + if #available(macOS 13, iOS 16, watchOS 9, tvOS 16, visionOS 1, macCatalyst 16, *) { + fileURL!.append(path: "Test Vectors", directoryHint: .isDirectory) + fileURL!.append(path: "\(fileName).txt", directoryHint: .notDirectory) + } else { + fileURL! = fileURL!.appendingPathComponent("Test Vectors", isDirectory: true) + fileURL! = fileURL!.appendingPathComponent("\(fileName).txt", isDirectory: false) + } + #else + fileURL! = fileURL!.appendingPathComponent("Test Vectors", isDirectory: true) + fileURL! = fileURL!.appendingPathComponent("\(fileName).txt", isDirectory: false) + #endif #endif let rfcVectorData = try Data(contentsOf: fileURL!) diff --git a/Tests/CryptoTests/Utils/Wycheproof.swift b/Tests/CryptoTests/Utils/Wycheproof.swift index f599ab7aa..a40fe0439 100644 --- a/Tests/CryptoTests/Utils/Wycheproof.swift +++ b/Tests/CryptoTests/Utils/Wycheproof.swift @@ -25,8 +25,22 @@ extension XCTestCase { let bundle = Bundle(for: type(of: bundleType)) let fileURL = bundle.url(forResource: jsonName, withExtension: "json") #else - let testsDirectory: String = URL(fileURLWithPath: "\(#file)").pathComponents.dropLast(3).joined(separator: "/") - let fileURL: URL? = URL(fileURLWithPath: "\(testsDirectory)/Test Vectors/\(jsonName).json") + var fileURL = URL(fileURLWithPath: "\(#file)") + for _ in 0..<3 { + fileURL.deleteLastPathComponent() + } + #if compiler(>=6.0) + if #available(macOS 13, iOS 16, watchOS 9, tvOS 16, visionOS 1, macCatalyst 16, *) { + fileURL.append(path: "Test Vectors", directoryHint: .isDirectory) + fileURL.append(path: "\(jsonName).json", directoryHint: .notDirectory) + } else { + fileURL = fileURL.appendingPathComponent("Test Vectors", isDirectory: true) + fileURL = fileURL.appendingPathComponent("\(jsonName).json", isDirectory: false) + } + #else + fileURL = fileURL.appendingPathComponent("Test Vectors", isDirectory: true) + fileURL = fileURL.appendingPathComponent("\(jsonName).json", isDirectory: false) + #endif #endif let data = try orFail(file: file, line: line) { try Data(contentsOf: unwrap(fileURL, file: file, line: line)) } diff --git a/Tests/_CryptoExtrasTests/Utils/RFCVector.swift b/Tests/_CryptoExtrasTests/Utils/RFCVector.swift index 2684a51c0..c7d8df7e9 100644 --- a/Tests/_CryptoExtrasTests/Utils/RFCVector.swift +++ b/Tests/_CryptoExtrasTests/Utils/RFCVector.swift @@ -25,8 +25,22 @@ struct RFCVectorDecoder { private var index: Int? init(bundleType: AnyObject, fileName: String) throws { - let testsDirectory: String = URL(fileURLWithPath: "\(#file)").pathComponents.dropLast(3).joined(separator: "/") - let fileURL: URL? = URL(fileURLWithPath: "\(testsDirectory)/_CryptoExtrasVectors/\(fileName).txt") + var fileURL: URL? = URL(fileURLWithPath: "\(#file)") + for _ in 0..<3 { + fileURL!.deleteLastPathComponent() + } + #if compiler(>=6.0) + if #available(macOS 13, iOS 16, watchOS 9, tvOS 16, visionOS 1, macCatalyst 16, *) { + fileURL!.append(path: "_CryptoExtrasVectors", directoryHint: .isDirectory) + fileURL!.append(path: "\(fileName).txt", directoryHint: .notDirectory) + } else { + fileURL! = fileURL!.appendingPathComponent("_CryptoExtrasVectors", isDirectory: true) + fileURL! = fileURL!.appendingPathComponent("\(fileName).txt", isDirectory: false) + } + #else + fileURL! = fileURL!.appendingPathComponent("_CryptoExtrasVectors", isDirectory: true) + fileURL! = fileURL!.appendingPathComponent("\(fileName).txt", isDirectory: false) + #endif let rfcVectorData = try Data(contentsOf: fileURL!) self.rfcVectorData = String(decoding: rfcVectorData, as: Unicode.UTF8.self) diff --git a/Tests/_CryptoExtrasTests/Utils/Wycheproof.swift b/Tests/_CryptoExtrasTests/Utils/Wycheproof.swift index 838a9a8bd..42d9e8c95 100644 --- a/Tests/_CryptoExtrasTests/Utils/Wycheproof.swift +++ b/Tests/_CryptoExtrasTests/Utils/Wycheproof.swift @@ -21,10 +21,24 @@ struct WycheproofTest: Codable { extension XCTestCase { func wycheproofTest(jsonName: String, file: StaticString = #file, line: UInt = #line, testFunction: (T) throws -> Void) throws { - let testsDirectory: String = URL(fileURLWithPath: "\(#file)").pathComponents.dropLast(3).joined(separator: "/") - let fileURL: URL? = URL(fileURLWithPath: "\(testsDirectory)/_CryptoExtrasVectors/\(jsonName).json") + var fileURL = URL(fileURLWithPath: "\(#file)") + for _ in 0..<3 { + fileURL.deleteLastPathComponent() + } + #if compiler(>=6.0) + if #available(macOS 13, iOS 16, watchOS 9, tvOS 16, visionOS 1, macCatalyst 16, *) { + fileURL.append(path: "_CryptoExtrasVectors", directoryHint: .isDirectory) + fileURL.append(path: "\(jsonName).json", directoryHint: .notDirectory) + } else { + fileURL = fileURL.appendingPathComponent("_CryptoExtrasVectors", isDirectory: true) + fileURL = fileURL.appendingPathComponent("\(jsonName).json", isDirectory: false) + } + #else + fileURL = fileURL.appendingPathComponent("_CryptoExtrasVectors", isDirectory: true) + fileURL = fileURL.appendingPathComponent("\(jsonName).json", isDirectory: false) + #endif - let data = try Data(contentsOf: fileURL!) + let data = try Data(contentsOf: fileURL) let decoder = JSONDecoder() let wpTest = try decoder.decode(WycheproofTest.self, from: data)