|
| 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 | + |
| 11 | +import TSCBasic |
| 12 | +import XCTest |
| 13 | + |
| 14 | +@testable import PackageLoading |
| 15 | + |
| 16 | +class MinimumDeploymentTargetTests: XCTestCase { |
| 17 | +#if os(macOS) // these tests eventually call `xcrun`. |
| 18 | + func testDoesNotAssertWithNoOutput() throws { |
| 19 | + let result = ProcessResult(arguments: [], |
| 20 | + environment: [:], |
| 21 | + exitStatus: .terminated(code: 0), |
| 22 | + output: "".asResult, |
| 23 | + stderrOutput: "xcodebuild: error: SDK \"macosx\" cannot be located.".asResult) |
| 24 | + |
| 25 | + XCTAssertNil(try MinimumDeploymentTarget.computeXCTestMinimumDeploymentTarget(with: result)) |
| 26 | + } |
| 27 | + |
| 28 | + func testThrowsWithNonPathOutput() throws { |
| 29 | + let result = ProcessResult(arguments: [], |
| 30 | + environment: [:], |
| 31 | + exitStatus: .terminated(code: 0), |
| 32 | + output: "some string".asResult, |
| 33 | + stderrOutput: "".asResult) |
| 34 | + |
| 35 | + XCTAssertThrowsError(try MinimumDeploymentTarget.computeXCTestMinimumDeploymentTarget(with: result)) |
| 36 | + } |
| 37 | + |
| 38 | + func testThrowsWithErrorForOutput() throws { |
| 39 | + let result = ProcessResult(arguments: [], |
| 40 | + environment: [:], |
| 41 | + exitStatus: .terminated(code: 0), |
| 42 | + output: .failure(DummyError()), |
| 43 | + stderrOutput: "".asResult) |
| 44 | + |
| 45 | + XCTAssertThrowsError(try MinimumDeploymentTarget.computeXCTestMinimumDeploymentTarget(with: result)) |
| 46 | + } |
| 47 | +#endif |
| 48 | +} |
| 49 | + |
| 50 | +private struct DummyError: Error { |
| 51 | +} |
| 52 | + |
| 53 | +private extension String { |
| 54 | + var asResult: Result<[UInt8], Error> { |
| 55 | + return .success(Array(utf8)) |
| 56 | + } |
| 57 | +} |
0 commit comments