Skip to content

Commit 063e7b7

Browse files
committed
Enable parallel testing
1 parent c4bf6c4 commit 063e7b7

6 files changed

Lines changed: 35 additions & 10 deletions

File tree

StyleCop.Analyzers/StyleCop.Analyzers.Test.CSharp7/Properties/AssemblyInfo.cs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,10 @@
33

44
using System;
55
using System.Runtime.InteropServices;
6-
using Xunit;
76

87
[assembly: CLSCompliant(false)]
98

109
// Setting ComVisible to false makes the types in this assembly not visible
1110
// to COM components. If you need to access a type in this assembly from
1211
// COM, set the ComVisible attribute to true on that type.
1312
[assembly: ComVisible(false)]
14-
15-
[assembly: CollectionBehavior(CollectionBehavior.CollectionPerAssembly, DisableTestParallelization = true)]

StyleCop.Analyzers/StyleCop.Analyzers.Test/HelperTests/IndentationHelperTests.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,12 @@ namespace StyleCop.Analyzers.Test.HelperTests
99
using Microsoft.CodeAnalysis;
1010
using Microsoft.CodeAnalysis.CSharp;
1111
using Microsoft.CodeAnalysis.Formatting;
12+
using Microsoft.CodeAnalysis.Host.Mef;
1213
using Microsoft.CodeAnalysis.Text;
1314
using StyleCop.Analyzers.Helpers;
1415
using StyleCop.Analyzers.Settings.ObjectModel;
1516
using StyleCop.Analyzers.Test.Helpers;
17+
using TestHelper;
1618
using Xunit;
1719

1820
/// <summary>
@@ -140,7 +142,7 @@ public async Task VerifyGetIndentationStepsForTokenNotAtStartOfLineAsync()
140142

141143
private static Document CreateTestDocument(string source, int indentationSize = 4, bool useTabs = false, int tabSize = 4)
142144
{
143-
var workspace = new AdhocWorkspace();
145+
var workspace = DiagnosticVerifier.CreateWorkspace();
144146
workspace.Options = workspace.Options
145147
.WithChangedOption(FormattingOptions.IndentationSize, LanguageNames.CSharp, indentationSize)
146148
.WithChangedOption(FormattingOptions.UseTabs, LanguageNames.CSharp, useTabs)

StyleCop.Analyzers/StyleCop.Analyzers.Test/Helpers/DiagnosticVerifier.Helper.cs

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,9 @@ namespace TestHelper
1515
using Microsoft.CodeAnalysis.CSharp;
1616
using Microsoft.CodeAnalysis.Diagnostics;
1717
using Microsoft.CodeAnalysis.Formatting;
18+
using Microsoft.CodeAnalysis.Host.Mef;
1819
using Microsoft.CodeAnalysis.Text;
20+
using Microsoft.VisualStudio.Composition;
1921
using StyleCop.Analyzers;
2022
using StyleCop.Analyzers.Settings.ObjectModel;
2123
using StyleCop.Analyzers.Test.Helpers;
@@ -33,6 +35,31 @@ public abstract partial class DiagnosticVerifier
3335
private static readonly string VisualBasicDefaultFilePath = DefaultFilePathPrefix + 0 + "." + VisualBasicDefaultExt;
3436
private static readonly string TestProjectName = "TestProject";
3537

38+
private static readonly Lazy<IExportProviderFactory> ExportProviderFactory;
39+
40+
static DiagnosticVerifier()
41+
{
42+
ExportProviderFactory = new Lazy<IExportProviderFactory>(
43+
() =>
44+
{
45+
var discovery = new AttributedPartDiscovery(Resolver.DefaultInstance, isNonPublicSupported: true);
46+
var parts = Task.Run(() => discovery.CreatePartsAsync(MefHostServices.DefaultAssemblies)).GetAwaiter().GetResult();
47+
var catalog = ComposableCatalog.Create(Resolver.DefaultInstance).AddParts(parts);
48+
49+
var configuration = CompositionConfiguration.Create(catalog);
50+
var runtimeComposition = RuntimeComposition.CreateRuntimeComposition(configuration);
51+
return runtimeComposition.CreateExportProviderFactory();
52+
},
53+
LazyThreadSafetyMode.ExecutionAndPublication);
54+
}
55+
56+
internal static AdhocWorkspace CreateWorkspace()
57+
{
58+
var exportProvider = ExportProviderFactory.Value.CreateExportProvider();
59+
var host = MefV1HostServices.Create(exportProvider.AsExportProvider());
60+
return new AdhocWorkspace(host);
61+
}
62+
3663
/// <summary>
3764
/// Given an analyzer and a collection of documents to apply it to, run the analyzer and gather an array of
3865
/// diagnostics found. The returned diagnostics are then ordered by location in the source documents.
@@ -115,7 +142,7 @@ protected virtual Solution CreateSolution(ProjectId projectId, string language)
115142
{
116143
var compilationOptions = new CSharpCompilationOptions(OutputKind.DynamicallyLinkedLibrary, allowUnsafe: true);
117144

118-
Solution solution = new AdhocWorkspace()
145+
Solution solution = CreateWorkspace()
119146
.CurrentSolution
120147
.AddProject(projectId, TestProjectName, TestProjectName, language)
121148
.WithProjectCompilationOptions(projectId, compilationOptions)

StyleCop.Analyzers/StyleCop.Analyzers.Test/Properties/AssemblyInfo.cs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,8 @@
22
// Licensed under the Apache License, Version 2.0. See LICENSE in the project root for license information.
33

44
using System;
5-
using System.Reflection;
65
using System.Runtime.CompilerServices;
76
using System.Runtime.InteropServices;
8-
using Xunit;
97

108
[assembly: CLSCompliant(false)]
119

@@ -14,6 +12,4 @@
1412
// COM, set the ComVisible attribute to true on that type.
1513
[assembly: ComVisible(false)]
1614

17-
[assembly: CollectionBehavior(CollectionBehavior.CollectionPerAssembly, DisableTestParallelization = true)]
18-
1915
[assembly: InternalsVisibleTo("StyleCop.Analyzers.Test.CSharp7, PublicKey=0024000004800000940000000602000000240000525341310004000001000100c36d40d996fcc95fb6a89754728616758f459026e31478ce93633b3e27a4af416f103aa3d7a9e7998f829f8715cc1240d30724fd662042550fa71357b19562622424267e9e4640c403edbe64709a9ca5918128a9b9020b0db6e770d0dd1eac888869c23a835b74bde00e171984b1d1c24636cf030f0b23106e73035a2be145a6")]

StyleCop.Analyzers/StyleCop.Analyzers.Test/Settings/SettingsUnitTests.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,10 @@ namespace StyleCop.Analyzers.Test.Settings
88
using System.Threading.Tasks;
99
using Microsoft.CodeAnalysis;
1010
using Microsoft.CodeAnalysis.Diagnostics;
11+
using Microsoft.CodeAnalysis.Host.Mef;
1112
using Microsoft.CodeAnalysis.Text;
1213
using StyleCop.Analyzers.Settings.ObjectModel;
14+
using TestHelper;
1315
using Xunit;
1416

1517
public class SettingsUnitTests
@@ -358,7 +360,7 @@ private static async Task<SyntaxTreeAnalysisContext> CreateAnalysisContextAsync(
358360
var projectId = ProjectId.CreateNewId();
359361
var documentId = DocumentId.CreateNewId(projectId);
360362

361-
var solution = new AdhocWorkspace()
363+
var solution = DiagnosticVerifier.CreateWorkspace()
362364
.CurrentSolution
363365
.AddProject(projectId, TestProjectName, TestProjectName, LanguageNames.CSharp)
364366
.AddDocument(documentId, "Test0.cs", SourceText.From(string.Empty));

StyleCop.Analyzers/StyleCop.Analyzers.Test/StyleCop.Analyzers.Test.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
<ItemGroup>
1818
<PackageReference Include="Microsoft.CodeAnalysis" Version="1.2.1" />
19+
<PackageReference Include="Microsoft.VisualStudio.Composition" Version="15.6.36" />
1920
<PackageReference Include="xunit" Version="2.3.1" />
2021
<PackageReference Include="xunit.runner.visualstudio" Version="2.3.1" PrivateAssets="all" />
2122
</ItemGroup>

0 commit comments

Comments
 (0)