StyleChecker works, tests dont

This commit is contained in:
Simon Lübeß
2025-08-03 11:58:27 +02:00
parent 41dacf72b6
commit 184b92e95c
9 changed files with 394 additions and 191 deletions
@@ -0,0 +1,120 @@
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System.Threading.Tasks;
using VerifyCS = MakeConst.Test.CSharpCodeFixVerifier<
ScriptCoreGenerator.StyleCheckers.CatchUnmanagedCallersOnlyAnalyzer,
ScriptCoreGenerator.StyleCheckers.CatchUnmanagedCallersOnlyFixProvider>;
namespace ScriptCoreGenerator.Test.StyleCheckers
{
[TestClass]
public class CatchUnmanagedCallersOnlyTest
{
//No diagnostics expected to show up
[TestMethod]
public async Task TestEmpty()
{
var test = @"";
await VerifyCS.VerifyAnalyzerAsync(test);
}
[TestMethod]
public async Task TestNoDiagnosticsMethodWithStatementBlock()
{
var test = @"""
using System;
class Program
{
static void Main()
{
Console.WriteLine(i);
}
}
""";
await VerifyCS.VerifyAnalyzerAsync(test);
}
[TestMethod]
public async Task TestNoDiagnosticsWithArrowFunction()
{
var test = @"""
using System;
class Program
{
static void Main() => Console.WriteLine(i);
}
""";
await VerifyCS.VerifyAnalyzerAsync(test);
}
[TestMethod]
public async Task TestNoDiagnosticWithCorrectMethod()
{
await VerifyCS.VerifyAnalyzerAsync(@"
using System;
using System.Runtime.InteropServices;
class Program
{
[UnmanagedCallersOnly]
static void Main()
{
try
{
const int i = 0;
Console.WriteLine(i);
}
catch (Exception e)
{
}
}
}
");
}
[TestMethod]
public async Task LocalIntCouldBeConstant_Diagnostic()
{
await VerifyCS.VerifyCodeFixAsync(
@"""
using System;
using System.Runtime.InteropServices;
class Program
{
[[|UnmanagedCallersOnly|]]
static void Main()
{
int i = 0;
Console.WriteLine(i);
}
}
""",
@"""
using System;
using System.Runtime.InteropServices;
class Program
{
[UnmanagedCallersOnly]
static void Main()
{
try
{
const int i = 0;
Console.WriteLine(i);
}
catch (Exception e)
{
}
}
}
""");
}
}
}