Skip to content

Commit cc09de8

Browse files
committed
Fix a bunch of failing tests
1 parent 8fba9e7 commit cc09de8

File tree

4 files changed

+36
-17
lines changed

4 files changed

+36
-17
lines changed

test/Microsoft.Windows.CsWin32.Tests/COMTests.cs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -341,11 +341,11 @@ public void COMInterfaceWithSupportedOSPlatform(bool netstandard, bool allowMars
341341

342342
if (netstandard)
343343
{
344-
Assert.Contains(iface.AttributeLists, al => IsAttributePresent(al, "SupportedOSPlatform"));
344+
Assert.DoesNotContain(iface.AttributeLists, al => IsAttributePresent(al, "SupportedOSPlatform"));
345345
}
346346
else
347347
{
348-
Assert.DoesNotContain(iface.AttributeLists, al => IsAttributePresent(al, "SupportedOSPlatform"));
348+
Assert.Contains(iface.AttributeLists, al => IsAttributePresent(al, "SupportedOSPlatform"));
349349
}
350350
}
351351

@@ -395,22 +395,21 @@ public void ReferencesToStructWithFlexibleArrayAreAlwaysPointers()
395395
[CombinatorialData]
396396
public void COMInterfaceIIDInterfaceOnAppropriateTFMs(
397397
bool allowMarshaling,
398-
[CombinatorialValues(LanguageVersion.CSharp10, LanguageVersion.CSharp11)] LanguageVersion langVersion,
399398
[CombinatorialValues("net8.0", "net9.0")] string tfm)
400399
{
401400
const string structName = "IEnumBstr";
402401
this.compilation = this.starterCompilations[tfm];
403-
this.parseOptions = this.parseOptions.WithLanguageVersion(langVersion);
402+
this.parseOptions = this.parseOptions.WithLanguageVersion(GetLanguageVersionForTfm(tfm) ?? LanguageVersion.Latest);
404403
this.generator = this.CreateGenerator(DefaultTestGeneratorOptions with { AllowMarshaling = allowMarshaling });
405404
this.GenerateApi(structName);
406405

407406
BaseTypeDeclarationSyntax type = this.FindGeneratedType(structName).Single();
408407
IEnumerable<BaseTypeSyntax> actual = type.BaseList?.Types ?? Enumerable.Empty<BaseTypeSyntax>();
409408
Predicate<BaseTypeSyntax> predicate = t => t.Type.ToString().Contains("IComIID");
410409

411-
// Static interface members requires C# 11 and .NET 7.
410+
// Static interface members requires C# 11 and .NET 7+.
412411
// And COM *interfaces* are not allowed to have them, so assert we only generate them on structs.
413-
if (tfm == "net8.0" && langVersion >= LanguageVersion.CSharp11 && type is StructDeclarationSyntax)
412+
if (this.parseOptions.LanguageVersion >= LanguageVersion.CSharp11 && type is StructDeclarationSyntax)
414413
{
415414
Assert.Contains(actual, predicate);
416415
}

test/Microsoft.Windows.CsWin32.Tests/GeneratorTestBase.cs

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ public GeneratorTestBase(ITestOutputHelper logger)
2626

2727
this.parseOptions = CSharpParseOptions.Default
2828
.WithDocumentationMode(DocumentationMode.Diagnose)
29-
.WithLanguageVersion(LanguageVersion.CSharp11);
29+
.WithLanguageVersion(LanguageVersion.CSharp12);
3030

3131
// set in InitializeAsync
3232
this.compilation = null!;
@@ -91,14 +91,27 @@ public async ValueTask InitializeAsync()
9191

9292
foreach (string tfm in this.starterCompilations.Keys)
9393
{
94-
if (tfm.StartsWith("net6") || tfm.StartsWith("net7"))
94+
if (tfm.StartsWith("netstandard", StringComparison.OrdinalIgnoreCase))
9595
{
96-
AddSymbols("NET5_0_OR_GREATER", "NET6_0_OR_GREATER", "NET6_0");
96+
AddSymbols("NETSTANDARD");
97+
AddSymbols("NETSTANDARD2_0");
98+
}
99+
else if (tfm.Contains('.'))
100+
{
101+
AddSymbols("NET5_0_OR_GREATER");
102+
AddSymbols("NET6_0_OR_GREATER");
103+
AddSymbols("NET7_0_OR_GREATER");
104+
AddSymbols("NET8_0_OR_GREATER");
105+
AddSymbols(tfm.Replace('.', '_').ToUpperInvariant());
106+
}
107+
else
108+
{
109+
AddSymbols("NETFRAMEWORK");
97110
}
98111

99-
if (tfm.StartsWith("net7"))
112+
if (tfm.StartsWith("net9"))
100113
{
101-
AddSymbols("NET7_0_OR_GREATER", "NET7_0");
114+
AddSymbols("NET9_0_OR_GREATER");
102115
}
103116

104117
// Guarantee we have at least an empty list of symbols for each TFM.
@@ -154,6 +167,13 @@ protected static bool IsOrContainsExternMethod(MethodDeclarationSyntax method)
154167
return method.Modifiers.Any(SyntaxKind.ExternKeyword) || method.Body?.Statements.OfType<LocalFunctionStatementSyntax>().Any(f => f.Modifiers.Any(SyntaxKind.ExternKeyword)) is true;
155168
}
156169

170+
protected static LanguageVersion? GetLanguageVersionForTfm(string tfm) => tfm switch
171+
{
172+
"net8.0" => LanguageVersion.CSharp12,
173+
"net9.0" => LanguageVersion.CSharp13,
174+
_ => null,
175+
};
176+
157177
protected static IEnumerable<AttributeSyntax> FindAttribute(SyntaxList<AttributeListSyntax> attributeLists, string name) => attributeLists.SelectMany(al => al.Attributes).Where(a => a.Name.ToString() == name);
158178

159179
protected void GenerateApi(string apiName)

test/Microsoft.Windows.CsWin32.Tests/InlineArrayTests.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,10 @@ public void FixedLengthInlineArray(
1313
bool allowMarshaling,
1414
bool multitargetingAPIs,
1515
[CombinatorialValues("net35", "net472", "net8.0")] string tfm,
16-
[CombinatorialValues(/*char*/"RM_PROCESS_INFO", /*custom unmanaged*/"ARRAYDESC")] string api,
17-
[CombinatorialValues(LanguageVersion.CSharp8, LanguageVersion.CSharp9)] LanguageVersion langVersion)
16+
[CombinatorialValues(/*char*/"RM_PROCESS_INFO", /*custom unmanaged*/"ARRAYDESC")] string api)
1817
{
1918
this.compilation = this.starterCompilations[tfm];
20-
this.parseOptions = this.parseOptions.WithLanguageVersion(langVersion);
19+
this.parseOptions = this.parseOptions.WithLanguageVersion(GetLanguageVersionForTfm(tfm) ?? LanguageVersion.CSharp9);
2120
this.generator = this.CreateGenerator(new GeneratorOptions { AllowMarshaling = allowMarshaling, MultiTargetingFriendlyAPIs = multitargetingAPIs });
2221

2322
// TODO we need to test

test/Microsoft.Windows.CsWin32.Tests/SourceGeneratorTests.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,11 +61,11 @@ public async Task MissingSystemMemoryReference_WithGeneratedCode_NetFx472()
6161
/// Asserts that when targeting a framework that implicitly includes the references we need, no warning is generated.
6262
/// </summary>
6363
[Fact]
64-
public async Task MissingSystemMemoryReference_WithGeneratedCode_Net60()
64+
public async Task MissingSystemMemoryReference_WithGeneratedCode_Net80()
6565
{
6666
await new VerifyCS.Test(logger)
6767
{
68-
ReferenceAssemblies = ReferenceAssemblies.Net.Net60,
68+
ReferenceAssemblies = ReferenceAssemblies.Net.Net80,
6969
NativeMethodsTxt = "CreateFile",
7070
}.RunAsync(TestContext.Current.CancellationToken);
7171
}
@@ -75,7 +75,8 @@ public async Task Gdi32()
7575
{
7676
await new VerifyCS.Test(logger)
7777
{
78-
ReferenceAssemblies = ReferenceAssemblies.Net.Net60,
78+
ReferenceAssemblies = ReferenceAssemblies.Net.Net80,
79+
LanguageVersion = LanguageVersion.CSharp12,
7980
NativeMethodsTxt = "gdi32.*",
8081
}.RunAsync(TestContext.Current.CancellationToken);
8182
}

0 commit comments

Comments
 (0)