diff --git a/tests/ComputeSharp.D2D1.WinUI.Tests.SourceGenerators/Test_CanvasEffectPropertyGenerator.cs b/tests/ComputeSharp.D2D1.WinUI.Tests.SourceGenerators/Test_CanvasEffectPropertyGenerator.cs index e637788a..6597d5ac 100644 --- a/tests/ComputeSharp.D2D1.WinUI.Tests.SourceGenerators/Test_CanvasEffectPropertyGenerator.cs +++ b/tests/ComputeSharp.D2D1.WinUI.Tests.SourceGenerators/Test_CanvasEffectPropertyGenerator.cs @@ -33,7 +33,7 @@ public class Test_CanvasEffectPropertyGenerator partial class MyEffect { /// - [global::System.CodeDom.Compiler.GeneratedCode("ComputeSharp.D2D1.WinUI.CanvasEffectPropertyGenerator", "3.0.0.0")] + [global::System.CodeDom.Compiler.GeneratedCode("ComputeSharp.D2D1.WinUI.CanvasEffectPropertyGenerator", )] [global::System.Diagnostics.DebuggerNonUserCode] [global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage] public partial int Number @@ -63,27 +63,27 @@ public class Test_CanvasEffectPropertyGenerator /// Executes the logic for when is changing. /// The new property value being set. /// This method is invoked right before the value of is changed. - [global::System.CodeDom.Compiler.GeneratedCode("ComputeSharp.D2D1.WinUI.CanvasEffectPropertyGenerator", "3.0.0.0")] + [global::System.CodeDom.Compiler.GeneratedCode("ComputeSharp.D2D1.WinUI.CanvasEffectPropertyGenerator", )] partial void OnNumberChanging(int newValue); /// Executes the logic for when is changing. /// The previous property value that is being replaced. /// The new property value being set. /// This method is invoked right before the value of is changed. - [global::System.CodeDom.Compiler.GeneratedCode("ComputeSharp.D2D1.WinUI.CanvasEffectPropertyGenerator", "3.0.0.0")] + [global::System.CodeDom.Compiler.GeneratedCode("ComputeSharp.D2D1.WinUI.CanvasEffectPropertyGenerator", )] partial void OnNumberChanging(int oldValue, int newValue); /// Executes the logic for when has just changed. /// The new property value that has been set. /// This method is invoked right after the value of is changed. - [global::System.CodeDom.Compiler.GeneratedCode("ComputeSharp.D2D1.WinUI.CanvasEffectPropertyGenerator", "3.0.0.0")] + [global::System.CodeDom.Compiler.GeneratedCode("ComputeSharp.D2D1.WinUI.CanvasEffectPropertyGenerator", )] partial void OnNumberChanged(int newValue); /// Executes the logic for when has just changed. /// The previous property value that has been replaced. /// The new property value that has been set. /// This method is invoked right after the value of is changed. - [global::System.CodeDom.Compiler.GeneratedCode("ComputeSharp.D2D1.WinUI.CanvasEffectPropertyGenerator", "3.0.0.0")] + [global::System.CodeDom.Compiler.GeneratedCode("ComputeSharp.D2D1.WinUI.CanvasEffectPropertyGenerator", )] partial void OnNumberChanged(int oldValue, int newValue); } } @@ -117,7 +117,7 @@ public class Test_CanvasEffectPropertyGenerator partial class MyEffect { /// - [global::System.CodeDom.Compiler.GeneratedCode("ComputeSharp.D2D1.WinUI.CanvasEffectPropertyGenerator", "3.0.0.0")] + [global::System.CodeDom.Compiler.GeneratedCode("ComputeSharp.D2D1.WinUI.CanvasEffectPropertyGenerator", )] [global::System.Diagnostics.DebuggerNonUserCode] [global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage] public partial object? Instance @@ -147,27 +147,27 @@ public class Test_CanvasEffectPropertyGenerator /// Executes the logic for when is changing. /// The new property value being set. /// This method is invoked right before the value of is changed. - [global::System.CodeDom.Compiler.GeneratedCode("ComputeSharp.D2D1.WinUI.CanvasEffectPropertyGenerator", "3.0.0.0")] + [global::System.CodeDom.Compiler.GeneratedCode("ComputeSharp.D2D1.WinUI.CanvasEffectPropertyGenerator", )] partial void OnInstanceChanging(object? newValue); /// Executes the logic for when is changing. /// The previous property value that is being replaced. /// The new property value being set. /// This method is invoked right before the value of is changed. - [global::System.CodeDom.Compiler.GeneratedCode("ComputeSharp.D2D1.WinUI.CanvasEffectPropertyGenerator", "3.0.0.0")] + [global::System.CodeDom.Compiler.GeneratedCode("ComputeSharp.D2D1.WinUI.CanvasEffectPropertyGenerator", )] partial void OnInstanceChanging(object? oldValue, object? newValue); /// Executes the logic for when has just changed. /// The new property value that has been set. /// This method is invoked right after the value of is changed. - [global::System.CodeDom.Compiler.GeneratedCode("ComputeSharp.D2D1.WinUI.CanvasEffectPropertyGenerator", "3.0.0.0")] + [global::System.CodeDom.Compiler.GeneratedCode("ComputeSharp.D2D1.WinUI.CanvasEffectPropertyGenerator", )] partial void OnInstanceChanged(object? newValue); /// Executes the logic for when has just changed. /// The previous property value that has been replaced. /// The new property value that has been set. /// This method is invoked right after the value of is changed. - [global::System.CodeDom.Compiler.GeneratedCode("ComputeSharp.D2D1.WinUI.CanvasEffectPropertyGenerator", "3.0.0.0")] + [global::System.CodeDom.Compiler.GeneratedCode("ComputeSharp.D2D1.WinUI.CanvasEffectPropertyGenerator", )] partial void OnInstanceChanged(object? oldValue, object? newValue); } } @@ -201,7 +201,7 @@ public class Test_CanvasEffectPropertyGenerator partial class MyEffect { /// - [global::System.CodeDom.Compiler.GeneratedCode("ComputeSharp.D2D1.WinUI.CanvasEffectPropertyGenerator", "3.0.0.0")] + [global::System.CodeDom.Compiler.GeneratedCode("ComputeSharp.D2D1.WinUI.CanvasEffectPropertyGenerator", )] [global::System.Diagnostics.DebuggerNonUserCode] [global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage] public partial object Instance @@ -231,27 +231,27 @@ public class Test_CanvasEffectPropertyGenerator /// Executes the logic for when is changing. /// The new property value being set. /// This method is invoked right before the value of is changed. - [global::System.CodeDom.Compiler.GeneratedCode("ComputeSharp.D2D1.WinUI.CanvasEffectPropertyGenerator", "3.0.0.0")] + [global::System.CodeDom.Compiler.GeneratedCode("ComputeSharp.D2D1.WinUI.CanvasEffectPropertyGenerator", )] partial void OnInstanceChanging(object newValue); /// Executes the logic for when is changing. /// The previous property value that is being replaced. /// The new property value being set. /// This method is invoked right before the value of is changed. - [global::System.CodeDom.Compiler.GeneratedCode("ComputeSharp.D2D1.WinUI.CanvasEffectPropertyGenerator", "3.0.0.0")] + [global::System.CodeDom.Compiler.GeneratedCode("ComputeSharp.D2D1.WinUI.CanvasEffectPropertyGenerator", )] partial void OnInstanceChanging(object? oldValue, object newValue); /// Executes the logic for when has just changed. /// The new property value that has been set. /// This method is invoked right after the value of is changed. - [global::System.CodeDom.Compiler.GeneratedCode("ComputeSharp.D2D1.WinUI.CanvasEffectPropertyGenerator", "3.0.0.0")] + [global::System.CodeDom.Compiler.GeneratedCode("ComputeSharp.D2D1.WinUI.CanvasEffectPropertyGenerator", )] partial void OnInstanceChanged(object newValue); /// Executes the logic for when has just changed. /// The previous property value that has been replaced. /// The new property value that has been set. /// This method is invoked right after the value of is changed. - [global::System.CodeDom.Compiler.GeneratedCode("ComputeSharp.D2D1.WinUI.CanvasEffectPropertyGenerator", "3.0.0.0")] + [global::System.CodeDom.Compiler.GeneratedCode("ComputeSharp.D2D1.WinUI.CanvasEffectPropertyGenerator", )] partial void OnInstanceChanged(object? oldValue, object newValue); } } @@ -285,7 +285,7 @@ public class Test_CanvasEffectPropertyGenerator partial class MyEffect { /// - [global::System.CodeDom.Compiler.GeneratedCode("ComputeSharp.D2D1.WinUI.CanvasEffectPropertyGenerator", "3.0.0.0")] + [global::System.CodeDom.Compiler.GeneratedCode("ComputeSharp.D2D1.WinUI.CanvasEffectPropertyGenerator", )] [global::System.Diagnostics.DebuggerNonUserCode] [global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage] public partial int Number @@ -315,27 +315,27 @@ public class Test_CanvasEffectPropertyGenerator /// Executes the logic for when is changing. /// The new property value being set. /// This method is invoked right before the value of is changed. - [global::System.CodeDom.Compiler.GeneratedCode("ComputeSharp.D2D1.WinUI.CanvasEffectPropertyGenerator", "3.0.0.0")] + [global::System.CodeDom.Compiler.GeneratedCode("ComputeSharp.D2D1.WinUI.CanvasEffectPropertyGenerator", )] partial void OnNumberChanging(int newValue); /// Executes the logic for when is changing. /// The previous property value that is being replaced. /// The new property value being set. /// This method is invoked right before the value of is changed. - [global::System.CodeDom.Compiler.GeneratedCode("ComputeSharp.D2D1.WinUI.CanvasEffectPropertyGenerator", "3.0.0.0")] + [global::System.CodeDom.Compiler.GeneratedCode("ComputeSharp.D2D1.WinUI.CanvasEffectPropertyGenerator", )] partial void OnNumberChanging(int oldValue, int newValue); /// Executes the logic for when has just changed. /// The new property value that has been set. /// This method is invoked right after the value of is changed. - [global::System.CodeDom.Compiler.GeneratedCode("ComputeSharp.D2D1.WinUI.CanvasEffectPropertyGenerator", "3.0.0.0")] + [global::System.CodeDom.Compiler.GeneratedCode("ComputeSharp.D2D1.WinUI.CanvasEffectPropertyGenerator", )] partial void OnNumberChanged(int newValue); /// Executes the logic for when has just changed. /// The previous property value that has been replaced. /// The new property value that has been set. /// This method is invoked right after the value of is changed. - [global::System.CodeDom.Compiler.GeneratedCode("ComputeSharp.D2D1.WinUI.CanvasEffectPropertyGenerator", "3.0.0.0")] + [global::System.CodeDom.Compiler.GeneratedCode("ComputeSharp.D2D1.WinUI.CanvasEffectPropertyGenerator", )] partial void OnNumberChanged(int oldValue, int newValue); } } @@ -372,7 +372,7 @@ public class Test_CanvasEffectPropertyGenerator partial class MyEffect { /// - [global::System.CodeDom.Compiler.GeneratedCode("ComputeSharp.D2D1.WinUI.CanvasEffectPropertyGenerator", "3.0.0.0")] + [global::System.CodeDom.Compiler.GeneratedCode("ComputeSharp.D2D1.WinUI.CanvasEffectPropertyGenerator", )] [global::System.Diagnostics.DebuggerNonUserCode] [global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage] public partial int X @@ -400,7 +400,7 @@ public class Test_CanvasEffectPropertyGenerator } /// - [global::System.CodeDom.Compiler.GeneratedCode("ComputeSharp.D2D1.WinUI.CanvasEffectPropertyGenerator", "3.0.0.0")] + [global::System.CodeDom.Compiler.GeneratedCode("ComputeSharp.D2D1.WinUI.CanvasEffectPropertyGenerator", )] [global::System.Diagnostics.DebuggerNonUserCode] [global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage] public partial int Y @@ -430,53 +430,53 @@ public class Test_CanvasEffectPropertyGenerator /// Executes the logic for when is changing. /// The new property value being set. /// This method is invoked right before the value of is changed. - [global::System.CodeDom.Compiler.GeneratedCode("ComputeSharp.D2D1.WinUI.CanvasEffectPropertyGenerator", "3.0.0.0")] + [global::System.CodeDom.Compiler.GeneratedCode("ComputeSharp.D2D1.WinUI.CanvasEffectPropertyGenerator", )] partial void OnXChanging(int newValue); /// Executes the logic for when is changing. /// The previous property value that is being replaced. /// The new property value being set. /// This method is invoked right before the value of is changed. - [global::System.CodeDom.Compiler.GeneratedCode("ComputeSharp.D2D1.WinUI.CanvasEffectPropertyGenerator", "3.0.0.0")] + [global::System.CodeDom.Compiler.GeneratedCode("ComputeSharp.D2D1.WinUI.CanvasEffectPropertyGenerator", )] partial void OnXChanging(int oldValue, int newValue); /// Executes the logic for when has just changed. /// The new property value that has been set. /// This method is invoked right after the value of is changed. - [global::System.CodeDom.Compiler.GeneratedCode("ComputeSharp.D2D1.WinUI.CanvasEffectPropertyGenerator", "3.0.0.0")] + [global::System.CodeDom.Compiler.GeneratedCode("ComputeSharp.D2D1.WinUI.CanvasEffectPropertyGenerator", )] partial void OnXChanged(int newValue); /// Executes the logic for when has just changed. /// The previous property value that has been replaced. /// The new property value that has been set. /// This method is invoked right after the value of is changed. - [global::System.CodeDom.Compiler.GeneratedCode("ComputeSharp.D2D1.WinUI.CanvasEffectPropertyGenerator", "3.0.0.0")] + [global::System.CodeDom.Compiler.GeneratedCode("ComputeSharp.D2D1.WinUI.CanvasEffectPropertyGenerator", )] partial void OnXChanged(int oldValue, int newValue); /// Executes the logic for when is changing. /// The new property value being set. /// This method is invoked right before the value of is changed. - [global::System.CodeDom.Compiler.GeneratedCode("ComputeSharp.D2D1.WinUI.CanvasEffectPropertyGenerator", "3.0.0.0")] + [global::System.CodeDom.Compiler.GeneratedCode("ComputeSharp.D2D1.WinUI.CanvasEffectPropertyGenerator", )] partial void OnYChanging(int newValue); /// Executes the logic for when is changing. /// The previous property value that is being replaced. /// The new property value being set. /// This method is invoked right before the value of is changed. - [global::System.CodeDom.Compiler.GeneratedCode("ComputeSharp.D2D1.WinUI.CanvasEffectPropertyGenerator", "3.0.0.0")] + [global::System.CodeDom.Compiler.GeneratedCode("ComputeSharp.D2D1.WinUI.CanvasEffectPropertyGenerator", )] partial void OnYChanging(int oldValue, int newValue); /// Executes the logic for when has just changed. /// The new property value that has been set. /// This method is invoked right after the value of is changed. - [global::System.CodeDom.Compiler.GeneratedCode("ComputeSharp.D2D1.WinUI.CanvasEffectPropertyGenerator", "3.0.0.0")] + [global::System.CodeDom.Compiler.GeneratedCode("ComputeSharp.D2D1.WinUI.CanvasEffectPropertyGenerator", )] partial void OnYChanged(int newValue); /// Executes the logic for when has just changed. /// The previous property value that has been replaced. /// The new property value that has been set. /// This method is invoked right after the value of is changed. - [global::System.CodeDom.Compiler.GeneratedCode("ComputeSharp.D2D1.WinUI.CanvasEffectPropertyGenerator", "3.0.0.0")] + [global::System.CodeDom.Compiler.GeneratedCode("ComputeSharp.D2D1.WinUI.CanvasEffectPropertyGenerator", )] partial void OnYChanged(int oldValue, int newValue); } } diff --git a/tests/ComputeSharp.D2D1.WinUI.Tests.SourceGenerators/Test_CanvasEffectPropertyGenerator_Analyzers.cs b/tests/ComputeSharp.D2D1.WinUI.Tests.SourceGenerators/Test_CanvasEffectPropertyGenerator_Analyzers.cs index 91b4b164..7489ecf7 100644 --- a/tests/ComputeSharp.D2D1.WinUI.Tests.SourceGenerators/Test_CanvasEffectPropertyGenerator_Analyzers.cs +++ b/tests/ComputeSharp.D2D1.WinUI.Tests.SourceGenerators/Test_CanvasEffectPropertyGenerator_Analyzers.cs @@ -173,4 +173,38 @@ public class Test_CanvasEffectPropertyGenerator_Analyzers await CSharpAnalyzerWithLanguageVersionTest.VerifyAnalyzerAsync(source, languageVersion: LanguageVersion.Preview); } + + [TestMethod] + public async Task RequireCSharpLanguageVersionPreviewAnalyzer_LanguageVersionIsNotPreview_Warns() + { + const string source = """ + using System; + using ComputeSharp.D2D1.WinUI; + + public abstract partial class MyEffect : CanvasEffect + { + [{|CMPSD2DWINUI0007:GeneratedCanvasEffectProperty|}] + public int Number { get; set; } + } + """; + + await CSharpAnalyzerWithLanguageVersionTest.VerifyAnalyzerAsync(source); + } + + [TestMethod] + public async Task RequireCSharpLanguageVersionPreviewAnalyzer_LanguageVersionIsPreview_DoesNotWarn() + { + const string source = """ + using System; + using ComputeSharp.D2D1.WinUI; + + public abstract partial class MyEffect : CanvasEffect + { + [GeneratedCanvasEffectProperty] + public int Number { get; set; } + } + """; + + await CSharpAnalyzerWithLanguageVersionTest.VerifyAnalyzerAsync(source, languageVersion: LanguageVersion.Preview); + } } \ No newline at end of file diff --git a/tests/ComputeSharp.D2D1.WinUI.Tests.SourceGenerators/Test_CanvasEffectPropertyGenerator_Incrementality.cs b/tests/ComputeSharp.D2D1.WinUI.Tests.SourceGenerators/Test_CanvasEffectPropertyGenerator_Incrementality.cs index ae987d10..2248b818 100644 --- a/tests/ComputeSharp.D2D1.WinUI.Tests.SourceGenerators/Test_CanvasEffectPropertyGenerator_Incrementality.cs +++ b/tests/ComputeSharp.D2D1.WinUI.Tests.SourceGenerators/Test_CanvasEffectPropertyGenerator_Incrementality.cs @@ -1,6 +1,7 @@ using ComputeSharp.D2D1.WinUI.SourceGenerators; using ComputeSharp.Tests.SourceGenerators.Helpers; using Microsoft.CodeAnalysis; +using Microsoft.CodeAnalysis.CSharp; using Microsoft.VisualStudio.TestTools.UnitTesting; namespace ComputeSharp.D2D1.WinUI.Tests.SourceGenerators; @@ -38,7 +39,8 @@ public class Test_CanvasEffectPropertyGenerator_Incrementality diagnosticsReason: null, outputReason: IncrementalStepRunReason.Modified, diagnosticsSourceReason: null, - sourceReason: IncrementalStepRunReason.Modified); + sourceReason: IncrementalStepRunReason.Modified, + languageVersion: LanguageVersion.Preview); } [TestMethod] @@ -74,7 +76,8 @@ public class Test_CanvasEffectPropertyGenerator_Incrementality diagnosticsReason: null, outputReason: IncrementalStepRunReason.Cached, diagnosticsSourceReason: null, - sourceReason: IncrementalStepRunReason.Cached); + sourceReason: IncrementalStepRunReason.Cached, + languageVersion: LanguageVersion.Preview); } [TestMethod] @@ -111,6 +114,7 @@ public class Test_CanvasEffectPropertyGenerator_Incrementality diagnosticsReason: null, outputReason: IncrementalStepRunReason.Cached, diagnosticsSourceReason: null, - sourceReason: IncrementalStepRunReason.Cached); + sourceReason: IncrementalStepRunReason.Cached, + languageVersion: LanguageVersion.Preview); } } \ No newline at end of file diff --git a/tests/ComputeSharp.Tests.SourceGenerators/Helpers/CSharpGeneratorTest{TGenerator}.cs b/tests/ComputeSharp.Tests.SourceGenerators/Helpers/CSharpGeneratorTest{TGenerator}.cs index 7670c841..1d29bfaf 100644 --- a/tests/ComputeSharp.Tests.SourceGenerators/Helpers/CSharpGeneratorTest{TGenerator}.cs +++ b/tests/ComputeSharp.Tests.SourceGenerators/Helpers/CSharpGeneratorTest{TGenerator}.cs @@ -83,6 +83,7 @@ internal static class CSharpGeneratorTest /// The reason for the "Output" step. /// The reason for the output step for the diagnostics. /// The reason for the final output source. + /// The language version to use to run the test. public static void VerifyIncrementalSteps( string source, string updatedSource, @@ -90,9 +91,10 @@ internal static class CSharpGeneratorTest IncrementalStepRunReason? diagnosticsReason, IncrementalStepRunReason outputReason, IncrementalStepRunReason? diagnosticsSourceReason, - IncrementalStepRunReason sourceReason) + IncrementalStepRunReason sourceReason, + LanguageVersion languageVersion = LanguageVersion.CSharp12) { - Compilation compilation = CreateCompilation(source); + Compilation compilation = CreateCompilation(source, languageVersion); GeneratorDriver driver = CSharpGeneratorDriver.Create( generators: [new TGenerator().AsSourceGenerator()], @@ -104,7 +106,7 @@ internal static class CSharpGeneratorTest // Update the compilation by replacing the source compilation = compilation.ReplaceSyntaxTree( compilation.SyntaxTrees.First(), - CSharpSyntaxTree.ParseText(updatedSource, CSharpParseOptions.Default.WithLanguageVersion(LanguageVersion.CSharp12))); + CSharpSyntaxTree.ParseText(updatedSource, CSharpParseOptions.Default.WithLanguageVersion(languageVersion))); // Run the generators again on the updated source driver = driver.RunGenerators(compilation);