Skip to content

Commit e303360

Browse files
committed
Fix issue where test nondeterministically failed if SwiftPM doesn't return build settings quickly
We might not have build settings at the time when we get the first diagnostics notification here and thus might get syntactic fallback diagnostics that don't contain 'Cannot find ... in scope'
1 parent 8ba80a0 commit e303360

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

Tests/SourceKitLSPTests/PublishDiagnosticsTests.swift

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -137,10 +137,14 @@ final class PublishDiagnosticsTests: XCTestCase {
137137
)
138138

139139
_ = try project.openDocument("FileB.swift")
140-
let diagnosticsBeforeChangingFileA = try await project.testClient.nextDiagnosticsNotification()
141-
XCTAssert(
142-
diagnosticsBeforeChangingFileA.diagnostics.contains(where: { $0.message == "Cannot find 'sayHello' in scope" })
143-
)
140+
try await repeatUntilExpectedResult {
141+
let diagnostics = try await project.testClient.nextDiagnosticsNotification()
142+
if diagnostics.diagnostics.contains(where: { $0.message == "Cannot find 'sayHello' in scope" }) {
143+
return true
144+
}
145+
logger.debug("Received unexpected diagnostics: \(diagnostics.forLogging)")
146+
return false
147+
}
144148

145149
let updatedACode = "func sayHello() {}"
146150
let aUri = try project.uri(for: "FileA.swift")

0 commit comments

Comments
 (0)