Skip to content

Conversation

Youssef1313
Copy link
Member

@Youssef1313 Youssef1313 commented Jun 22, 2025

Part of #1154

Related to #1285

@@ -163,7 +145,7 @@ public static void IsNull(object? value, [InterpolatedStringHandlerArgument(name
/// <exception cref="AssertFailedException">
/// Thrown if <paramref name="value"/> is not null.
/// </exception>
public static void IsNull(object? value, string? message)
public static void IsNull(object? value, [CallerArgumentExpression(nameof(value))] string message = "")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can discuss about the design, what I had in mind was to still allow the user to set a custom message but for us to use the capture mechanism to enrich the default message (always displayed - or with some verbosity setting in case).

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know if we should have an analyzer to ensure people don't set this value or if we should use the trick from @sharwell (bait and switch).

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I could be missing something, but I don't see how that trick can prevent users from passing the value. If the overload is available in the assembly passed to Csc, then it's available.

The trick is useful if we want to preserve binary compatibility and keep Assert.IsNull(object) but let the compiler prefer Assert.IsNull(object, /*caller arg expression*/ string = ""), by passing an assembly that only has the latter to Csc, but at run time, we keep the assembly that has both overloads.

@Youssef1313 Youssef1313 added this to the 4.0.0 milestone Jun 25, 2025
@Youssef1313 Youssef1313 force-pushed the dev/ygerges/callerarg-round1 branch from 91ab65c to 0e864ba Compare June 25, 2025 10:59
@Youssef1313 Youssef1313 force-pushed the dev/ygerges/callerarg-round1 branch from 0e864ba to 3782fab Compare June 26, 2025 13:29
@codecov-commenter
Copy link

Codecov Report

Attention: Patch coverage is 64.86486% with 13 lines in your changes missing coverage. Please review.

Project coverage is 63.05%. Comparing base (81e228e) to head (7dd9e8a).

Files with missing lines Patch % Lines
...c/TestFramework/TestFramework/Assertions/Assert.cs 0.00% 6 Missing ⚠️
...ramework/TestFramework/Assertions/Assert.IsNull.cs 33.33% 4 Missing ⚠️
...ramework/TestFramework/Assertions/Assert.IsTrue.cs 25.00% 3 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           dev/v4    #5851      +/-   ##
==========================================
+ Coverage   62.99%   63.05%   +0.05%     
==========================================
  Files         574      574              
  Lines       31434    31417      -17     
==========================================
+ Hits        19803    19811       +8     
+ Misses      11631    11606      -25     
Flag Coverage Δ
Debug 63.05% <64.86%> (+0.05%) ⬆️
integration 63.05% <64.86%> (+0.05%) ⬆️
production 63.05% <64.86%> (+0.05%) ⬆️
unit 63.05% <64.86%> (+0.05%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
...t.Analyzers/DoNotNegateBooleanAssertionAnalyzer.cs 100.00% <100.00%> (ø)
...eferAssertFailOverAlwaysFalseConditionsAnalyzer.cs 100.00% <100.00%> (+15.47%) ⬆️
...alyzers/ReviewAlwaysTrueAssertConditionAnalyzer.cs 98.36% <100.00%> (ø)
...ramework/TestFramework/Assertions/Assert.IsTrue.cs 37.50% <25.00%> (ø)
...ramework/TestFramework/Assertions/Assert.IsNull.cs 16.00% <33.33%> (ø)
...c/TestFramework/TestFramework/Assertions/Assert.cs 7.69% <0.00%> (ø)

... and 8 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link
Member

@Evangelink Evangelink left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not a big fan of the current message but let's merge as-is and I'll suggest a bigger assertion message rename.

@Evangelink Evangelink merged commit b3eb228 into dev/v4 Jun 27, 2025
8 checks passed
@Evangelink Evangelink deleted the dev/ygerges/callerarg-round1 branch June 27, 2025 11:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants