|
| 1 | +/* |
| 2 | + This source file is part of the Swift.org open source project |
| 3 | + |
| 4 | + Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors |
| 5 | + Licensed under Apache License v2.0 with Runtime Library Exception |
| 6 | + |
| 7 | + See http://swift.org/LICENSE.txt for license information |
| 8 | + See http://swift.org/CONTRIBUTORS.txt for Swift project authors |
| 9 | + */ |
| 10 | +import XCTest |
| 11 | + |
| 12 | +import PackageGraph |
| 13 | +import TSCBasic |
| 14 | +import struct TSCUtility.Version |
| 15 | + |
| 16 | +public struct MockDependencyGraph { |
| 17 | + public let name: String |
| 18 | + public let constraints: [MockPackageConstraint] |
| 19 | + public let containers: [MockPackageContainer] |
| 20 | + public let result: [String: Version] |
| 21 | + |
| 22 | + public init(_ json: JSON) { |
| 23 | + guard case .dictionary(let dict) = json else { fatalError() } |
| 24 | + guard case .string(let name)? = dict["name"] else { fatalError() } |
| 25 | + guard case .array(let constraints)? = dict["constraints"] else { fatalError() } |
| 26 | + guard case .array(let containers)? = dict["containers"] else { fatalError() } |
| 27 | + guard case .dictionary(let result)? = dict["result"] else { fatalError() } |
| 28 | + |
| 29 | + self.result = Dictionary(uniqueKeysWithValues: result.map { value in |
| 30 | + let (container, version) = value |
| 31 | + guard case .string(let str) = version else { fatalError() } |
| 32 | + return (container.lowercased(), Version(string: str)!) |
| 33 | + }) |
| 34 | + self.name = name |
| 35 | + self.constraints = constraints.map(PackageContainerConstraint.init(json:)) |
| 36 | + self.containers = containers.map(MockPackageContainer.init(json:)) |
| 37 | + } |
| 38 | + |
| 39 | + public func checkResult( |
| 40 | + _ output: [(container: String, version: Version)], |
| 41 | + file: StaticString = #file, |
| 42 | + line: UInt = #line |
| 43 | + ) { |
| 44 | + var result = self.result |
| 45 | + for item in output { |
| 46 | + XCTAssertEqual(result[item.container], item.version, file: file, line: line) |
| 47 | + result[item.container] = nil |
| 48 | + } |
| 49 | + if !result.isEmpty { |
| 50 | + XCTFail("Unchecked containers: \(result)", file: file, line: line) |
| 51 | + } |
| 52 | + } |
| 53 | +} |
0 commit comments