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
Wrap exceptions from the Assert.Equal comparer #2800
Comments
I'll have to think about this. My gut reaction is that I think rather than "additionally", it would be that an One thing that gives me a bit of pause is that the |
The collection equality assertion would be similar in behavior to |
Another approach would be embedding public static void CompositeEqual<T>(
T? expected,
T? actual,
params Action<T, T>[] checks);
public static void CompositeEqual<T>(
IEnumerable<T>? expected,
IEnumerable<T>? actual,
params Action<T, T>[] checks); |
Hmm, this is an interesting suggestion. It has the value of being a "different" assert, and therefore the inherent confusion between I'm not 100% sure the first version (non-enumerable) is necessary, but having both definitely offers some symmetry. I'll poke around with this today and see how it feels. |
After prototyping all the options and looking at the results, I think I'm going to go with a modification of your original suggestion. I've updated I've decided that this update is a debugging improvement: if you throw when we don't expect you to throw, we're providing additional information to help you understand why and how you threw. In your case, you were doing it with assertions, but that is a secondary reason to why I'm doing this. Even an inadvertent throw in the current system will only provide partial information (the exception), whereas with this update it will provide additional context (which element was being compared when the exception occurred). This isn't exactly the feature I think you were asking for, because I'm not 100% convinced that that's a scenario that I necessarily want to support. Attempting to reconcile the differences between what "throw" means in Here's the output from your test with my changes:
At this point in time, I am not planning any of the other suggested additions. |
Available in v2 |
This should be good enough ™ |
…b0..cb1e33ba6 cb1e33ba6 Updated doc comment for AllException.ForFailures 5986aa7bf Remove all ValueTask support e48a30666 Performance optimization: unused code in comparison hot path 094b4d4cf Formatting b3e3c931a Performance improvements in CollectionTrackerExtensions.AsTracker 6a94a86a0 Performance improvements in AssertEqualityComparer (conditional IEquatable<Y> and IComparable<Y> with type caching) f1843557b Replace dictionary with ring buffer in CollectionTracker.Enumerator 3bb330972 Don't depend on the Assert class inside AssertEqualityComparer 10f8fe362 Ensure all throws of NotImplementedException contain messages 37e83a858 Ensure all GetHashCode functions are implemented (xunit/xunit#2804) 4828bf193 xunit/xunit#2803: Add support for KeyValuePair<,> in AssertEqualityComparer to enable collections in values a92673b02 xunit/xunit#2800: Record exceptions from Assert.(Not)Equal comparer ba2525400 Replace concatenation and interpolation with String.Format git-subtree-dir: src/Microsoft.DotNet.XUnitAssert/src git-subtree-split: cb1e33ba612d4829e0848a44bde1026f5f9e3576
…b0..cb1e33ba6 cb1e33ba6 Updated doc comment for AllException.ForFailures 5986aa7bf Remove all ValueTask support e48a30666 Performance optimization: unused code in comparison hot path 094b4d4cf Formatting b3e3c931a Performance improvements in CollectionTrackerExtensions.AsTracker 6a94a86a0 Performance improvements in AssertEqualityComparer (conditional IEquatable<Y> and IComparable<Y> with type caching) f1843557b Replace dictionary with ring buffer in CollectionTracker.Enumerator 3bb330972 Don't depend on the Assert class inside AssertEqualityComparer 10f8fe362 Ensure all throws of NotImplementedException contain messages 37e83a858 Ensure all GetHashCode functions are implemented (xunit/xunit#2804) 4828bf193 xunit/xunit#2803: Add support for KeyValuePair<,> in AssertEqualityComparer to enable collections in values a92673b02 xunit/xunit#2800: Record exceptions from Assert.(Not)Equal comparer ba2525400 Replace concatenation and interpolation with String.Format git-subtree-dir: src/Microsoft.DotNet.XUnitAssert/src git-subtree-split: cb1e33ba612d4829e0848a44bde1026f5f9e3576
Test code
Expected
Actual
Additionally, consider adding a overloads specifically for this type of assert, something like:
The text was updated successfully, but these errors were encountered: