Skip to content

Conversation

@thomhurst
Copy link
Owner

Summary

  • Fixed bug where [Arguments] with no values passed null instead of an empty array to params parameters
  • The ArgumentsAttribute constructor now distinguishes between empty arguments ([]) and explicit null ([null])
  • Added test case to verify the fix

Fixes #4561

Test plan

  • Verified new test ParamsOnlyWithEmptyArguments passes with 4 test cases
  • Verified all 12 ParamsArgumentsTests pass
  • Verified 105 source generator tests pass
  • No snapshot test failures

🤖 Generated with Claude Code

When [Arguments] is used with no arguments and the test method has a
params parameter, the parameter now correctly receives an empty array
instead of null. This matches standard C# behavior where calling a
method with params and no arguments passes an empty array.

Fixes #4561

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@thomhurst
Copy link
Owner Author

Summary

Fixes bug where [Arguments] with no values passed null instead of an empty array to params parameters.

Critical Issues

None found ✅

Analysis

Changes Review:
The fix correctly distinguishes between three cases in the ArgumentsAttribute constructor (TUnit.Core/Attributes/TestData/ArgumentsAttribute.cs:63-73):

  1. null passed → wraps as [null] (explicit null value)
  2. Empty array [] → keeps as [] (empty params)
  3. Non-empty array → uses values as-is

This aligns with standard C# behavior where calling a method with a params parameter and no arguments passes an empty array, not null.

Test Coverage:
The new test ParamsOnlyWithEmptyArguments (TUnit.TestProject/ParamsArgumentsTests.cs:47-58) validates the fix with 4 test cases covering the empty, single, double, and triple argument scenarios.

TUnit Rules Compliance:

  • No dual-mode concerns - This is a runtime attribute change, not source generator output modification
  • No snapshot test updates needed - No source generator output changed (verified PR description: "No snapshot test failures")
  • No public API changes - Internal behavior fix only
  • No reflection concerns - No new reflection usage
  • No performance concerns - Single conditional check, minimal overhead
  • No VSTest usage

Correctness:
The logic is sound. The original code treated both null and empty array identically (wrapping as [null]), which violated C# params semantics. The fix preserves the ability to pass an explicit null value via ArgumentsAttribute(null) while correctly handling the no-arguments case ArgumentsAttribute().

Verdict

APPROVE - No critical issues

@thomhurst thomhurst disabled auto-merge January 27, 2026 01:33
@thomhurst thomhurst merged commit a78374e into main Jan 27, 2026
12 of 13 checks passed
@thomhurst thomhurst deleted the fix/params-empty-arguments-null branch January 27, 2026 01:33
This was referenced Jan 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: params test argument is null when Arguments list is empty

2 participants