Skip to content

Possible issue with DiffMarkupFormatter.Instance #60

Closed
@dannoh

Description

We are using Verify with BUnit on a fairly large project, with many tests using .Verify We increasingly see the following exception in our tests when we run the entire suite. When running smaller sub-groups the error will not occur and we can continue.

As shown below the error occurs in the AngleSharp PrettyMarkupFormatter when it tries to indent by a negative number.
The problem I can (easily) see is that Verify.Bunit uses the static instance of DiffMarkupFormatter meaning that it is keeping count of open tags across all tests, so any test that is invalid, will break all tests after that.

Locally I made the change to create a new DiffMarkupFormatter each time instead of using .Instance and it appears to have solved the problem. I can submit a PR, but being very new to this code base I wanted to get some feedback first.

System.ArgumentOutOfRangeException
Specified argument was out of the range of valid values. (Parameter 'count')
   at System.Linq.ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument argument)
   at System.Linq.Enumerable.Repeat[TResult](TResult element, Int32 count)
   at AngleSharp.Html.PrettyMarkupFormatter.IndentBefore(Int32 i)
   at AngleSharp.Html.PrettyMarkupFormatter.OpenTag(IElement element, Boolean selfClosing)
   at Bunit.Diffing.DiffMarkupFormatter.OpenTag(IElement element, Boolean selfClosing) in /_/src/bunit.web/Diffing/DiffMarkupFormatter.cs:line 51
   at AngleSharp.Dom.Node.ToHtml(TextWriter writer, IMarkupFormatter formatter)
   at AngleSharp.FormatExtensions.ToHtml(IMarkupFormattable markup, IMarkupFormatter formatter)
   at MarkupFormattableToString.Convert(IMarkupFormattable markup, IReadOnlyDictionary`2 context) in C:\projects\verify-bunit\src\Verify.Bunit\MarkupFormattableToString.cs:line 4
   at VerifyTests.VerifierSettings.<>c__DisplayClass166_0`1.<RegisterFileConverter>b__0(T o, IReadOnlyDictionary`2 context) in /_/src/Verify/Splitters/Settings_Typed.cs:line 30
   at VerifyTests.VerifierSettings.<>c__DisplayClass167_0`1.<RegisterFileConverter>b__0(Object o, IReadOnlyDictionary`2 context) in /_/src/Verify/Splitters/Settings_Typed.cs:line 39
   at VerifyTests.InnerVerifier.Verify(Object target) in /_/src/Verify/Verifier/InnerVerifier_Object.cs:line 67
   at VerifyXunit.Verifier.<>c__DisplayClass9_0.<<Verify>b__0>d.MoveNext() in /_/src/Verify.Xunit/Verifier.cs:line 74
--- End of stack trace from previous location ---
   at Web.Pages.Students.SemesterDetailsTests.RendersCorrectly__WhenStudent__AndViewIs__Certificate() in C:\code\work\gnl\gnl.sams\app\Gnl.Sams.Ops.Web.UnitTests\Pages\Students\SemesterDetailsTests.cs:line 440
   at Xunit.Sdk.TestInvoker`1.<>c__DisplayClass47_0.<<InvokeTestMethodAsync>b__1>d.MoveNext() in /_/src/xunit.execution/Sdk/Frameworks/Runners/TestInvoker.cs:line 259
--- End of stack trace from previous location ---
   at Xunit.Sdk.ExecutionTimer.AggregateAsync(Func`1 asyncAction) in /_/src/xunit.execution/Sdk/Frameworks/ExecutionTimer.cs:line 48
   at Xunit.Sdk.ExceptionAggregator.RunAsync(Func`1 code) in /_/src/xunit.core/Sdk/ExceptionAggregator.cs:line 90

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions