Skip to content

Commit

Permalink
Use TestHost consistently (#45861)
Browse files Browse the repository at this point in the history
* Use TestHost consistently

* Comments

* Fix

* RenameTestHost

* Renaming
  • Loading branch information
tmat authored Jul 11, 2020
1 parent 21803cb commit 4153950
Show file tree
Hide file tree
Showing 106 changed files with 1,081 additions and 1,062 deletions.
12 changes: 6 additions & 6 deletions src/EditorFeatures/CSharpTest/AddUsing/AddUsingTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@
using Microsoft.CodeAnalysis.Editing;
using Microsoft.CodeAnalysis.Editor.CSharp.UnitTests.Diagnostics;
using Microsoft.CodeAnalysis.Editor.UnitTests.CodeActions;
using Microsoft.CodeAnalysis.Remote.Testing;
using Microsoft.CodeAnalysis.Tags;
using Microsoft.CodeAnalysis.Test.Utilities;
using Microsoft.CodeAnalysis.Test.Utilities.RemoteHost;
using Roslyn.Test.Utilities;
using Xunit;
using static Roslyn.Test.Utilities.TestMetadata;
Expand Down Expand Up @@ -48,8 +48,8 @@ internal async Task TestAsync(
CodeActionPriority? priority = null,
OptionsCollection options = null)
{
await TestAsync(initialMarkup, expectedMarkup, index, priority, options, outOfProcess: false);
await TestAsync(initialMarkup, expectedMarkup, index, priority, options, outOfProcess: true);
await TestAsync(initialMarkup, expectedMarkup, index, priority, options, TestHost.OutOfProcess);
await TestAsync(initialMarkup, expectedMarkup, index, priority, options, TestHost.InProcess);
}

internal async Task TestAsync(
Expand All @@ -58,11 +58,11 @@ internal async Task TestAsync(
int index,
CodeActionPriority? priority,
OptionsCollection options,
bool outOfProcess)
TestHost testHost)
{
await TestInRegularAndScript1Async(
initialMarkup, expectedMarkup, index,
parameters: new TestParameters(options: options, runProviderOutOfProc: outOfProcess, priority: priority));
parameters: new TestParameters(options: options, testHost: testHost, priority: priority));
}
}

Expand All @@ -72,7 +72,7 @@ internal override (DiagnosticAnalyzer, CodeFixProvider) CreateDiagnosticProvider
Workspace workspace, TestParameters parameters)
{
workspace.TryApplyChanges(workspace.CurrentSolution.WithOptions(
workspace.CurrentSolution.Options.WithChangedOption(RemoteHostOptions.RemoteHostTest, parameters.runProviderOutOfProc)));
workspace.CurrentSolution.Options.WithChangedOption(RemoteTestHostOptions.RemoteHostTest, parameters.testHost)));

return base.CreateDiagnosticProviderAndFixer(workspace, parameters);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,26 +5,26 @@
using System.Threading.Tasks;
using Microsoft.CodeAnalysis.Editor.UnitTests.Classification;
using Microsoft.CodeAnalysis.Editor.UnitTests.Workspaces;
using Microsoft.CodeAnalysis.Test.Utilities.RemoteHost;
using Microsoft.CodeAnalysis.Remote.Testing;
using Microsoft.CodeAnalysis.Text;

namespace Microsoft.CodeAnalysis.Editor.CSharp.UnitTests.Classification
{
public abstract class AbstractCSharpClassifierTests : AbstractClassifierTests
{
protected static TestWorkspace CreateWorkspace(string code, ParseOptions options, bool outOfProcess)
protected static TestWorkspace CreateWorkspace(string code, ParseOptions options, TestHost testHost)
{
var workspace = TestWorkspace.CreateCSharp(code, parseOptions: options);
workspace.TryApplyChanges(workspace.CurrentSolution.WithOptions(
workspace.Options.WithChangedOption(RemoteHostOptions.RemoteHostTest, outOfProcess)));
workspace.Options.WithChangedOption(RemoteTestHostOptions.RemoteHostTest, testHost == TestHost.OutOfProcess)));

return workspace;
}

protected override async Task DefaultTestAsync(string code, string allCode, bool outOfProcess, FormattedClassification[] expected)
protected override async Task DefaultTestAsync(string code, string allCode, TestHost testHost, FormattedClassification[] expected)
{
await TestAsync(code, allCode, parseOptions: null, outOfProcess, expected);
await TestAsync(code, allCode, parseOptions: Options.Script, outOfProcess, expected);
await TestAsync(code, allCode, parseOptions: null, testHost, expected);
await TestAsync(code, allCode, parseOptions: Options.Script, testHost, expected);
}

protected override string WrapInClass(string className, string code) =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@
using Microsoft.CodeAnalysis.Editor.UnitTests;
using Microsoft.CodeAnalysis.Editor.UnitTests.Workspaces;
using Microsoft.CodeAnalysis.Notification;
using Microsoft.CodeAnalysis.Remote.Testing;
using Microsoft.CodeAnalysis.Shared.Extensions;
using Microsoft.CodeAnalysis.Shared.TestHooks;
using Microsoft.CodeAnalysis.Test.Utilities;
using Microsoft.CodeAnalysis.Test.Utilities.RemoteHost;
using Microsoft.CodeAnalysis.Text;
using Microsoft.CodeAnalysis.Text.Shared.Extensions;
using Microsoft.VisualStudio.Text;
Expand All @@ -32,9 +32,9 @@ namespace Microsoft.CodeAnalysis.Editor.CSharp.UnitTests.Classification
{
public partial class SemanticClassifierTests : AbstractCSharpClassifierTests
{
protected override Task<ImmutableArray<ClassifiedSpan>> GetClassificationSpansAsync(string code, TextSpan span, ParseOptions options, bool outOfProcess)
protected override Task<ImmutableArray<ClassifiedSpan>> GetClassificationSpansAsync(string code, TextSpan span, ParseOptions options, TestHost testHost)
{
using var workspace = CreateWorkspace(code, options, outOfProcess);
using var workspace = CreateWorkspace(code, options, testHost);
var document = workspace.CurrentSolution.GetDocument(workspace.Documents.First().Id);

return GetSemanticClassificationsAsync(document, span);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
using Microsoft.CodeAnalysis.CSharp;
using Microsoft.CodeAnalysis.CSharp.Test.Utilities;
using Microsoft.CodeAnalysis.Editor.UnitTests.Workspaces;
using Microsoft.CodeAnalysis.Remote.Testing;
using Microsoft.CodeAnalysis.Test.Utilities;
using Microsoft.CodeAnalysis.Test.Utilities.RemoteHost;
using Microsoft.CodeAnalysis.Text;
using Roslyn.Test.Utilities;
using Xunit;
Expand All @@ -20,9 +20,9 @@ namespace Microsoft.CodeAnalysis.Editor.CSharp.UnitTests.Classification
{
public partial class SyntacticClassifierTests : AbstractCSharpClassifierTests
{
protected override Task<ImmutableArray<ClassifiedSpan>> GetClassificationSpansAsync(string code, TextSpan span, ParseOptions options, bool outOfProcess)
protected override Task<ImmutableArray<ClassifiedSpan>> GetClassificationSpansAsync(string code, TextSpan span, ParseOptions options, TestHost testHost)
{
using var workspace = CreateWorkspace(code, options, outOfProcess);
using var workspace = CreateWorkspace(code, options, testHost);
var document = workspace.CurrentSolution.Projects.First().Documents.First();

return GetSyntacticClassificationsAsync(document, span);
Expand Down Expand Up @@ -351,7 +351,7 @@ await TestInMethodAsync(code,
[Theory, Trait(Traits.Feature, Traits.Features.Classification)]
[WorkItem(44423, "https://github.com/dotnet/roslyn/issues/44423")]
[CombinatorialData]
public async Task VerbatimStringLiteral6(bool script, bool outOfProcess)
public async Task VerbatimStringLiteral6(bool script, TestHost testHost)
{
var code = @"string s = @""""""/*"";";

Expand All @@ -361,7 +361,7 @@ await TestAsync(
code,
code,
parseOptions,
outOfProcess,
testHost,
Keyword("string"),
script ? Field("s") : Local("s"),
Operators.Equals,
Expand Down Expand Up @@ -471,7 +471,7 @@ await TestInExpressionAsync(code,
[Theory, Trait(Traits.Feature, Traits.Features.Classification)]
[WorkItem(44423, "https://github.com/dotnet/roslyn/issues/44423")]
[CombinatorialData]
public async Task VarContextualKeywordAtNamespaceLevel(bool script, bool outOfProcess)
public async Task VarContextualKeywordAtNamespaceLevel(bool script, TestHost testHost)
{
var code = @"var goo = 2;";

Expand All @@ -480,7 +480,7 @@ public async Task VarContextualKeywordAtNamespaceLevel(bool script, bool outOfPr
await TestAsync(code,
code,
parseOptions,
outOfProcess,
testHost,
script ? Identifier("var") : Keyword("var"),
script ? Field("goo") : Local("goo"),
Operators.Equals,
Expand All @@ -491,7 +491,7 @@ await TestAsync(code,
[Theory, Trait(Traits.Feature, Traits.Features.Classification)]
[WorkItem(44423, "https://github.com/dotnet/roslyn/issues/44423")]
[CombinatorialData]
public async Task LinqKeywordsAtNamespaceLevel(bool script, bool outOfProcess)
public async Task LinqKeywordsAtNamespaceLevel(bool script, TestHost testHost)
{
// the contextual keywords are actual keywords since we parse top level field declaration and only give a semantic error
var code = @"object goo = from goo in goo
Expand All @@ -508,7 +508,7 @@ await TestAsync(
code,
code,
parseOptions,
outOfProcess,
testHost,
Keyword("object"),
script ? Field("goo") : Local("goo"),
Operators.Equals,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

using System;
using System.Threading.Tasks;
using Microsoft.CodeAnalysis.Remote.Testing;
using Microsoft.CodeAnalysis.Test.Utilities;
using Roslyn.Test.Utilities;
using Xunit;
Expand Down Expand Up @@ -374,7 +375,7 @@ await TestAsync(code,
[Theory, Trait(Traits.Feature, Traits.Features.Classification)]
[WorkItem(44423, "https://github.com/dotnet/roslyn/issues/44423")]
[CombinatorialData]
public async Task PP_If8(bool script, bool outOfProcess)
public async Task PP_If8(bool script, TestHost testHost)
{
var code =
@"#if
Expand All @@ -391,7 +392,7 @@ await TestAsync(
code,
code,
parseOptions,
outOfProcess,
testHost,
PPKeyword("#"),
PPKeyword("if"),
PPKeyword("#"),
Expand All @@ -407,7 +408,7 @@ await TestAsync(
[Theory, Trait(Traits.Feature, Traits.Features.Classification)]
[WorkItem(44423, "https://github.com/dotnet/roslyn/issues/44423")]
[CombinatorialData]
public async Task PP_If9(bool script, bool outOfProcess)
public async Task PP_If9(bool script, TestHost testHost)
{
var code =
@"#if //Goo1
Expand All @@ -424,7 +425,7 @@ await TestAsync(
code,
code,
parseOptions,
outOfProcess,
testHost,
PPKeyword("#"),
PPKeyword("if"),
Comment("//Goo1"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using System.Linq;
using System.Threading.Tasks;
using Microsoft.CodeAnalysis.Classification;
using Microsoft.CodeAnalysis.Remote.Testing;
using Microsoft.CodeAnalysis.Test.Utilities;
using Microsoft.CodeAnalysis.Text;
using Roslyn.Test.Utilities;
Expand All @@ -17,9 +18,9 @@ namespace Microsoft.CodeAnalysis.Editor.CSharp.UnitTests.Classification
{
public partial class TotalClassifierTests : AbstractCSharpClassifierTests
{
protected override Task<ImmutableArray<ClassifiedSpan>> GetClassificationSpansAsync(string code, TextSpan span, ParseOptions options, bool outOfProcess)
protected override Task<ImmutableArray<ClassifiedSpan>> GetClassificationSpansAsync(string code, TextSpan span, ParseOptions options, TestHost testHost)
{
using var workspace = CreateWorkspace(code, options, outOfProcess);
using var workspace = CreateWorkspace(code, options, testHost);
var document = workspace.CurrentSolution.GetDocument(workspace.Documents.First().Id);

return GetAllClassificationsAsync(document, span);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
// See the LICENSE file in the project root for more information.

using System.Threading.Tasks;
using Microsoft.CodeAnalysis.Remote.Testing;
using Microsoft.CodeAnalysis.Test.Utilities;
using Roslyn.Test.Utilities;
using Xunit;
Expand Down Expand Up @@ -624,7 +625,7 @@ await TestInMethodAsync(@"typeof(dynamic)",
[Theory, Trait(Traits.Feature, Traits.Features.Classification)]
[WorkItem(44423, "https://github.com/dotnet/roslyn/issues/44423")]
[CombinatorialData]
public async Task DynamicAsArrayName(bool script, bool outOfProcess)
public async Task DynamicAsArrayName(bool script, TestHost testHost)
{
var code =
@"int[] dynamic = {
Expand All @@ -637,7 +638,7 @@ await TestAsync(
code,
code,
parseOptions,
outOfProcess,
testHost,
Keyword("int"),
Punctuation.OpenBracket,
Punctuation.CloseBracket,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,13 @@
using Microsoft.CodeAnalysis.CSharp.Test.Utilities;
using Microsoft.CodeAnalysis.Editor.UnitTests.CodeActions;
using Microsoft.CodeAnalysis.EncapsulateField;
using Microsoft.CodeAnalysis.Remote.Testing;
using Microsoft.CodeAnalysis.Test.Utilities;
using Microsoft.CodeAnalysis.Test.Utilities.RemoteHost;
using Roslyn.Test.Utilities;
using Xunit;

namespace Microsoft.CodeAnalysis.Editor.CSharp.UnitTests.CodeRefactorings.EncapsulateField
{
public enum TestHost
{
InProcess,
OutOfProcess,
}

public class EncapsulateFieldTests : AbstractCSharpCodeActionTest
{
protected override CodeRefactoringProvider CreateCodeRefactoringProvider(Workspace workspace, TestParameters parameters)
Expand All @@ -43,7 +37,7 @@ internal Task TestAllOptionsOffAsync(
{
options = options ?? new OptionsCollection(GetLanguage());
options.AddRange(AllOptionsOff);
options.Add(RemoteHostOptions.RemoteHostTest, host != TestHost.InProcess);
options.Add(RemoteTestHostOptions.RemoteHostTest, host != TestHost.InProcess);

return TestAsync(initialMarkup, expectedMarkup,
parseOptions, compilationOptions, index, options);
Expand Down Expand Up @@ -219,7 +213,7 @@ await TestInRegularAndScriptAsync(text, expected,
{
{ CSharpCodeStyleOptions.PreferExpressionBodiedProperties, ExpressionBodyPreference.WhenPossible, NotificationOption2.Silent },
{ CSharpCodeStyleOptions.PreferExpressionBodiedAccessors, ExpressionBodyPreference.Never, NotificationOption2.Silent },
{ RemoteHostOptions.RemoteHostTest, host != TestHost.InProcess }
{ RemoteTestHostOptions.RemoteHostTest, host != TestHost.InProcess }
});
}

Expand Down Expand Up @@ -255,7 +249,7 @@ await TestInRegularAndScriptAsync(text, expected,
options: new OptionsCollection(GetLanguage())
{
{ CSharpCodeStyleOptions.PreferExpressionBodiedAccessors, CSharpCodeStyleOptions.WhenPossibleWithSilentEnforcement },
{ RemoteHostOptions.RemoteHostTest, host != TestHost.InProcess }
{ RemoteTestHostOptions.RemoteHostTest, host != TestHost.InProcess }
});
}

Expand Down Expand Up @@ -794,7 +788,7 @@ class Program

private TestParameters GetRemoteHostOptions(TestHost host)
{
return new TestParameters(options: Option(RemoteHostOptions.RemoteHostTest, host != TestHost.InProcess));
return new TestParameters(options: Option(RemoteTestHostOptions.RemoteHostTest, host != TestHost.InProcess));
}

[WorkItem(705898, "http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/705898")]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,13 @@
using Microsoft.CodeAnalysis.Editor.CSharp.UnitTests.CodeActions;
using Microsoft.CodeAnalysis.Editor.CSharp.UnitTests.CodeRefactorings;
using Microsoft.CodeAnalysis.Editor.UnitTests.CodeActions;
using Microsoft.CodeAnalysis.Remote.Testing;
using Microsoft.CodeAnalysis.Test.Utilities;
using Microsoft.CodeAnalysis.Test.Utilities.RemoteHost;
using Roslyn.Test.Utilities;
using Xunit;

namespace Microsoft.CodeAnalysis.Editor.CSharp.UnitTests.ConvertTupleToStruct
{
public enum TestHost
{
InProcess,
OutOfProcess,
}

public class ConvertTupleToStructTests : AbstractCSharpCodeActionTest
{
protected override CodeRefactoringProvider CreateCodeRefactoringProvider(Workspace workspace, TestParameters parameters)
Expand All @@ -34,7 +28,7 @@ protected override ImmutableArray<CodeAction> MassageActions(ImmutableArray<Code
private OptionsCollection GetPreferImplicitTypeOptions(TestHost host)
{
var options = this.PreferImplicitTypeWithInfo();
options.Add(RemoteHostOptions.RemoteHostTest, host != TestHost.InProcess);
options.Add(RemoteTestHostOptions.RemoteHostTest, host != TestHost.InProcess);
return options;
}

Expand Down Expand Up @@ -238,7 +232,7 @@ public static implicit operator NewStruct((int a, int b) value)
}
}";
await TestInRegularAndScriptAsync(text, expected,
options: Option(RemoteHostOptions.RemoteHostTest, host != TestHost.InProcess));
options: Option(RemoteTestHostOptions.RemoteHostTest, host != TestHost.InProcess));
}

[Theory, CombinatorialData, Trait(Traits.Feature, Traits.Features.CodeActionsConvertTupleToStruct)]
Expand Down Expand Up @@ -1302,7 +1296,7 @@ void Method()
";

await TestMissingInRegularAndScriptAsync(text,
parameters: new TestParameters(options: Option(RemoteHostOptions.RemoteHostTest, host != TestHost.InProcess)));
parameters: new TestParameters(options: Option(RemoteTestHostOptions.RemoteHostTest, host != TestHost.InProcess)));
}

[Theory, CombinatorialData, Trait(Traits.Feature, Traits.Features.CodeActionsConvertTupleToStruct)]
Expand Down
Loading

0 comments on commit 4153950

Please sign in to comment.