Skip to content

Commit f9e7ad4

Browse files
authored
Merge pull request #34 from hartbit/import
Several small improvements necessary for SwiftPM
2 parents 6a93875 + 044fd3f commit f9e7ad4

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

Sources/TSCTestSupport/AssertMatch.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public indirect enum StringPattern {
3232
case or(StringPattern, StringPattern)
3333
}
3434

35-
extension StringPattern: ExpressibleByStringLiteral {
35+
extension StringPattern: ExpressibleByStringInterpolation {
3636
public typealias UnicodeScalarLiteralType = StringLiteralType
3737
public typealias ExtendedGraphemeClusterLiteralType = StringLiteralType
3838

Sources/TSCTestSupport/DiagnosticsEngine.swift

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,4 +61,28 @@ final public class DiagnosticsEngineResult {
6161
XCTAssertEqual(theDiagnostic.message.behavior, behavior, file: file, line: line)
6262
XCTAssertEqual(theDiagnostic.location.description, location, file: file, line: line)
6363
}
64+
65+
public func checkUnordered(
66+
diagnostic diagnosticPattern: StringPattern,
67+
checkContains: Bool = false,
68+
behavior: Diagnostic.Behavior,
69+
location: String? = nil,
70+
file: StaticString = #file,
71+
line: UInt = #line
72+
) {
73+
guard !uncheckedDiagnostics.isEmpty else {
74+
return XCTFail("No diagnostics left to check", file: file, line: line)
75+
}
76+
77+
let locationDescription = location ?? UnknownLocation.location.description
78+
let matchIndex = uncheckedDiagnostics.firstIndex(where: { diagnostic in
79+
diagnosticPattern ~= diagnostic.description &&
80+
diagnostic.message.behavior == behavior &&
81+
diagnostic.location.description == locationDescription
82+
})
83+
84+
if let index = matchIndex {
85+
uncheckedDiagnostics.remove(at: index)
86+
}
87+
}
6488
}

0 commit comments

Comments
 (0)