From 094eb0c237bd99081b765a63e2a84c5a3a8db307 Mon Sep 17 00:00:00 2001 From: Alex Hoppen Date: Thu, 30 May 2024 19:40:47 -0700 Subject: [PATCH] Relax `testMainFileChangesIfIncludeIsAdded` to allow `clangd` to return diagnostics from old build settings `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 and allow it to return outdated diagnostics for a short while. --- .../MainFilesProviderTests.swift | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/Tests/SourceKitLSPTests/MainFilesProviderTests.swift b/Tests/SourceKitLSPTests/MainFilesProviderTests.swift index 9923bbd47..779c8c05a 100644 --- a/Tests/SourceKitLSPTests/MainFilesProviderTests.swift +++ b/Tests/SourceKitLSPTests/MainFilesProviderTests.swift @@ -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..