-
-
Notifications
You must be signed in to change notification settings - Fork 506
/
TuistAcceptanceTestCase+Extra.swift
131 lines (120 loc) · 4.28 KB
/
TuistAcceptanceTestCase+Extra.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
import TSCBasic
import TuistSupport
import XcodeProj
import XCTest
extension TuistAcceptanceTestCase {
private func headers(
for productName: String,
destination: String
) throws -> [AbsolutePath] {
let productPath = try productPath(for: productName, destination: destination)
return FileHandler.shared.glob(productPath, glob: "**/*.h")
}
public func productPath(
for name: String,
destination: String
) throws -> AbsolutePath {
try XCTUnwrap(
FileHandler.shared.glob(derivedDataPath, glob: "**/Build/**/Products/\(destination)/\(name)/").first
)
}
public func XCTUnwrapTarget(
_ targetName: String,
in xcodeproj: XcodeProj,
file: StaticString = #file,
line: UInt = #line
) throws -> PBXTarget {
let targets = xcodeproj.pbxproj.projects.flatMap(\.targets)
guard let target = targets.first(where: { $0.name == targetName })
else {
XCTFail(
"Target \(targetName) doesn't exist in any of the projects' targets of the workspace",
file: file,
line: line
)
throw XCTUnwrapError.nilValueDetected
}
return target
}
public func XCTAssertProductWithDestinationDoesNotContainHeaders(
_ product: String,
destination: String,
file: StaticString = #file,
line: UInt = #line
) throws {
if try !headers(for: product, destination: destination).isEmpty {
XCTFail("Product with name \(product) and destination \(destination) contains headers", file: file, line: line)
}
}
public func XCTAssertFrameworkEmbedded(
_ framework: String,
by targetName: String,
file: StaticString = #file,
line: UInt = #line
) throws {
let xcodeproj = try XcodeProj(pathString: xcodeprojPath.pathString)
let target = try XCTUnwrapTarget(targetName, in: xcodeproj)
let xcframeworkDependencies = target.embedFrameworksBuildPhases()
.filter { $0.dstSubfolderSpec == .frameworks }
.map(\.files)
.compactMap { $0 }
.flatMap { $0 }
.compactMap(\.file?.nameOrPath)
.filter { $0.contains(".framework") }
guard xcframeworkDependencies.contains("\(framework).framework")
else {
XCTFail(
"Target \(targetName) doesn't link the framework \(framework)",
file: file,
line: line
)
return
}
}
/// Asserts that a simulated location is contained in a specific testable target.
/// - Parameters:
/// - xcodeprojPath: A specific `.xcodeproj` file path.
/// - scheme: A specific scheme name.
/// - testTarget: A specific test target name.
/// - simulatedLocation: A simulated location. This value can be passed a `location string` or a `GPX filename`.
/// For example, "Rio de Janeiro, Brazil" or "Grand Canyon.gpx".
public func XCTAssertContainsSimulatedLocation(
xcodeprojPath: AbsolutePath,
scheme: String,
testTarget: String,
simulatedLocation: String,
file: StaticString = #file,
line: UInt = #line
) throws {
let xcodeproj = try XcodeProj(pathString: xcodeprojPath.pathString)
guard let scheme = xcodeproj.sharedData?.schemes
.filter({ $0.name == scheme })
.first
else {
XCTFail(
"The '\(scheme)' scheme doesn't exist.",
file: file,
line: line
)
return
}
guard let testableTarget = scheme.testAction?.testables
.filter({ $0.buildableReference.blueprintName == testTarget })
.first
else {
XCTFail(
"The '\(testTarget)' testable target doesn't exist.",
file: file,
line: line
)
return
}
XCTAssertEqual(
testableTarget.locationScenarioReference?.identifier.contains(simulatedLocation),
true,
"The '\(testableTarget)' testable target doesn't have simulated location set.",
file: file,
line: line
)
}
}