question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Smarter formatting

See original GitHub issue

The 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:open
  • Created 5 years ago
  • Comments:8 (8 by maintainers)

github_iconTop GitHub Comments

1reaction
jnyrupcommented, May 16, 2021

#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 the FormattingOptions.

When using ExcludingFields, fields could be excluded from the failure message

var col = new HtmlNodeCollection(new HtmlNode(HtmlNodeType.Element, new HtmlDocument(), 0));
col.Add(new HtmlNode(HtmlNodeType.Element, new HtmlDocument(), 0));
col.Should().BeEquivalentTo(new HtmlNode[] { }, opt => opt
    .ExcludingFields());

When excluding internal getters, those could also be excluded from the failure message

var col = new HtmlNodeCollection(new HtmlNode(HtmlNodeType.Element, new HtmlDocument(), 0));
col.Add(new HtmlNode(HtmlNodeType.Element, new HtmlDocument(), 0));

col.Should().BeEquivalentTo(new HtmlNode[] { }, opt => opt
    .Excluding(ctx => ctx.WhichGetterHas(CSharpAccessModifier.Internal)));
0reactions
jnyrupcommented, May 16, 2021

The work about internal members is also tracked in #744 and #1205

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to write SMART goals (with examples)
SMART goals are Specific, Measurable, Achievable, Relevant, and Time-Bound. Here, we work through an example of how to write them.
Read more >
Save time and be more efficient in PowerPoint
Smarter Format helps you to align and format your PowerPoint presentation. Copy size of objects, align slide titles or replace colors. The Smarter...
Read more >
Smart Formatting Tips
Make your professional document more readable by following these 5 formatting tips. Improve your writing and formatting skills with Hurley Write today....
Read more >
How To Write SMART Goals in 5 Steps (With Examples)
Learn how to use the SMART method to effectively create SMART goals that are Specific, Measurable, Achievable, Relevant and Time-based.
Read more >
How to Write SMART Goals
Everything you need to know about writing business or personal SMART goals, including an easy-to-use worksheet and free SMART goal templates.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found