mirror of
https://github.com/apple/swift-crypto
synced 2026-11-30 05:18:46 +00:00
The test runners for Windows were failing to load the paths from disk
for test vectors. This patch cleans up the loading logic.
(cherry picked from commit 1f483f4240)
51 lines
1.9 KiB
Swift
51 lines
1.9 KiB
Swift
//===----------------------------------------------------------------------===//
|
|
//
|
|
// This source file is part of the SwiftCrypto open source project
|
|
//
|
|
// Copyright (c) 2019-2021 Apple Inc. and the SwiftCrypto project authors
|
|
// Licensed under Apache License v2.0
|
|
//
|
|
// See LICENSE.txt for license information
|
|
// See CONTRIBUTORS.txt for the list of SwiftCrypto project authors
|
|
//
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
import XCTest
|
|
|
|
struct WycheproofTest<T: Codable>: Codable {
|
|
let algorithm: String
|
|
let numberOfTests: UInt32
|
|
let testGroups: [T]
|
|
}
|
|
|
|
extension XCTestCase {
|
|
func wycheproofTest<T: Codable>(jsonName: String, file: StaticString = #file, line: UInt = #line, testFunction: (T) throws -> Void) throws {
|
|
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 decoder = JSONDecoder()
|
|
let wpTest = try decoder.decode(WycheproofTest<T>.self, from: data)
|
|
|
|
for group in wpTest.testGroups {
|
|
try testFunction(group)
|
|
}
|
|
}
|
|
}
|