Update unit tests to use partial properties
このコミットが含まれているのは:
1 親
bbb0134494
コミット
d8f9b35c9e
4ファイル変更
+48
-44
検索条件に一致するファイルはありません
+21
-22
@@ -1,6 +1,6 @@
|
||||
using System.Threading.Tasks;
|
||||
using ComputeSharp.D2D1.WinUI.SourceGenerators;
|
||||
using ComputeSharp.Tests.SourceGenerators.Helpers;
|
||||
using Microsoft.CodeAnalysis.CSharp;
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
|
||||
namespace ComputeSharp.D2D1.WinUI.Tests.SourceGenerators;
|
||||
@@ -9,7 +9,7 @@ namespace ComputeSharp.D2D1.WinUI.Tests.SourceGenerators;
|
||||
public class Test_CanvasEffectPropertyGenerator
|
||||
{
|
||||
[TestMethod]
|
||||
public async Task SingleProperty()
|
||||
public void SingleProperty()
|
||||
{
|
||||
const string source = """
|
||||
using ComputeSharp.D2D1.WinUI;
|
||||
@@ -19,7 +19,7 @@ public class Test_CanvasEffectPropertyGenerator
|
||||
public abstract partial class MyEffect : CanvasEffect
|
||||
{
|
||||
[GeneratedCanvasEffectProperty]
|
||||
public int Number { get; set; }
|
||||
public partial int Number { get; set; }
|
||||
}
|
||||
""";
|
||||
|
||||
@@ -89,11 +89,11 @@ public class Test_CanvasEffectPropertyGenerator
|
||||
}
|
||||
"""";
|
||||
|
||||
await VerifyGeneratedDiagnosticsAsync(source, ("MyNamespace.MyEffect.g.cs", result));
|
||||
VerifyGeneratedDiagnostics(source, ("MyNamespace.MyEffect.g.cs", result));
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public async Task SingleProperty_WithNullabilityAnnotations()
|
||||
public void SingleProperty_WithNullabilityAnnotations()
|
||||
{
|
||||
const string source = """
|
||||
using ComputeSharp.D2D1.WinUI;
|
||||
@@ -103,7 +103,7 @@ public class Test_CanvasEffectPropertyGenerator
|
||||
public abstract partial class MyEffect : CanvasEffect
|
||||
{
|
||||
[GeneratedCanvasEffectProperty]
|
||||
public object? Instance { get; set; }
|
||||
public partial object? Instance { get; set; }
|
||||
}
|
||||
""";
|
||||
|
||||
@@ -173,11 +173,11 @@ public class Test_CanvasEffectPropertyGenerator
|
||||
}
|
||||
"""";
|
||||
|
||||
await VerifyGeneratedDiagnosticsAsync(source, ("MyNamespace.MyEffect.g.cs", result));
|
||||
VerifyGeneratedDiagnostics(source, ("MyNamespace.MyEffect.g.cs", result));
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public async Task SingleProperty_WithNotNullableReferenceType()
|
||||
public void SingleProperty_WithNotNullableReferenceType()
|
||||
{
|
||||
const string source = """
|
||||
using ComputeSharp.D2D1.WinUI;
|
||||
@@ -187,7 +187,7 @@ public class Test_CanvasEffectPropertyGenerator
|
||||
public abstract partial class MyEffect : CanvasEffect
|
||||
{
|
||||
[GeneratedCanvasEffectProperty]
|
||||
public object Instance { get; set; }
|
||||
public partial object Instance { get; set; }
|
||||
}
|
||||
""";
|
||||
|
||||
@@ -257,11 +257,11 @@ public class Test_CanvasEffectPropertyGenerator
|
||||
}
|
||||
"""";
|
||||
|
||||
await VerifyGeneratedDiagnosticsAsync(source, ("MyNamespace.MyEffect.g.cs", result));
|
||||
VerifyGeneratedDiagnostics(source, ("MyNamespace.MyEffect.g.cs", result));
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public async Task SingleProperty_WithCustomAccessorVisibility()
|
||||
public void SingleProperty_WithCustomAccessorVisibility()
|
||||
{
|
||||
const string source = """
|
||||
using ComputeSharp.D2D1.WinUI;
|
||||
@@ -271,7 +271,7 @@ public class Test_CanvasEffectPropertyGenerator
|
||||
public abstract partial class MyEffect : CanvasEffect
|
||||
{
|
||||
[GeneratedCanvasEffectProperty]
|
||||
public int Number { get; private set; }
|
||||
public partial int Number { get; private set; }
|
||||
}
|
||||
""";
|
||||
|
||||
@@ -341,11 +341,11 @@ public class Test_CanvasEffectPropertyGenerator
|
||||
}
|
||||
"""";
|
||||
|
||||
await VerifyGeneratedDiagnosticsAsync(source, ("MyNamespace.MyEffect.g.cs", result));
|
||||
VerifyGeneratedDiagnostics(source, ("MyNamespace.MyEffect.g.cs", result));
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public async Task MultipleProperties()
|
||||
public void MultipleProperties()
|
||||
{
|
||||
const string source = """
|
||||
using ComputeSharp.D2D1.WinUI;
|
||||
@@ -355,10 +355,10 @@ public class Test_CanvasEffectPropertyGenerator
|
||||
public abstract partial class MyEffect : CanvasEffect
|
||||
{
|
||||
[GeneratedCanvasEffectProperty]
|
||||
public int X { get; set; }
|
||||
public partial int X { get; set; }
|
||||
|
||||
[GeneratedCanvasEffectProperty(CanvasEffectInvalidationType.Creation)]
|
||||
public int Y { get; set; }
|
||||
public partial int Y { get; set; }
|
||||
}
|
||||
""";
|
||||
|
||||
@@ -482,7 +482,7 @@ public class Test_CanvasEffectPropertyGenerator
|
||||
}
|
||||
"""";
|
||||
|
||||
await VerifyGeneratedDiagnosticsAsync(source, ("MyNamespace.MyEffect.g.cs", result));
|
||||
VerifyGeneratedDiagnostics(source, ("MyNamespace.MyEffect.g.cs", result));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -491,11 +491,10 @@ public class Test_CanvasEffectPropertyGenerator
|
||||
/// <param name="source">The input source to process.</param>
|
||||
/// <param name="result">The expected source to be generated.</param>
|
||||
/// <returns>The task for the operation.</returns>
|
||||
private static async Task VerifyGeneratedDiagnosticsAsync(string source, (string Filename, string Source) result)
|
||||
private static void VerifyGeneratedDiagnostics(string source, (string Filename, string Source) result)
|
||||
{
|
||||
await CSharpAnalyzerWithLanguageVersionTest<InvalidGeneratedCanvasEffectPropertyContainingTypeAnalyzer>.VerifyAnalyzerAsync(source);
|
||||
await CSharpAnalyzerWithLanguageVersionTest<InvalidGeneratedCanvasEffectPropertyAccessorsAnalyzer>.VerifyAnalyzerAsync(source);
|
||||
|
||||
CSharpGeneratorTest<CanvasEffectPropertyGenerator>.VerifySources(source, result);
|
||||
// We cannot run the analyzers on the input source, because they'd report unwanted dsiagnostics due to the
|
||||
// partial properties missing an implementation part. For this generator, we just test analyzers individually.
|
||||
CSharpGeneratorTest<CanvasEffectPropertyGenerator>.VerifySources(source, result, languageVersion: LanguageVersion.Preview);
|
||||
}
|
||||
}
|
||||
+10
-9
@@ -1,6 +1,7 @@
|
||||
using System.Threading.Tasks;
|
||||
using ComputeSharp.D2D1.WinUI.SourceGenerators;
|
||||
using ComputeSharp.Tests.SourceGenerators.Helpers;
|
||||
using Microsoft.CodeAnalysis.CSharp;
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
|
||||
namespace ComputeSharp.D2D1.WinUI.Tests.SourceGenerators;
|
||||
@@ -14,14 +15,14 @@ public class Test_CanvasEffectPropertyGenerator_Analyzers
|
||||
const string source = """
|
||||
using ComputeSharp.D2D1.WinUI;
|
||||
|
||||
public class MyEffect
|
||||
public partial class MyEffect
|
||||
{
|
||||
[{|CMPSD2DWINUI0001:GeneratedCanvasEffectProperty|}]
|
||||
public int Number { get; set; }
|
||||
public partial int {|CS9248:Number|} { get; set; }
|
||||
}
|
||||
""";
|
||||
|
||||
await CSharpAnalyzerWithLanguageVersionTest<InvalidGeneratedCanvasEffectPropertyContainingTypeAnalyzer>.VerifyAnalyzerAsync(source);
|
||||
await CSharpAnalyzerWithLanguageVersionTest<InvalidGeneratedCanvasEffectPropertyContainingTypeAnalyzer>.VerifyAnalyzerAsync(source, languageVersion: LanguageVersion.Preview);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
@@ -30,14 +31,14 @@ public class Test_CanvasEffectPropertyGenerator_Analyzers
|
||||
const string source = """
|
||||
using ComputeSharp.D2D1.WinUI;
|
||||
|
||||
public class MyEffect
|
||||
public partial class MyEffect
|
||||
{
|
||||
[{|CMPSD2DWINUI0002:GeneratedCanvasEffectProperty|}]
|
||||
public int Number { get; }
|
||||
public partial int {|CS9248:Number|} { get; }
|
||||
}
|
||||
""";
|
||||
|
||||
await CSharpAnalyzerWithLanguageVersionTest<InvalidGeneratedCanvasEffectPropertyAccessorsAnalyzer>.VerifyAnalyzerAsync(source);
|
||||
await CSharpAnalyzerWithLanguageVersionTest<InvalidGeneratedCanvasEffectPropertyAccessorsAnalyzer>.VerifyAnalyzerAsync(source, languageVersion: LanguageVersion.Preview);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
@@ -46,13 +47,13 @@ public class Test_CanvasEffectPropertyGenerator_Analyzers
|
||||
const string source = """
|
||||
using ComputeSharp.D2D1.WinUI;
|
||||
|
||||
public abstract class MyEffect : CanvasEffect
|
||||
public abstract partial class MyEffect : CanvasEffect
|
||||
{
|
||||
[{|CMPSD2DWINUI0002:GeneratedCanvasEffectProperty|}]
|
||||
public int Number { get; init; }
|
||||
public partial int {|CS9248:Number|} { get; init; }
|
||||
}
|
||||
""";
|
||||
|
||||
await CSharpAnalyzerWithLanguageVersionTest<InvalidGeneratedCanvasEffectPropertyAccessorsAnalyzer>.VerifyAnalyzerAsync(source);
|
||||
await CSharpAnalyzerWithLanguageVersionTest<InvalidGeneratedCanvasEffectPropertyAccessorsAnalyzer>.VerifyAnalyzerAsync(source, languageVersion: LanguageVersion.Preview);
|
||||
}
|
||||
}
|
||||
+6
-6
@@ -17,7 +17,7 @@ public class Test_CanvasEffectPropertyGenerator_Incrementality
|
||||
abstract partial class MyEffect : CanvasEffect
|
||||
{
|
||||
[GeneratedCanvasEffectProperty]
|
||||
public int Number { get; set; }
|
||||
public partial int Number { get; set; }
|
||||
}
|
||||
"""";
|
||||
|
||||
@@ -27,7 +27,7 @@ public class Test_CanvasEffectPropertyGenerator_Incrementality
|
||||
abstract partial class MyEffect : CanvasEffect
|
||||
{
|
||||
[GeneratedCanvasEffectProperty(CanvasEffectInvalidationType.Creation)]
|
||||
public int Number { get; set; }
|
||||
public partial int Number { get; set; }
|
||||
}
|
||||
"""";
|
||||
|
||||
@@ -50,7 +50,7 @@ public class Test_CanvasEffectPropertyGenerator_Incrementality
|
||||
abstract partial class MyEffect : CanvasEffect
|
||||
{
|
||||
[GeneratedCanvasEffectProperty]
|
||||
public int Number { get; set; }
|
||||
public partial int Number { get; set; }
|
||||
}
|
||||
"""";
|
||||
|
||||
@@ -63,7 +63,7 @@ public class Test_CanvasEffectPropertyGenerator_Incrementality
|
||||
/// This is some property.
|
||||
/// </summary>
|
||||
[GeneratedCanvasEffectProperty]
|
||||
public int Number { get; set; }
|
||||
public partial int Number { get; set; }
|
||||
}
|
||||
"""";
|
||||
|
||||
@@ -86,7 +86,7 @@ public class Test_CanvasEffectPropertyGenerator_Incrementality
|
||||
abstract partial class MyEffect : CanvasEffect
|
||||
{
|
||||
[GeneratedCanvasEffectProperty]
|
||||
public int Number { get; set; }
|
||||
public partial int Number { get; set; }
|
||||
}
|
||||
"""";
|
||||
|
||||
@@ -100,7 +100,7 @@ public class Test_CanvasEffectPropertyGenerator_Incrementality
|
||||
}
|
||||
|
||||
[GeneratedCanvasEffectProperty]
|
||||
public int Number { get; set; }
|
||||
public partial int Number { get; set; }
|
||||
}
|
||||
"""";
|
||||
|
||||
|
||||
@@ -57,9 +57,10 @@ internal static class CSharpGeneratorTest<TGenerator>
|
||||
/// </summary>
|
||||
/// <param name="source">The input source to process.</param>
|
||||
/// <param name="result">The expected source to be generated.</param>
|
||||
public static void VerifySources(string source, (string Filename, string Source) result)
|
||||
/// <param name="languageVersion">The language version to use to run the test.</param>
|
||||
public static void VerifySources(string source, (string Filename, string Source) result, LanguageVersion languageVersion = LanguageVersion.CSharp12)
|
||||
{
|
||||
RunGenerator(source, out Compilation compilation, out ImmutableArray<Diagnostic> diagnostics);
|
||||
RunGenerator(source, out Compilation compilation, out ImmutableArray<Diagnostic> diagnostics, languageVersion);
|
||||
|
||||
// Ensure that no diagnostics were generated
|
||||
CollectionAssert.AreEquivalent(Array.Empty<Diagnostic>(), diagnostics);
|
||||
@@ -171,8 +172,9 @@ internal static class CSharpGeneratorTest<TGenerator>
|
||||
/// Creates a compilation from a given source.
|
||||
/// </summary>
|
||||
/// <param name="source">The input source to process.</param>
|
||||
/// <param name="languageVersion">The language version to use to run the test.</param>
|
||||
/// <returns>The resulting <see cref="Compilation"/> object.</returns>
|
||||
private static CSharpCompilation CreateCompilation(string source)
|
||||
private static CSharpCompilation CreateCompilation(string source, LanguageVersion languageVersion = LanguageVersion.CSharp12)
|
||||
{
|
||||
// Get all assembly references for the .NET TFM and ComputeSharp
|
||||
IEnumerable<MetadataReference> metadataReferences =
|
||||
@@ -189,10 +191,10 @@ internal static class CSharpGeneratorTest<TGenerator>
|
||||
#endif
|
||||
];
|
||||
|
||||
// Parse the source text (C# 12)
|
||||
// Parse the source text
|
||||
SyntaxTree sourceTree = CSharpSyntaxTree.ParseText(
|
||||
source,
|
||||
CSharpParseOptions.Default.WithLanguageVersion(LanguageVersion.CSharp12));
|
||||
CSharpParseOptions.Default.WithLanguageVersion(languageVersion));
|
||||
|
||||
// Create the original compilation
|
||||
return CSharpCompilation.Create(
|
||||
@@ -208,12 +210,14 @@ internal static class CSharpGeneratorTest<TGenerator>
|
||||
/// <param name="source">The input source to process.</param>
|
||||
/// <param name="compilation"><inheritdoc cref="GeneratorDriver.RunGeneratorsAndUpdateCompilation" path="/param[@name='outputCompilation']/node()"/></param>
|
||||
/// <param name="diagnostics"><inheritdoc cref="GeneratorDriver.RunGeneratorsAndUpdateCompilation" path="/param[@name='diagnostics']/node()"/></param>
|
||||
/// <param name="languageVersion">The language version to use to run the test.</param>
|
||||
private static void RunGenerator(
|
||||
string source,
|
||||
out Compilation compilation,
|
||||
out ImmutableArray<Diagnostic> diagnostics)
|
||||
out ImmutableArray<Diagnostic> diagnostics,
|
||||
LanguageVersion languageVersion = LanguageVersion.CSharp12)
|
||||
{
|
||||
Compilation originalCompilation = CreateCompilation(source);
|
||||
Compilation originalCompilation = CreateCompilation(source, languageVersion);
|
||||
|
||||
// Create the generator driver with the D2D shader generator
|
||||
GeneratorDriver driver = CSharpGeneratorDriver.Create(new TGenerator()).WithUpdatedParseOptions(originalCompilation.SyntaxTrees.First().Options);
|
||||
|
||||
新しいイシューから参照
ユーザーをブロックする