Use enum names instead of numeric values in test display names#5178
Use enum names instead of numeric values in test display names#5178
Conversation
…trixDataSource Change MatrixDataSourceAttribute to convert underlying type values back to enum instances using Enum.ToObject(), so ArgumentFormatter.FormatDefault() correctly identifies them as enums and displays their names (e.g., "ToEven") instead of numeric values (e.g., "0"). Fixes: #4059 Co-authored-by: thomhurst <30480171+thomhurst@users.noreply.github.com>
|
@copilot I only want to affect the display name logic, not the actual parameter injection/exclusion logic |
… parameter injection Revert MatrixDataSourceAttribute.cs to original (no changes to parameter injection/exclusion logic). Instead, add a parameter-type-aware Format overload to ArgumentFormatter that converts numeric values to enum names for display only. Updated callers: TestContext.GetDisplayName(), DisplayNameAttribute, DisplayNameSubstitutor. Updated PublicAPI snapshots for the new public method. Co-authored-by: thomhurst <30480171+thomhurst@users.noreply.github.com>
…ption type Co-authored-by: thomhurst <30480171+thomhurst@users.noreply.github.com>
Reverted |
Code ReviewThis PR correctly fixes the root issue: What works well
Concerns1. Code duplication in the two The new public overload repeats the formatter loop verbatim from the original: public static string Format(object? o, List<Func<object?, string?>> formatters)
public static string Format(object? o, Type? parameterType, List<Func<object?, string?>> formatters)The original overload could simply delegate to the new one: public static string Format(object? o, List<Func<object?, string?>> formatters)
=> Format(o, parameterType: null, formatters);This removes the duplicated loop and makes the relationship between the two overloads explicit. Currently a future change to the formatter loop (e.g., short-circuiting, logging) would need to be applied in two places. 2.
3.
4. The guard SummaryThe fix correctly solves the reported issue and respects the constraint of not touching injection/exclusion logic. The main actionable improvements are: (1) eliminating the duplicated formatter loop by delegating from the old overload to the new one, and (2) reviewing whether |
MatrixDataSourceAttributeusesEnum.GetValuesAsUnderlyingType()to auto-generate enum parameter values, which returns boxed numeric types (e.g.,int 0, 1, 2). These bypass theo is Enumcheck inArgumentFormatter.FormatDefault(), causing test names likeRoundingWorks(1)instead ofRoundingWorks(AwayFromZero).Changes
Formatoverload toArgumentFormatterthat accepts aType? parameterType— when the parameter type is an enum and the value is numeric, it converts to the enum name for display viaEnum.ToObject()TestContext.GetDisplayName(),DisplayNameAttribute,DisplayNameSubstitutor) to pass parameter type information to the new formatter overloadMatrixDataSourceAttributeis untouched; only display formatting is affectedBefore / After
Original prompt
🔒 GitHub Advanced Security automatically protects Copilot coding agent pull requests. You can protect all pull requests by enabling Advanced Security for your repositories. Learn more about Advanced Security.