Add test for new accessibility analyzer
このコミットが含まれているのは:
1 親
cea408a4d4
コミット
d076ce5c05
3ファイル変更
+96
検索条件に一致するファイルはありません
@@ -0,0 +1,36 @@
|
||||
using System.Threading.Tasks;
|
||||
using ComputeSharp.SourceGenerators;
|
||||
using ComputeSharp.Tests.SourceGenerators.Helpers;
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
|
||||
namespace ComputeSharp.Tests.SourceGenerators;
|
||||
|
||||
[TestClass]
|
||||
[TestCategory("Analyzers")]
|
||||
public class AnalyzerTests
|
||||
{
|
||||
[TestMethod]
|
||||
public async Task InvalidShaderField()
|
||||
{
|
||||
const string source = """
|
||||
using ComputeSharp;
|
||||
|
||||
namespace MyFancyApp.Sample;
|
||||
|
||||
public partial class Foo
|
||||
{
|
||||
[{|CMPS0055:GeneratedComputeShaderDescriptor|}]
|
||||
private partial struct MyShader : IComputeShader
|
||||
{
|
||||
public ReadWriteBuffer<float> buffer;
|
||||
|
||||
public void Execute()
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
""";
|
||||
|
||||
await CSharpAnalyzerWithLanguageVersionTest<NotAccessibleGeneratedComputeShaderDescriptorAttributeTargetAnalyzer>.VerifyAnalyzerAsync(source);
|
||||
}
|
||||
}
|
||||
@@ -1,10 +1,15 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net7.0</TargetFramework>
|
||||
<RestoreSources>
|
||||
https://api.nuget.org/v3/index.json;
|
||||
https://pkgs.dev.azure.com/dnceng/public/_packaging/dotnet-tools/nuget/v3/index.json;
|
||||
</RestoreSources>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Basic.Reference.Assemblies.Net70" Version="1.4.5" />
|
||||
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.Analyzer.Testing.MSTest" Version="1.1.2-beta1.23509.1" />
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.7.2" />
|
||||
<PackageReference Include="MSTest.TestAdapter" Version="3.1.1" />
|
||||
<PackageReference Include="MSTest.TestFramework" Version="3.1.1" />
|
||||
|
||||
+55
@@ -0,0 +1,55 @@
|
||||
extern alias Core;
|
||||
extern alias D3D12;
|
||||
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.CodeAnalysis.CSharp.Testing;
|
||||
using Microsoft.CodeAnalysis.CSharp;
|
||||
using Microsoft.CodeAnalysis.Diagnostics;
|
||||
using Microsoft.CodeAnalysis.Testing.Verifiers;
|
||||
using Microsoft.CodeAnalysis.Testing;
|
||||
using Microsoft.CodeAnalysis;
|
||||
|
||||
namespace ComputeSharp.Tests.SourceGenerators.Helpers;
|
||||
|
||||
/// <summary>
|
||||
/// A custom <see cref="CSharpAnalyzerTest{TAnalyzer, TVerifier}"/> that uses a specific C# language version to parse code.
|
||||
/// </summary>
|
||||
/// <typeparam name="TAnalyzer">The type of the analyzer to test.</typeparam>
|
||||
internal sealed class CSharpAnalyzerWithLanguageVersionTest<TAnalyzer> : CSharpAnalyzerTest<TAnalyzer, MSTestVerifier>
|
||||
where TAnalyzer : DiagnosticAnalyzer, new()
|
||||
{
|
||||
/// <summary>
|
||||
/// The C# language version to use to parse code.
|
||||
/// </summary>
|
||||
private readonly LanguageVersion languageVersion;
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new <see cref="CSharpAnalyzerWithLanguageVersionTest{TAnalyzer}"/> instance with the specified paramaters.
|
||||
/// </summary>
|
||||
/// <param name="languageVersion">The C# language version to use to parse code.</param>
|
||||
private CSharpAnalyzerWithLanguageVersionTest(LanguageVersion languageVersion)
|
||||
{
|
||||
this.languageVersion = languageVersion;
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
protected override ParseOptions CreateParseOptions()
|
||||
{
|
||||
return new CSharpParseOptions(this.languageVersion, DocumentationMode.Diagnose);
|
||||
}
|
||||
|
||||
/// <inheritdoc cref="AnalyzerVerifier{TAnalyzer, TTest, TVerifier}.VerifyAnalyzerAsync"/>
|
||||
/// <param name="source">The source code to analyze.</param>
|
||||
/// <param name="languageVersion">The language version to use to run the test.</param>
|
||||
public static Task VerifyAnalyzerAsync(string source, LanguageVersion languageVersion = LanguageVersion.CSharp11)
|
||||
{
|
||||
CSharpAnalyzerWithLanguageVersionTest<TAnalyzer> test = new(languageVersion) { TestCode = source };
|
||||
|
||||
test.TestState.ReferenceAssemblies = ReferenceAssemblies.Net.Net70;
|
||||
test.TestState.AdditionalReferences.Add(MetadataReference.CreateFromFile(typeof(Core::ComputeSharp.Hlsl).Assembly.Location));
|
||||
test.TestState.AdditionalReferences.Add(MetadataReference.CreateFromFile(typeof(D3D12::ComputeSharp.IComputeShader).Assembly.Location));
|
||||
|
||||
return test.RunAsync(CancellationToken.None);
|
||||
}
|
||||
}
|
||||
新しいイシューから参照
ユーザーをブロックする