-
Notifications
You must be signed in to change notification settings - Fork 94
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1172 from microsoft/fix1158
Drop the implicit `System.Memory` reference from the package
- Loading branch information
Showing
10 changed files
with
224 additions
and
106 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
87 changes: 87 additions & 0 deletions
87
test/Microsoft.Windows.CsWin32.Tests/CSharpSourceGeneratorVerifier.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT license. See LICENSE file in the project root for full license information. | ||
|
||
using System.Diagnostics.CodeAnalysis; | ||
using Microsoft.CodeAnalysis.CSharp.Testing; | ||
|
||
internal static class CSharpSourceGeneratorVerifier | ||
{ | ||
internal class Test : CSharpSourceGeneratorTest<SourceGenerator, DefaultVerifier> | ||
{ | ||
private readonly string testFile; | ||
private readonly string testMethod; | ||
|
||
public Test([CallerFilePath] string? testFile = null, [CallerMemberName] string? testMethod = null) | ||
{ | ||
this.testFile = testFile ?? throw new ArgumentNullException(nameof(testFile)); | ||
this.testMethod = testMethod ?? throw new ArgumentNullException(nameof(testMethod)); | ||
|
||
// We don't mean to use record/playback verification. | ||
this.TestBehaviors |= TestBehaviors.SkipGeneratedSourcesCheck; | ||
|
||
this.ReferenceAssemblies = MyReferenceAssemblies.NetStandard20; | ||
this.TestState.Sources.Add(string.Empty); | ||
this.TestState.AnalyzerConfigFiles.Add(("/.globalconfig", ConstructGlobalConfigString())); | ||
} | ||
|
||
public LanguageVersion LanguageVersion { get; set; } = LanguageVersion.CSharp9; | ||
|
||
public string? NativeMethodsTxt { get; set; } | ||
|
||
[StringSyntax(StringSyntaxAttribute.Json)] | ||
public string? NativeMethodsJson { get; set; } | ||
|
||
protected override IEnumerable<Type> GetSourceGenerators() | ||
{ | ||
yield return typeof(SourceGenerator); | ||
} | ||
|
||
protected override ParseOptions CreateParseOptions() | ||
{ | ||
return ((CSharpParseOptions)base.CreateParseOptions()).WithLanguageVersion(this.LanguageVersion); | ||
} | ||
|
||
protected override CompilationOptions CreateCompilationOptions() | ||
{ | ||
var compilationOptions = (CSharpCompilationOptions)base.CreateCompilationOptions(); | ||
return compilationOptions | ||
.WithAllowUnsafe(true) | ||
.WithWarningLevel(99) | ||
.WithSpecificDiagnosticOptions(compilationOptions.SpecificDiagnosticOptions.SetItem("CS1591", ReportDiagnostic.Suppress)); | ||
} | ||
|
||
protected override Task RunImplAsync(CancellationToken cancellationToken) | ||
{ | ||
if (this.NativeMethodsTxt is not null) | ||
{ | ||
this.TestState.AdditionalFiles.Add(("NativeMethods.txt", this.NativeMethodsTxt)); | ||
} | ||
|
||
if (this.NativeMethodsJson is not null) | ||
{ | ||
this.TestState.AdditionalFiles.Add(("NativeMethods.json", this.NativeMethodsJson)); | ||
} | ||
|
||
return base.RunImplAsync(cancellationToken); | ||
} | ||
|
||
private static string ConstructGlobalConfigString(bool omitDocs = false) | ||
{ | ||
StringBuilder globalConfigBuilder = new(); | ||
globalConfigBuilder.AppendLine("is_global = true"); | ||
globalConfigBuilder.AppendLine(); | ||
globalConfigBuilder.AppendLine($"build_property.CsWin32InputMetadataPaths = {JoinAssemblyMetadata("ProjectionMetadataWinmd")}"); | ||
if (!omitDocs) | ||
{ | ||
globalConfigBuilder.AppendLine($"build_property.CsWin32InputDocPaths = {JoinAssemblyMetadata("ProjectionDocs")}"); | ||
} | ||
|
||
return globalConfigBuilder.ToString(); | ||
|
||
static string JoinAssemblyMetadata(string name) | ||
{ | ||
return string.Join(";", typeof(GeneratorTests).Assembly.GetCustomAttributes<AssemblyMetadataAttribute>().Where(metadata => metadata.Key == name).Select(metadata => metadata.Value)); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
test/Microsoft.Windows.CsWin32.Tests/Microsoft.Windows.CsWin32.Tests.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 29 additions & 0 deletions
29
test/Microsoft.Windows.CsWin32.Tests/MyReferenceAssemblies.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT license. See LICENSE file in the project root for full license information. | ||
|
||
internal static class MyReferenceAssemblies | ||
{ | ||
#pragma warning disable SA1202 // Elements should be ordered by access - because field initializer depend on each other | ||
private static readonly ImmutableArray<PackageIdentity> AdditionalLegacyPackages = ImmutableArray.Create( | ||
new PackageIdentity("Microsoft.Windows.SDK.Contracts", "10.0.22621.2")); | ||
|
||
private static readonly ImmutableArray<PackageIdentity> AdditionalModernPackages = AdditionalLegacyPackages.AddRange(ImmutableArray.Create( | ||
new PackageIdentity("System.Runtime.CompilerServices.Unsafe", "6.0.0"), | ||
new PackageIdentity("System.Memory", "4.5.5"), | ||
new PackageIdentity("Microsoft.Win32.Registry", "5.0.0"))); | ||
|
||
internal static readonly ReferenceAssemblies NetStandard20 = ReferenceAssemblies.NetStandard.NetStandard20.AddPackages(AdditionalModernPackages); | ||
#pragma warning restore SA1202 // Elements should be ordered by access | ||
|
||
internal static class NetFramework | ||
{ | ||
internal static readonly ReferenceAssemblies Net35 = ReferenceAssemblies.NetFramework.Net35.WindowsForms.AddPackages(AdditionalLegacyPackages); | ||
internal static readonly ReferenceAssemblies Net472 = ReferenceAssemblies.NetFramework.Net472.WindowsForms.AddPackages(AdditionalModernPackages); | ||
} | ||
|
||
internal static class Net | ||
{ | ||
internal static readonly ReferenceAssemblies Net60 = ReferenceAssemblies.Net.Net60.AddPackages(AdditionalModernPackages); | ||
internal static readonly ReferenceAssemblies Net70 = ReferenceAssemblies.Net.Net70.AddPackages(AdditionalModernPackages); | ||
} | ||
} |
Oops, something went wrong.