-
Notifications
You must be signed in to change notification settings - Fork 33
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
Why dropping composite message formatting support also for Assert.Pass/Fail/... where there are no actual and constraint parameters? #734
Comments
Where do you see there is a CallerArgumentExpresson for these? E.g.: Pass only take a string, no caller expression there. |
@OsirisTerje I'm not at a computer but I think I see what @maettu-this is referencing. There is a table in the markdown file linked which includes those other methods. This is likely a documentation issue as the methods themselves take basic, undecorated strings. I'm unsure if it's just in that one place we need to update |
My bad for not looking up the link there . Good you caught that @stevenaw , and thanks @maettu-this for finding this. |
The Analyzer warns that because the NUnit 4 code no longer has the These However I'm not sure if we should re-instate these in NUnit and then update the analyzer or for consistency sake leave it as it is so we have consistency and only support InterpolatedString. Otherwise we might get questions of why can I use @OsirisTerje Your opinion? |
@manfred-brands I am also unsure here. The reporter is correct we have an inconsistency here. The reporter seems to hold the opinion that it should stay as strings, but I don't share that an interpolated string is more noisy than an interpolated string, rather the opposite: ($"This is {givenname}, my last name is {surname}") versus ("This is {0}, my last name is {1}",givenname,surname) On the other side, we haven't had anyone complaining about this (ordinary strings here, interpolated otherwise), so I don't think people really notice. Four of these asserts are also in their own group in the docs (Special Assertions) and Warn is on its own. The keyword Warn ( used for Warn.If andWarn.Unless use CAE. For just these with only strings, a CAE doesn't (at first) seem to add anything, except for the fact that the output message tells where the message comes from, they don't do that now, but all functions where we have CAE does that, including the classic asserts *since they re/route to the constraint ones. Writing a Assert.Warn("There is something strange here"); ends with an output like this: versus if we use something with CAE: Warn.If(MyValue != 42, "There is something strange here"); ends up like this, which imho is better: PS: The use of negative logic here makes the example a bit harder, but you see the gist of it. So... after this little "walk inside my thoughts", I think I would prefer it to use an interpolated string and adding CAE. :-) |
Let me add three pieces to consider: the "master" of the messageFor For the others like conditional vs. unconditionalThe above shown composite message formatting vs. interpolated strings
Many may agree for the stated example, but I personally prefer composite message formatting especially in case of formatting numbers, e.g.:
vs.
With composite message formatting...
But maybe this is just personal taste. |
@stevenaw wrote the following about SpecFlow and their NUnit integration:
This means we should be very careful and only change this after talking with the SpecFlow guys. We don't want to break them. Which again means: Documentation should be updated. |
Thanks for cross-posting and sharing this here @OsirisTerje Agreed, we should be careful with those methods here. I'm unsure if there's a proposed direction here yet but I think we should be mindful of backwards compatibility in general here too as it sounds like we're considering changing or adding method signatures in the framework, which would be released as a semver-minor version bump. |
Agree. Perhaps we should add a v5 branch, and merge all breaking changes in there. |
We should first decide if these changes are worthwhile enough to break compatibility or reject them and don't do them. |
Sure :-) Imho, I'm leaning on keeping these as they are. If we do so, the 2050 rule should not trigger on these, and documentation updated. Comments: @nunit/framework-team @nunit/analyzers-team |
I think I also lean towards keeping these as they are. |
No strong opinions on my end either way. |
It seem we are in agreement to not change this again in NUnit which would require another major version change. This means that the analyzer is correct that it warns for |
@OsirisTerje and @manfred-brands I am a bit confused now, as I understood...
...to lean towards not breaking compatibility against NUnit 3, i.e. reintroduce the But even if not reintroducing the
...just doesn't make sense for those |
Correct. The table could be move higher to refer to method that used to have The special section is only relevant for [TestCase("NUnit 4", "NUnit 3")]
public void TestMessage(string actual, string expected)
{
Assert.That(actual, Is.EqualTo(expected), "Expected '{0}', but got: '{1}'", expected, actual);
} |
NUnit2050 tells me to replace composite message formatting by a simple string literal (not possible where variable values need to be injected) or an interpolatable string (would be possible but adds too much noise as variable names are much longer than {0} or {1}).
I fully understand the benefits of using
CallerArgumentExpression
forAssert.That
andAssume.That
. But why also for......where there neither is a
condition
noractual
/constraint
parameters?The text was updated successfully, but these errors were encountered: