-
Notifications
You must be signed in to change notification settings - Fork 34
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
NUnit 2045: Assert.Multiple fixer might be slightly too greedy due to the lack of lookahead #777
Comments
@danielmarbach Thanks for your report. The current CodeFix uses common prefix to determine if something is independent. Logically you might say that these two statements belong together, but the CodeFix looks at maximum grouping ability and is technically correct. |
@manfred-brands Agreed it is technically correct. I was first even hesitant to raise it as an issue. I think what caused me to raise it was that the prefix can be seen as "start of a hierarchy level" and every new prefix is a different "hierarchy". I went down on this path of thinking because when I saw var configuration = new Configuration();
Assert.That(configuration, Is.Not.Null);
Assert.Multiple(() =>
{
Assert.That(configuration.Value1, Is.EqualTo(0));
Assert.That(configuration.Value2, Is.EqualTo(0.0));
Assert.That(configuration.Value11, Is.EqualTo(string.Empty));
}); I immediately thought "kind of smart because essentially every . or descending into subtrees is a good candidate for grouping". But when I look at the application of the fix through our more than 20 plus repositories, we got quite surprising groupings. My hunch that the originally intent of the feature was exactly what my intuition told me is the following rule https://github.com/nunit/nunit.analyzers/blob/master/src/nunit.analyzers/UseAssertMultiple/UseAssertMultipleAnalyzer.cs#L49-L50 Here are a few live example Particular/ServiceControl@60c8d48 |
@danielmarbach The lines you referred to say that What you want is looking at 3 items. Only if That would require maintaining more previous arguments in the loop and check something like |
For example
will be rewritten to
while my intuition tells me it should do
or if Values would contain more complex objects
will be rewritten to
while my intuition would tell me it should do
Or with nested objects
it currently does
while my intuition tells me to
I do realize this can be highly depending on "taste". I think my intuition comes from the explanation of Assert.Multiple that an argument is not suffixed later and that is an indication that individual subtrees should be groupe together
The text was updated successfully, but these errors were encountered: