From 5cdb71684c92cb8fb50c03031f73c1d8820948ed Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Sat, 6 Jan 2024 23:26:20 +0100 Subject: [PATCH] Add MissingD2DShaderProfileOnD2DPixelShaderSourceMethodAnalyzer tests --- .../D2DPixelShaderSourceAttribute.cs | 2 +- ...D2DPixelShaderSourceGenerator_Analyzers.cs | 87 +++++++++++++++++++ 2 files changed, 88 insertions(+), 1 deletion(-) diff --git a/src/ComputeSharp.D2D1/Attributes/D2DPixelShaderSourceAttribute.cs b/src/ComputeSharp.D2D1/Attributes/D2DPixelShaderSourceAttribute.cs index da780e56..f1887143 100644 --- a/src/ComputeSharp.D2D1/Attributes/D2DPixelShaderSourceAttribute.cs +++ b/src/ComputeSharp.D2D1/Attributes/D2DPixelShaderSourceAttribute.cs @@ -21,7 +21,7 @@ namespace ComputeSharp.D2D1; /// float3 rgb = saturate(1.0 - color.rgb); /// return float4(rgb, 1); /// } -/// """")] +/// """)] /// static partial ReadOnlySpan<byte> GetBytecode(); /// /// diff --git a/tests/ComputeSharp.D2D1.Tests.SourceGenerators/Test_D2DPixelShaderSourceGenerator_Analyzers.cs b/tests/ComputeSharp.D2D1.Tests.SourceGenerators/Test_D2DPixelShaderSourceGenerator_Analyzers.cs index 12450fcc..5b4d26bf 100644 --- a/tests/ComputeSharp.D2D1.Tests.SourceGenerators/Test_D2DPixelShaderSourceGenerator_Analyzers.cs +++ b/tests/ComputeSharp.D2D1.Tests.SourceGenerators/Test_D2DPixelShaderSourceGenerator_Analyzers.cs @@ -71,4 +71,91 @@ public class Test_D2DPixelShaderSourceGenerator_Analyzers await CSharpAnalyzerWithLanguageVersionTest.VerifyAnalyzerAsync(source); } + + [TestMethod] + public async Task MissingShaderProfileForD2DPixelShaderSource_ShaderProfileOnMethod_DoesNotWarn() + { + const string source = """" + using System; + using ComputeSharp.D2D1; + + public partial class MyClass + { + [D2DPixelShaderSource(""" + #define D2D_INPUT_COUNT 0 + + #include "d2d1effecthelpers.hlsli" + + D2D_PS_ENTRY(Execute) + { + return 0; + } + """)] + [D2DShaderProfile(D2D1ShaderProfile.PixelShader50)] + public static partial ReadOnlySpan InvertEffect(); + + public static partial ReadOnlySpan InvertEffect() => default; + } + """"; + + await CSharpAnalyzerWithLanguageVersionTest.VerifyAnalyzerAsync(source); + } + + [TestMethod] + public async Task MissingShaderProfileForD2DPixelShaderSource_ShaderProfileOnAssembly_DoesNotWarn() + { + const string source = """" + using System; + using ComputeSharp.D2D1; + + [assembly: D2DShaderProfile(D2D1ShaderProfile.PixelShader50)] + + public partial class MyClass + { + [D2DPixelShaderSource(""" + #define D2D_INPUT_COUNT 0 + + #include "d2d1effecthelpers.hlsli" + + D2D_PS_ENTRY(Execute) + { + return 0; + } + """)] + public static partial ReadOnlySpan InvertEffect(); + + public static partial ReadOnlySpan InvertEffect() => default; + } + """"; + + await CSharpAnalyzerWithLanguageVersionTest.VerifyAnalyzerAsync(source); + } + + [TestMethod] + public async Task MissingShaderProfileForD2DPixelShaderSource_MissingShaderProfile_Warns() + { + const string source = """" + using System; + using ComputeSharp.D2D1; + + public partial class MyClass + { + [D2DPixelShaderSource(""" + #define D2D_INPUT_COUNT 0 + + #include "d2d1effecthelpers.hlsli" + + D2D_PS_ENTRY(Execute) + { + return 0; + } + """)] + public static partial ReadOnlySpan {|CMPSD2D0055:InvertEffect|}(); + + public static partial ReadOnlySpan InvertEffect() => default; + } + """"; + + await CSharpAnalyzerWithLanguageVersionTest.VerifyAnalyzerAsync(source); + } } \ No newline at end of file