Skip to content

Commit

Permalink
Merge pull request #3341 from sharwell/update-testing
Browse files Browse the repository at this point in the history
Update to Microsoft.CodeAnalysis.Testing 1.0.1-beta1.21202.2
  • Loading branch information
sharwell authored Apr 28, 2021
2 parents 0eee82b + ddd167b commit e7af4b3
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

<ItemGroup>
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.Workspaces" Version="1.3.2" />
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.CodeFix.Testing.XUnit" Version="1.0.1-beta1.21159.2" />
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.CodeFix.Testing.XUnit" Version="1.0.1-beta1.21202.2" />
<PackageReference Include="Microsoft.VisualStudio.Composition" Version="16.1.8" />
<PackageReference Include="System.ValueTuple" Version="4.5.0" />
<PackageReference Include="xunit" Version="2.4.1" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ public CSharpTest()
public CSharpTest(LanguageVersion? languageVersion)
{
this.ReferenceAssemblies = GenericAnalyzerTest.ReferenceAssemblies;
this.LanguageVersion = languageVersion;

this.OptionsTransforms.Add(options =>
options
Expand All @@ -120,15 +121,6 @@ public CSharpTest(LanguageVersion? languageVersion)
this.TestState.AdditionalFilesFactories.Add(GenerateSettingsFile);
this.CodeActionValidationMode = CodeActionValidationMode.None;

if (languageVersion != null)
{
this.SolutionTransforms.Add((solution, projectId) =>
{
var parseOptions = (CSharpParseOptions)solution.GetProject(projectId).ParseOptions;
return solution.WithProjectParseOptions(projectId, parseOptions.WithLanguageVersion(languageVersion.Value));
});
}

this.SolutionTransforms.Add((solution, projectId) =>
{
var corlib = solution.GetProject(projectId).MetadataReferences.OfType<PortableExecutableReference>()
Expand Down Expand Up @@ -248,6 +240,8 @@ public CSharpTest(LanguageVersion? languageVersion)
/// </value>
public List<string> ExplicitlyEnabledDiagnostics { get; } = new List<string>();

private LanguageVersion? LanguageVersion { get; }

protected override CompilationOptions CreateCompilationOptions()
{
var compilationOptions = base.CreateCompilationOptions();
Expand All @@ -261,6 +255,17 @@ protected override CompilationOptions CreateCompilationOptions()
return compilationOptions.WithSpecificDiagnosticOptions(specificDiagnosticOptions);
}

protected override ParseOptions CreateParseOptions()
{
var parseOptions = base.CreateParseOptions();
if (this.LanguageVersion is { } languageVersion)
{
parseOptions = ((CSharpParseOptions)parseOptions).WithLanguageVersion(languageVersion);
}

return parseOptions;
}

protected override IEnumerable<CodeFixProvider> GetCodeFixProviders()
{
var codeFixProvider = new TCodeFix();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,14 +62,20 @@ public CSharpTest()

public CSharpTest(LanguageVersion? languageVersion)
{
if (languageVersion != null)
this.LanguageVersion = languageVersion;
}

private LanguageVersion? LanguageVersion { get; }

protected override ParseOptions CreateParseOptions()
{
var parseOptions = base.CreateParseOptions();
if (this.LanguageVersion is { } languageVersion)
{
this.SolutionTransforms.Add((solution, projectId) =>
{
var parseOptions = (CSharpParseOptions)solution.GetProject(projectId).ParseOptions;
return solution.WithProjectParseOptions(projectId, parseOptions.WithLanguageVersion(languageVersion.Value));
});
parseOptions = ((CSharpParseOptions)parseOptions).WithLanguageVersion(languageVersion);
}

return parseOptions;
}
}
}
Expand Down

0 comments on commit e7af4b3

Please sign in to comment.