-
Notifications
You must be signed in to change notification settings - Fork 746
EqualTo().Using() prevents caller from comparing strings to anything else #1897
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
Comments
Thanks for the detailed report. I've labeled and moved to the backlog. |
I've confirmed that I can build NUnit and have locally added this test to
It is failing correctly (that is, the last line is throwing an assertion). I can claim this issue if you like and submit a pull request later today. |
Have assigned it to you @tenwit, sure it would be welcome! |
I've reviewed all uses of Reducing that, my solution would be to remove Are the specs or executable specs explaining the use case for multiple calls to |
@tenwit Bear in mind that Using may not be applied at the top level of a comparison. For example, if you are testing that a certain collection contains an item equal to an expected value, the equal comparison is performed on the individual items. In theory, this sort of nesting can be to any depth. As another example, imagine comparing two object arrays for equality. The object arrays contain strings, ints and user defined class insttances. There may be several usings, each one for a particular type. Admittedly, this is not a very common situation, but it's exactly the situation that caused us to allow adding multiple comparers. The approach you are suggesting would break those cases. |
Ok found the requirement by searching all the .md in nunit/docs.wiki:
Which describes what @CharliePoole said above. In investigating the comment "multiple generic comparers for different types may be specified", I changed my comparer from this:
to this:
and also to this:
and the generic comparers support my use case (that is, test "CanCompareUncomparableTypes" mentioned earlier changes from failing to passing). So I suggest that the bug, such as it is, is in the form of incomplete documentation, rather than code. I will submit a PR for the new test though, as I think the situation isn't covered by any existing test that I could see. I'll go add this information to my original stackoverflow question, and fork/PR the wiki. Is that how wiki updates are made? Or is it just by editing the pages directly in GitHub? |
@tenwit you have been added to the @nunit/contributors team, so you can now edit the documents directly. |
A test proving that issue #1897 is not an issue
Is this good to be closed? |
I think so (but I'm unsure whether the wiki was ever updated) |
Looks like I merged a commit that was supposed to fix it. |
The merged commit contained only some tests illustrating that it is not a problem (if one used the generic version of the comparers. |
Given a suitable
DateTimeComparer
class that convertsIConvertible
objects toDateTime
, I expect this code to not throw an assertion:But it does, because
Using(DateTimeCompare.Instance)
returns either aComparerAdapter
or anEqualityComparerAdapter
, neither of which override the default implementation ofCanCompare
.Since the person writing the test is taking responsibility for comparing the actual and expected values (due to calling
Using
),CanCompare
should always returntrue
for anyExternalComparer
added when callingUsing
.The original issue and MCVE is described at Stackoverflow.
The text was updated successfully, but these errors were encountered: