未验证 提交 ced90cb6 编写于 作者: S Sam Harwell 提交者: GitHub

Merge pull request #34361 from sharwell/fix-editorconfig-tests

Updated wait operations to fix unreliable .editorconfig integration tests
......@@ -197,6 +197,12 @@ class C
MarkupTestFile.GetSpans(markup, out var text, out ImmutableArray<TextSpan> spans);
SetUpEditor(markup);
VisualStudio.WaitForApplicationIdle(CancellationToken.None);
VisualStudio.Workspace.WaitForAllAsyncOperations(
Helper.HangMitigatingTimeout,
FeatureAttribute.Workspace,
FeatureAttribute.SolutionCrawler,
FeatureAttribute.DiagnosticService,
FeatureAttribute.ErrorSquiggles);
VisualStudio.Editor.Verify.CodeActionsNotShowing();
var editorConfig = @"root = true
......@@ -205,7 +211,15 @@ class C
csharp_style_expression_bodied_properties = true:warning
";
VisualStudio.SolutionExplorer.AddFile(new ProjectUtils.Project(ProjectName), ".editorconfig", editorConfig, open: false);
VisualStudio.SolutionExplorer.BeginWatchForCodingConventionsChange(new ProjectUtils.Project(ProjectName), "Class1.cs");
try
{
VisualStudio.SolutionExplorer.AddFile(new ProjectUtils.Project(ProjectName), ".editorconfig", editorConfig, open: false);
}
finally
{
VisualStudio.SolutionExplorer.EndWaitForCodingConventionsChange(Helper.HangMitigatingTimeout);
}
// Wait for CodingConventions library events to propagate to the workspace
VisualStudio.WaitForApplicationIdle(CancellationToken.None);
......@@ -213,7 +227,8 @@ class C
Helper.HangMitigatingTimeout,
FeatureAttribute.Workspace,
FeatureAttribute.SolutionCrawler,
FeatureAttribute.DiagnosticService);
FeatureAttribute.DiagnosticService,
FeatureAttribute.ErrorSquiggles);
VisualStudio.Editor.InvokeCodeActionList();
VisualStudio.Editor.Verify.CodeAction(
"Use expression body for properties",
......@@ -229,7 +244,15 @@ class C
* outcome for the modified .editorconfig style.
*/
VisualStudio.SolutionExplorer.SetFileContents(new ProjectUtils.Project(ProjectName), ".editorconfig", editorConfig.Replace("true:warning", "false:warning"));
VisualStudio.SolutionExplorer.BeginWatchForCodingConventionsChange(new ProjectUtils.Project(ProjectName), "Class1.cs");
try
{
VisualStudio.SolutionExplorer.SetFileContents(new ProjectUtils.Project(ProjectName), ".editorconfig", editorConfig.Replace("true:warning", "false:warning"));
}
finally
{
VisualStudio.SolutionExplorer.EndWaitForCodingConventionsChange(Helper.HangMitigatingTimeout);
}
// Wait for CodingConventions library events to propagate to the workspace
VisualStudio.WaitForApplicationIdle(CancellationToken.None);
......@@ -237,7 +260,8 @@ class C
Helper.HangMitigatingTimeout,
FeatureAttribute.Workspace,
FeatureAttribute.SolutionCrawler,
FeatureAttribute.DiagnosticService);
FeatureAttribute.DiagnosticService,
FeatureAttribute.ErrorSquiggles);
VisualStudio.Editor.InvokeCodeActionList();
VisualStudio.Editor.Verify.CodeAction(
"Use block body for properties",
......
......@@ -317,7 +317,8 @@ public int X1
Helper.HangMitigatingTimeout,
FeatureAttribute.Workspace,
FeatureAttribute.SolutionCrawler,
FeatureAttribute.DiagnosticService);
FeatureAttribute.DiagnosticService,
FeatureAttribute.ErrorSquiggles);
VisualStudio.Editor.FormatDocumentViaCommand();
Assert.Equal(expectedTextFourSpaceIndent, VisualStudio.Editor.GetText());
......@@ -333,7 +334,15 @@ public int X1
indent_size = 2
";
VisualStudio.SolutionExplorer.AddFile(new ProjectUtils.Project(ProjectName), ".editorconfig", editorConfig, open: false);
VisualStudio.SolutionExplorer.BeginWatchForCodingConventionsChange(new ProjectUtils.Project(ProjectName), "Class1.cs");
try
{
VisualStudio.SolutionExplorer.AddFile(new ProjectUtils.Project(ProjectName), ".editorconfig", editorConfig, open: false);
}
finally
{
VisualStudio.SolutionExplorer.EndWaitForCodingConventionsChange(Helper.HangMitigatingTimeout);
}
// Wait for CodingConventions library events to propagate to the workspace
VisualStudio.WaitForApplicationIdle(CancellationToken.None);
......@@ -341,7 +350,8 @@ public int X1
Helper.HangMitigatingTimeout,
FeatureAttribute.Workspace,
FeatureAttribute.SolutionCrawler,
FeatureAttribute.DiagnosticService);
FeatureAttribute.DiagnosticService,
FeatureAttribute.ErrorSquiggles);
VisualStudio.Editor.FormatDocumentViaCommand();
Assert.Equal(expectedTextTwoSpaceIndent, VisualStudio.Editor.GetText());
......@@ -351,7 +361,15 @@ public int X1
* and verifies that the next Format Document operation adheres to the updated formatting.
*/
VisualStudio.SolutionExplorer.SetFileContents(new ProjectUtils.Project(ProjectName), ".editorconfig", editorConfig.Replace("2", "4"));
VisualStudio.SolutionExplorer.BeginWatchForCodingConventionsChange(new ProjectUtils.Project(ProjectName), "Class1.cs");
try
{
VisualStudio.SolutionExplorer.SetFileContents(new ProjectUtils.Project(ProjectName), ".editorconfig", editorConfig.Replace("2", "4"));
}
finally
{
VisualStudio.SolutionExplorer.EndWaitForCodingConventionsChange(Helper.HangMitigatingTimeout);
}
// Wait for CodingConventions library events to propagate to the workspace
VisualStudio.WaitForApplicationIdle(CancellationToken.None);
......@@ -359,7 +377,8 @@ public int X1
Helper.HangMitigatingTimeout,
FeatureAttribute.Workspace,
FeatureAttribute.SolutionCrawler,
FeatureAttribute.DiagnosticService);
FeatureAttribute.DiagnosticService,
FeatureAttribute.ErrorSquiggles);
VisualStudio.Editor.FormatDocumentViaCommand();
Assert.Equal(expectedTextFourSpaceIndent, VisualStudio.Editor.GetText());
......
......@@ -7,11 +7,13 @@
using System.Linq;
using System.Runtime.InteropServices;
using System.Threading;
using System.Threading.Tasks;
using System.Xml.Linq;
using EnvDTE80;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.EditAndContinue;
using Microsoft.CodeAnalysis.Shared.TestHooks;
using Microsoft.VisualStudio.CodingConventions;
using Microsoft.VisualStudio.IntegrationTest.Utilities.Input;
using Microsoft.VisualStudio.ProjectSystem.Properties;
using Microsoft.VisualStudio.Shell;
......@@ -21,6 +23,7 @@
using NuGet.SolutionRestoreManager;
using Roslyn.Hosting.Diagnostics.Waiters;
using VSLangProj;
using Task = System.Threading.Tasks.Task;
namespace Microsoft.VisualStudio.IntegrationTest.Utilities.InProcess
{
......@@ -1113,5 +1116,43 @@ public string[] GetChildrenOfItemAtPath(params string[] path)
return null;
}
private CodingConventionsChangedWatcher _codingConventionsChangedWatcher;
public void BeginWatchForCodingConventionsChange(string projectName, string relativeFilePath)
{
var filePath = GetAbsolutePathForProjectRelativeFilePath(projectName, relativeFilePath);
_codingConventionsChangedWatcher = new CodingConventionsChangedWatcher(filePath);
}
public void EndWaitForCodingConventionsChange(TimeSpan timeout)
{
var watcher = Interlocked.Exchange(ref _codingConventionsChangedWatcher, null);
if (watcher is null)
{
throw new InvalidOperationException();
}
watcher.Changed.Wait(timeout);
}
private class CodingConventionsChangedWatcher
{
private readonly TaskCompletionSource<object> _taskCompletionSource = new TaskCompletionSource<object>();
private readonly ICodingConventionContext _codingConventionContext;
public CodingConventionsChangedWatcher(string filePath)
{
var codingConventionsManager = GetComponentModelService<ICodingConventionsManager>();
_codingConventionContext = codingConventionsManager.GetConventionContextAsync(filePath, CancellationToken.None).Result;
_codingConventionContext.CodingConventionsChangedAsync += (sender, e) =>
{
_taskCompletionSource.SetResult(null);
return Task.CompletedTask;
};
}
public Task Changed => _taskCompletionSource.Task;
}
}
}
......@@ -39,6 +39,7 @@
<PackageReference Include="EnvDTE" Version="$(EnvDTEVersion)" />
<PackageReference Include="EnvDTE80" Version="$(EnvDTE80Version)" />
<PackageReference Include="VSLangProj" Version="$(VSLangProjVersion)" />
<PackageReference Include="Microsoft.VisualStudio.CodingConventions" Version="$(MicrosoftVisualStudioCodingConventionsVersion)" />
<PackageReference Include="Microsoft.VisualStudio.CoreUtility" Version="$(MicrosoftVisualStudioCoreUtilityVersion)" />
<PackageReference Include="Microsoft.VisualStudio.InteractiveWindow" Version="$(MicrosoftVisualStudioInteractiveWindowVersion)" />
<PackageReference Include="Microsoft.VisualStudio.Language" Version="$(MicrosoftVisualStudioLanguageVersion)" />
......
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using System.Xml.Linq;
using Microsoft.CodeAnalysis.Shared.TestHooks;
using Microsoft.VisualStudio.IntegrationTest.Utilities.InProcess;
......@@ -199,5 +200,11 @@ public void EditProjectFile(ProjectUtils.Project project)
public void AddStandaloneFile(string fileName)
=> _inProc.AddStandaloneFile(fileName);
public void BeginWatchForCodingConventionsChange(ProjectUtils.Project project, string fileName)
=> _inProc.BeginWatchForCodingConventionsChange(project.Name, fileName);
public void EndWaitForCodingConventionsChange(TimeSpan timeout)
=> _inProc.EndWaitForCodingConventionsChange(timeout);
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册