Handle breaking changes

This commit is contained in:
Tyrrrz
2025-02-02 21:49:30 +02:00
parent c79a8c6502
commit 078ddeaf07
4 changed files with 53 additions and 53 deletions

View File

@@ -13,9 +13,11 @@ using Microsoft.CodeAnalysis.Text;
namespace CliFx.Analyzers.Tests.Utils;
internal class AnalyzerAssertions(DiagnosticAnalyzer analyzer)
: ReferenceTypeAssertions<DiagnosticAnalyzer, AnalyzerAssertions>(analyzer)
internal class AnalyzerAssertions(DiagnosticAnalyzer analyzer, AssertionChain assertionChain)
: ReferenceTypeAssertions<DiagnosticAnalyzer, AnalyzerAssertions>(analyzer, assertionChain)
{
private readonly AssertionChain _assertionChain = assertionChain;
protected override string Identifier => "analyzer";
private Compilation Compile(string sourceCode)
@@ -102,8 +104,8 @@ internal class AnalyzerAssertions(DiagnosticAnalyzer analyzer)
expectedDiagnosticIds.Intersect(producedDiagnosticIds).Count()
== expectedDiagnosticIds.Length;
Execute
.Assertion.ForCondition(isSuccessfulAssertion)
_assertionChain
.ForCondition(isSuccessfulAssertion)
.FailWith(() =>
{
var buffer = new StringBuilder();
@@ -146,8 +148,8 @@ internal class AnalyzerAssertions(DiagnosticAnalyzer analyzer)
var producedDiagnostics = GetProducedDiagnostics(sourceCode);
var isSuccessfulAssertion = !producedDiagnostics.Any();
Execute
.Assertion.ForCondition(isSuccessfulAssertion)
_assertionChain
.ForCondition(isSuccessfulAssertion)
.FailWith(() =>
{
var buffer = new StringBuilder();
@@ -170,5 +172,6 @@ internal class AnalyzerAssertions(DiagnosticAnalyzer analyzer)
internal static class AnalyzerAssertionsExtensions
{
public static AnalyzerAssertions Should(this DiagnosticAnalyzer analyzer) => new(analyzer);
public static AnalyzerAssertions Should(this DiagnosticAnalyzer analyzer) =>
new(analyzer, AssertionChain.GetOrCreate());
}

View File

@@ -1,7 +1,6 @@
using System;
using System.Collections.Generic;
using FluentAssertions;
using FluentAssertions.Execution;
using FluentAssertions.Primitives;
namespace CliFx.Tests.Utils.Extensions;
@@ -13,7 +12,7 @@ internal static class AssertionExtensions
params IEnumerable<string> lines
) =>
assertions
.Subject.Split(new[] { '\n', '\r' }, StringSplitOptions.RemoveEmptyEntries)
.Subject.Split(['\n', '\r'], StringSplitOptions.RemoveEmptyEntries)
.Should()
.Equal(lines);
@@ -30,7 +29,7 @@ internal static class AssertionExtensions
if (index < 0)
{
Execute.Assertion.FailWith(
assertions.CurrentAssertionChain.FailWith(
$"Expected string '{assertions.Subject}' to contain '{value}' after position {lastIndex}."
);
}

View File

@@ -6,12 +6,11 @@ namespace CliFx.Utils;
internal static class EnvironmentEx
{
private static readonly Lazy<string?> ProcessPathLazy =
new(() =>
{
using var process = Process.GetCurrentProcess();
return process.MainModule?.FileName;
});
private static readonly Lazy<string?> ProcessPathLazy = new(() =>
{
using var process = Process.GetCurrentProcess();
return process.MainModule?.FileName;
});
public static string? ProcessPath => ProcessPathLazy.Value;

View File

@@ -38,43 +38,42 @@ internal partial class StackFrame
private const string NotSpace = @"[^\x20\t]";
// Taken from https://github.com/atifaziz/StackTraceParser
private static readonly Regex Pattern =
new(
$$"""
^
{{Space}}*
\w+ {{Space}}+
(?<frame>
(?<type> {{NotSpace}}+ ) \.
(?<method> {{NotSpace}}+? ) {{Space}}*
(?<params> \( ( {{Space}}* \)
| (?<pt> .+?) {{Space}}+ (?<pn> .+?)
(, {{Space}}* (?<pt> .+?) {{Space}}+ (?<pn> .+?) )* \) ) )
( {{Space}}+
( # Microsoft .NET stack traces
\w+ {{Space}}+
(?<file> ( [a-z] \: # Windows rooted path starting with a drive letter
| / ) # Unix rooted path starting with a forward-slash
.+? )
\: \w+ {{Space}}+
(?<line> [0-9]+ ) \p{P}?
| # Mono stack traces
\[0x[0-9a-f]+\] {{Space}}+ \w+ {{Space}}+
<(?<file> [^>]+ )>
:(?<line> [0-9]+ )
)
)?
)
\s*
$
""",
RegexOptions.IgnoreCase
| RegexOptions.Multiline
| RegexOptions.ExplicitCapture
| RegexOptions.CultureInvariant
| RegexOptions.IgnorePatternWhitespace,
TimeSpan.FromSeconds(5)
);
private static readonly Regex Pattern = new(
$$"""
^
{{Space}}*
\w+ {{Space}}+
(?<frame>
(?<type> {{NotSpace}}+ ) \.
(?<method> {{NotSpace}}+? ) {{Space}}*
(?<params> \( ( {{Space}}* \)
| (?<pt> .+?) {{Space}}+ (?<pn> .+?)
(, {{Space}}* (?<pt> .+?) {{Space}}+ (?<pn> .+?) )* \) ) )
( {{Space}}+
( # Microsoft .NET stack traces
\w+ {{Space}}+
(?<file> ( [a-z] \: # Windows rooted path starting with a drive letter
| / ) # Unix rooted path starting with a forward-slash
.+? )
\: \w+ {{Space}}+
(?<line> [0-9]+ ) \p{P}?
| # Mono stack traces
\[0x[0-9a-f]+\] {{Space}}+ \w+ {{Space}}+
<(?<file> [^>]+ )>
:(?<line> [0-9]+ )
)
)?
)
\s*
$
""",
RegexOptions.IgnoreCase
| RegexOptions.Multiline
| RegexOptions.ExplicitCapture
| RegexOptions.CultureInvariant
| RegexOptions.IgnorePatternWhitespace,
TimeSpan.FromSeconds(5)
);
public static IEnumerable<StackFrame> ParseTrace(string stackTrace)
{