Skip to content
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

Rewrite BulidSolution in Integration tests #74690

Merged
merged 1 commit into from
Aug 9, 2024
Merged
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ static void Main(string[] args)

await TestServices.Editor.SetTextAsync(editorText, HangMitigatingCancellationToken);

var buildSummary = await TestServices.SolutionExplorer.BuildSolutionAndWaitAsync(HangMitigatingCancellationToken);
Assert.Equal("========== Build: 1 succeeded, 0 failed, 0 up-to-date, 0 skipped ==========", buildSummary);
var succeed = await TestServices.SolutionExplorer.BuildSolutionAndWaitAsync(HangMitigatingCancellationToken);
Assert.True(succeed);

await TestServices.ErrorList.ShowBuildErrorsAsync(HangMitigatingCancellationToken);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -630,67 +630,27 @@ public async Task<string> GetFileContentsAsync(string projectName, string relati
}

/// <returns>
/// The summary line for the build, which generally looks something like this:
///
/// <code>
/// ========== Build: 1 succeeded, 0 failed, 0 up-to-date, 0 skipped ==========
/// </code>
/// true if build succeeds, otherwise false.
/// </returns>
public async Task<string> BuildSolutionAndWaitAsync(CancellationToken cancellationToken)
public async Task<bool> BuildSolutionAndWaitAsync(CancellationToken cancellationToken)
{
await JoinableTaskFactory.SwitchToMainThreadAsync(cancellationToken);

var buildOutputWindowPane = await GetBuildOutputWindowPaneAsync(cancellationToken);
buildOutputWindowPane.Clear();

var buildManager = await GetRequiredGlobalServiceAsync<SVsSolutionBuildManager, IVsSolutionBuildManager2>(cancellationToken);
using var solutionEvents = new UpdateSolutionEvents(buildManager);
var buildCompleteTaskCompletionSource = new TaskCompletionSource<bool>();

void HandleUpdateSolutionDone() => buildCompleteTaskCompletionSource.SetResult(true);
void HandleUpdateSolutionDone(bool buildSucceed) => buildCompleteTaskCompletionSource.SetResult(buildSucceed);
solutionEvents.OnUpdateSolutionDone += HandleUpdateSolutionDone;
try
{
await TestServices.Shell.ExecuteCommandAsync(VSConstants.VSStd97CmdID.BuildSln, cancellationToken);

await buildCompleteTaskCompletionSource.Task;
ErrorHandler.ThrowOnFailure(buildManager.StartSimpleUpdateSolutionConfiguration((uint)VSSOLNBUILDUPDATEFLAGS.SBF_OPERATION_BUILD, 0, 0));
return await buildCompleteTaskCompletionSource.Task;
}
finally
{
solutionEvents.OnUpdateSolutionDone -= HandleUpdateSolutionDone;
}

// Force the error list to update
ErrorHandler.ThrowOnFailure(buildOutputWindowPane.FlushToTaskList());

var textView = (IVsTextView)buildOutputWindowPane;
var wpfTextViewHost = await textView.GetTextViewHostAsync(JoinableTaskFactory, cancellationToken);
var lines = wpfTextViewHost.TextView.TextViewLines;
if (lines.Count < 1)
{
return string.Empty;
}

// Find the build summary line
for (var index = lines.Count - 1; index >= 0; index--)
{
var lineText = lines[index].Extent.GetText();
if (lineText.StartsWith("========== Build:"))
{
return lineText;
}
}

return string.Empty;
}

public async Task<IVsOutputWindowPane> GetBuildOutputWindowPaneAsync(CancellationToken cancellationToken)
{
await JoinableTaskFactory.SwitchToMainThreadAsync(cancellationToken);

var outputWindow = await GetRequiredGlobalServiceAsync<SVsOutputWindow, IVsOutputWindow>(cancellationToken);
ErrorHandler.ThrowOnFailure(outputWindow.GetPane(VSConstants.OutputWindowPaneGuid.BuildOutputPane_guid, out var pane));
return pane;
}

private static string ConvertLanguageName(string languageName)
Expand Down Expand Up @@ -802,7 +762,7 @@ internal sealed class UpdateSolutionEvents : IVsUpdateSolutionEvents, IDisposabl
private uint _cookie;
private readonly IVsSolutionBuildManager2 _solutionBuildManager;

public event Action? OnUpdateSolutionDone;
public event Action<bool>? OnUpdateSolutionDone;

internal UpdateSolutionEvents(IVsSolutionBuildManager2 solutionBuildManager)
{
Expand All @@ -819,8 +779,9 @@ internal UpdateSolutionEvents(IVsSolutionBuildManager2 solutionBuildManager)

int IVsUpdateSolutionEvents.UpdateSolution_Done(int fSucceeded, int fModified, int fCancelCommand)
{
OnUpdateSolutionDone?.Invoke();
return 0;
var buildSucceeded = fSucceeded == 1;
OnUpdateSolutionDone?.Invoke(buildSucceeded);
return VSConstants.S_OK;
}

void IDisposable.Dispose()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ End Sub

await TestServices.Editor.SetTextAsync(editorText, HangMitigatingCancellationToken);

var buildSummary = await TestServices.SolutionExplorer.BuildSolutionAndWaitAsync(HangMitigatingCancellationToken);
Assert.Equal("========== Build: 1 succeeded, 0 failed, 0 up-to-date, 0 skipped ==========", buildSummary);
var succeed = await TestServices.SolutionExplorer.BuildSolutionAndWaitAsync(HangMitigatingCancellationToken);
Assert.True(succeed);

await TestServices.ErrorList.ShowBuildErrorsAsync(HangMitigatingCancellationToken);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,8 @@ await TestServices.Editor.SetTextAsync(@"Class Class1
await TestServices.SolutionExplorer.CloseActiveWindow(HangMitigatingCancellationToken);

// Build and verify build failure in the output window.
var buildSummary = await TestServices.SolutionExplorer.BuildSolutionAndWaitAsync(HangMitigatingCancellationToken);
Assert.Equal("========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========", buildSummary);
var succeed = await TestServices.SolutionExplorer.BuildSolutionAndWaitAsync(HangMitigatingCancellationToken);
Assert.False(succeed);

await TestServices.Workspace.WaitForAllAsyncOperationsAsync([FeatureAttribute.Workspace, FeatureAttribute.SolutionCrawlerLegacy, FeatureAttribute.DiagnosticService, FeatureAttribute.ErrorSquiggles, FeatureAttribute.ErrorList], HangMitigatingCancellationToken);

Expand Down
Loading