diff --git a/CliFx.Analyzers.Tests/Utils/AnalyzerAssertions.cs b/CliFx.Analyzers.Tests/Utils/AnalyzerAssertions.cs index db20562..e35d89e 100644 --- a/CliFx.Analyzers.Tests/Utils/AnalyzerAssertions.cs +++ b/CliFx.Analyzers.Tests/Utils/AnalyzerAssertions.cs @@ -13,9 +13,11 @@ using Microsoft.CodeAnalysis.Text; namespace CliFx.Analyzers.Tests.Utils; -internal class AnalyzerAssertions(DiagnosticAnalyzer analyzer) - : ReferenceTypeAssertions(analyzer) +internal class AnalyzerAssertions(DiagnosticAnalyzer analyzer, AssertionChain assertionChain) + : ReferenceTypeAssertions(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()); } diff --git a/CliFx.Tests/Utils/Extensions/AssertionExtensions.cs b/CliFx.Tests/Utils/Extensions/AssertionExtensions.cs index 8ef3fd4..8e5fa2e 100644 --- a/CliFx.Tests/Utils/Extensions/AssertionExtensions.cs +++ b/CliFx.Tests/Utils/Extensions/AssertionExtensions.cs @@ -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 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}." ); } diff --git a/CliFx/Utils/EnvironmentEx.cs b/CliFx/Utils/EnvironmentEx.cs index 64ccbe8..972afaa 100644 --- a/CliFx/Utils/EnvironmentEx.cs +++ b/CliFx/Utils/EnvironmentEx.cs @@ -6,12 +6,11 @@ namespace CliFx.Utils; internal static class EnvironmentEx { - private static readonly Lazy ProcessPathLazy = - new(() => - { - using var process = Process.GetCurrentProcess(); - return process.MainModule?.FileName; - }); + private static readonly Lazy ProcessPathLazy = new(() => + { + using var process = Process.GetCurrentProcess(); + return process.MainModule?.FileName; + }); public static string? ProcessPath => ProcessPathLazy.Value; diff --git a/CliFx/Utils/StackFrame.cs b/CliFx/Utils/StackFrame.cs index 21f12aa..f88a6d5 100644 --- a/CliFx/Utils/StackFrame.cs +++ b/CliFx/Utils/StackFrame.cs @@ -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}}+ - (? - (? {{NotSpace}}+ ) \. - (? {{NotSpace}}+? ) {{Space}}* - (? \( ( {{Space}}* \) - | (? .+?) {{Space}}+ (? .+?) - (, {{Space}}* (? .+?) {{Space}}+ (? .+?) )* \) ) ) - ( {{Space}}+ - ( # Microsoft .NET stack traces - \w+ {{Space}}+ - (? ( [a-z] \: # Windows rooted path starting with a drive letter - | / ) # Unix rooted path starting with a forward-slash - .+? ) - \: \w+ {{Space}}+ - (? [0-9]+ ) \p{P}? - | # Mono stack traces - \[0x[0-9a-f]+\] {{Space}}+ \w+ {{Space}}+ - <(? [^>]+ )> - :(? [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}}+ + (? + (? {{NotSpace}}+ ) \. + (? {{NotSpace}}+? ) {{Space}}* + (? \( ( {{Space}}* \) + | (? .+?) {{Space}}+ (? .+?) + (, {{Space}}* (? .+?) {{Space}}+ (? .+?) )* \) ) ) + ( {{Space}}+ + ( # Microsoft .NET stack traces + \w+ {{Space}}+ + (? ( [a-z] \: # Windows rooted path starting with a drive letter + | / ) # Unix rooted path starting with a forward-slash + .+? ) + \: \w+ {{Space}}+ + (? [0-9]+ ) \p{P}? + | # Mono stack traces + \[0x[0-9a-f]+\] {{Space}}+ \w+ {{Space}}+ + <(? [^>]+ )> + :(? [0-9]+ ) + ) + )? + ) + \s* + $ + """, + RegexOptions.IgnoreCase + | RegexOptions.Multiline + | RegexOptions.ExplicitCapture + | RegexOptions.CultureInvariant + | RegexOptions.IgnorePatternWhitespace, + TimeSpan.FromSeconds(5) + ); public static IEnumerable ParseTrace(string stackTrace) {