File tree Expand file tree Collapse file tree 3 files changed +45
-26
lines changed
Expand file tree Collapse file tree 3 files changed +45
-26
lines changed Original file line number Diff line number Diff line change 1111//===----------------------------------------------------------------------===//
1212
1313import LanguageServerProtocol
14+ import SKLogging
1415import SKTestSupport
1516import XCTest
1617
@@ -42,18 +43,21 @@ final class DependencyTrackingTests: XCTestCase {
4243
4344 _ = try project. openDocument ( " LibB.swift " )
4445
45- let initialDiags = try await project . testClient . nextDiagnosticsNotification ( )
46- // Semantic analysis: expect module import error .
47- XCTAssertEqual ( initialDiags . diagnostics . count , 1 )
48- if let diagnostic = initialDiags . diagnostics . first {
46+ // Once we have build settings for the file, we should get an error about `LibA` not existing (background
47+ // preparation is disabled). Before that, we might get empty syntactic diagnostics .
48+ try await repeatUntilExpectedResult {
49+ let initialDiags = try ? await project . testClient . nextDiagnosticsNotification ( timeout : . seconds ( 1 ) )
4950 #if compiler(>=6.1)
5051 #warning("When we drop support for Swift 5.10 we no longer need to check for the Objective-C error message")
5152 #endif
52- XCTAssert (
53+ if let diagnostic = initialDiags ? . diagnostics . only ,
5354 diagnostic. message. contains ( " Could not build Objective-C module " )
54- || diagnostic. message. contains ( " No such module " ) ,
55- " expected module import error but found \" \( diagnostic. message) \" "
56- )
55+ || diagnostic. message. contains ( " No such module " )
56+ {
57+ return true
58+ }
59+ logger. debug ( " Received unexpected diagnostics: \( initialDiags? . forLogging) " )
60+ return false
5761 }
5862
5963 try await SwiftPMTestProject . build ( at: project. scratchDirectory)
Original file line number Diff line number Diff line change 1111//===----------------------------------------------------------------------===//
1212
1313import LanguageServerProtocol
14+ import SKLogging
1415import SKTestSupport
1516import XCTest
1617
@@ -180,15 +181,22 @@ final class PublishDiagnosticsTests: XCTestCase {
180181 )
181182
182183 _ = try project. openDocument ( " LibB.swift " )
183- let diagnosticsBeforeBuilding = try await project. testClient. nextDiagnosticsNotification ( )
184- XCTAssert (
185- diagnosticsBeforeBuilding. diagnostics. contains ( where: {
186- #if compiler(>=6.1)
187- #warning("When we drop support for Swift 5.10 we no longer need to check for the Objective-C error message")
188- #endif
184+
185+ // We might receive empty syntactic diagnostics before getting build settings. Wait until we get the diagnostic
186+ // about the missing module.
187+ try await repeatUntilExpectedResult {
188+ let diagnosticsBeforeBuilding = try ? await project. testClient. nextDiagnosticsNotification ( timeout: . seconds( 1 ) )
189+ #if compiler(>=6.1)
190+ #warning("When we drop support for Swift 5.10 we no longer need to check for the Objective-C error message")
191+ #endif
192+ if ( diagnosticsBeforeBuilding? . diagnostics ?? [ ] ) . contains ( where: {
189193 return $0. message == " No such module 'LibA' " || $0. message == " Could not build Objective-C module 'LibA' "
190- } )
191- )
194+ } ) {
195+ return true
196+ }
197+ logger. debug ( " Received unexpected diagnostics: \( diagnosticsBeforeBuilding? . forLogging) " )
198+ return false
199+ }
192200
193201 try await SwiftPMTestProject . build ( at: project. scratchDirectory)
194202
Original file line number Diff line number Diff line change 1111//===----------------------------------------------------------------------===//
1212
1313import LanguageServerProtocol
14+ import SKLogging
1415import SKSupport
1516import SKTestSupport
1617import SourceKitLSP
@@ -204,18 +205,24 @@ final class PullDiagnosticsTests: XCTestCase {
204205 )
205206
206207 let ( bUri, _) = try project. openDocument ( " LibB.swift " )
207- let beforeBuilding = try await project. testClient. send (
208- DocumentDiagnosticsRequest ( textDocument: TextDocumentIdentifier ( bUri) )
209- )
210- XCTAssert (
211- ( beforeBuilding. fullReport? . items ?? [ ] ) . contains ( where: {
212- #if compiler(>=6.1)
213- #warning("When we drop support for Swift 5.10 we no longer need to check for the Objective-C error message")
214- #endif
208+
209+ // We might receive empty syntactic diagnostics before getting build settings. Wait until we get the diagnostic
210+ // about the missing module.
211+ try await repeatUntilExpectedResult {
212+ let beforeBuilding = try ? await project. testClient. send (
213+ DocumentDiagnosticsRequest ( textDocument: TextDocumentIdentifier ( bUri) )
214+ )
215+ #if compiler(>=6.1)
216+ #warning("When we drop support for Swift 5.10 we no longer need to check for the Objective-C error message")
217+ #endif
218+ if ( beforeBuilding? . fullReport? . items ?? [ ] ) . contains ( where: {
215219 return $0. message == " No such module 'LibA' " || $0. message == " Could not build Objective-C module 'LibA' "
220+ } ) {
221+ return true
216222 }
217- )
218- )
223+ logger. debug ( " Received unexpected diagnostics: \( beforeBuilding? . forLogging) " )
224+ return false
225+ }
219226
220227 let diagnosticsRefreshRequestReceived = self . expectation ( description: " DiagnosticsRefreshRequest received " )
221228 project. testClient. handleSingleRequest { ( request: DiagnosticsRefreshRequest ) in
You can’t perform that action at this time.
0 commit comments