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 11
11
//===----------------------------------------------------------------------===//
12
12
13
13
import LanguageServerProtocol
14
+ import SKLogging
14
15
import SKTestSupport
15
16
import XCTest
16
17
@@ -42,18 +43,21 @@ final class DependencyTrackingTests: XCTestCase {
42
43
43
44
_ = try project. openDocument ( " LibB.swift " )
44
45
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 ) )
49
50
#if compiler(>=6.1)
50
51
#warning("When we drop support for Swift 5.10 we no longer need to check for the Objective-C error message")
51
52
#endif
52
- XCTAssert (
53
+ if let diagnostic = initialDiags ? . diagnostics . only ,
53
54
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
57
61
}
58
62
59
63
try await SwiftPMTestProject . build ( at: project. scratchDirectory)
Original file line number Diff line number Diff line change 11
11
//===----------------------------------------------------------------------===//
12
12
13
13
import LanguageServerProtocol
14
+ import SKLogging
14
15
import SKTestSupport
15
16
import XCTest
16
17
@@ -180,15 +181,22 @@ final class PublishDiagnosticsTests: XCTestCase {
180
181
)
181
182
182
183
_ = 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: {
189
193
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
+ }
192
200
193
201
try await SwiftPMTestProject . build ( at: project. scratchDirectory)
194
202
Original file line number Diff line number Diff line change 11
11
//===----------------------------------------------------------------------===//
12
12
13
13
import LanguageServerProtocol
14
+ import SKLogging
14
15
import SKSupport
15
16
import SKTestSupport
16
17
import SourceKitLSP
@@ -204,18 +205,24 @@ final class PullDiagnosticsTests: XCTestCase {
204
205
)
205
206
206
207
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: {
215
219
return $0. message == " No such module 'LibA' " || $0. message == " Could not build Objective-C module 'LibA' "
220
+ } ) {
221
+ return true
216
222
}
217
- )
218
- )
223
+ logger. debug ( " Received unexpected diagnostics: \( beforeBuilding? . forLogging) " )
224
+ return false
225
+ }
219
226
220
227
let diagnosticsRefreshRequestReceived = self . expectation ( description: " DiagnosticsRefreshRequest received " )
221
228
project. testClient. handleSingleRequest { ( request: DiagnosticsRefreshRequest ) in
You can’t perform that action at this time.
0 commit comments