Skip to content

Relax testMainFileChangesIfIncludeIsAdded to allow clangd to return diagnostics from old build settings #1372

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 14 additions & 4 deletions Tests/SourceKitLSPTests/MainFilesProviderTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -214,9 +214,19 @@ final class MainFilesProviderTests: XCTestCase {

// 'MyFancyLibrary.c' now also includes 'shared.h'. Since it lexicographically preceeds MyLibrary, we should use its
// build settings.
let postEditDiags = try await project.testClient.nextDiagnosticsNotification()
XCTAssertEqual(postEditDiags.diagnostics.count, 1)
let postEditDiag = try XCTUnwrap(postEditDiags.diagnostics.first)
XCTAssertEqual(postEditDiag.message, "Unused variable 'fromMyFancyLibrary'")
// `clangd` may return diagnostics from the old build settings sometimes (I believe when it's still building the
// preamble for shared.h when the new build settings come in). Check that it eventually returns the correct
// diagnostics.
var receivedCorrectDiagnostic = false
for _ in 0..<Int(defaultTimeout) {
let refreshedDiags = try await project.testClient.nextDiagnosticsNotification(timeout: 1)
if let diagnostic = refreshedDiags.diagnostics.only,
diagnostic.message == "Unused variable 'fromMyFancyLibrary'"
{
receivedCorrectDiagnostic = true
break
}
}
XCTAssert(receivedCorrectDiagnostic)
}
}