Smarter formatting
See original GitHub issueThe DefaultFormatter
recursively prints all non-private members of an object graph to a limit of 5 levels.
#889 showed that with a limit of 15 this could cause an OOM.
var col = new HtmlNodeCollection(new HtmlNode(HtmlNodeType.Element, new HtmlDocument(), 0));
col.Add(new HtmlNode(HtmlNodeType.Element, new HtmlDocument(), 0));
col.Should().BeNullOrEmpty();
When I run the test, the failure message contains both the internal field _ownerdocument
and the public property OwnerDocument
.
OwnerDocument is just returning _ownerdocument.
https://github.com/zzzprojects/html-agility-pack/blob/master/src/HtmlAgilityPack.Shared/HtmlNode.cs
Can we somehow limit the formatter to only select internal members if their DeclaringType
is marked with InternalsVisibleTo
the assembly containing the unit test?
Maybe the AppDomain
is of any help?
I don’t think we should exclude internal members in general, as people tend to use internal access modifier to expose the members to unit tests.
Issue Analytics
- State:
- Created 5 years ago
- Comments:8 (8 by maintainers)
Top GitHub Comments
#1469 prevents it from throwing an OOM, so the main problem is solved ✅
There are still related things that would be nice to improve when formatting complex object graphs, but I don’t think any of those are a blocker for shipping 6.0.
Many of the properties on
HtmlNode
are simply forwarding an internal field, so it would be nice to exclude fields and/or internal members from the failure message. That helps hiding the unimportant and emphasizing the important.A workaround is to add a custom formatter for
HtmlNode
and exclude the unwanted members. If you want to do that for multiple types, it may be nice with built-in handles to control that, e.g. on theFormattingOptions
.When using
ExcludingFields
, fields could be excluded from the failure messageWhen excluding
internal
getters, those could also be excluded from the failure messageThe work about internal members is also tracked in #744 and #1205