Add tests for code paths not covered by the test suite
Merged
ME
2mo ago+538+538+012345678901234567890123456789-2-2-0123456789
This PR only adds tests. No analyzer or code fixer code changes. I found the gaps by running the Roslyn 5.9 test suite with code coverage, and the new tests cover about 150 more lines and 130 more branches.
Tests added
- MA0015 / MA0043:
- A test that
ArgumentNullException.ThrowIfNull(arg, "arg")is fixed to usenameof. - Valid and invalid argument names for
InvalidEnumArgumentException.
- A test that
- MA0194: fixer tests for:
- Other terms between the checks that can be merged.
- Checks that switch to another value.
- An expression nested in a parenthesized logical expression.
- Constant patterns joined with
&&that can't be merged next to ones that can. - Parenthesized values.
- Events.
- MA0192:
(value & Flag) == 0for every enum underlying type, using the highest bit (reported) and a combined flag (not reported). - MA0005:
0Land0usizes, and multi-dimensional arrays.- Compiler-generated
paramsarrays for constructors and indexers.
- MA0003:
- The
minimum_method_parametersoption, including an invalid value. - A single
paramselement. - The
ReferenceEqualsandParse/TryParseexclusions. SyntaxNode.With*methods with several parameters.
- The
- MA0151: indexers, the
!operator, parenthesized expressions and blank expressions. - MA0011:
string.FormatandStringBuilder.AppendFormatwith an explicitobject[]. - MA0076:
nuint,StringBuilderandVersion.- The WPF
FontStretch/Brushand NuGetSemanticVersiontypes, as stubs that implementIFormattableso the exclusion is what prevents the diagnostic.
- MA0110: match timeouts that overflow the tick arithmetic, and timeouts computed with an instance method.
- MA0193: a type declared in source that implements
IFloatingPoint<T>without explicit interface syntax.
MinimumNumberOfParameters_2 passed without reading the option, because its argument (new object()) is never reported. It now passes a boolean literal, so the option is what prevents the diagnostic.
Notes for reviewers
- Bug not fixed here: MA0011 does not report collection expressions such as
string.Format("", ["test", -1]). The argument is wrapped in an implicit conversion toReadOnlySpan<object?>, so theICollectionExpressionOperationchecks inCultureSensitiveFormattingContextnever match. The fix would add new diagnostics, so it belongs in its own PR, and this PR has no tests for it. - Code no test can reach:
- The MA0003 exclusions for
MethodBase.Invoke,FieldInfo/PropertyInfo.GetValueandSetValuenever run, because their first parameter is namedobjand is filtered out earlier. - The MA0003
Volatile.Readexclusion never runs, because its only parameter isrefand can't take a literal. - MA0042 checks
IVariableDeclarationOperation.Initializer, which is only set for VB.
- The MA0003 exclusions for
Testing
dotnet build: 0 errors, 0 warnings.dotnet teston all Roslyn versions (4.8, 4.14, 5.0, 5.6, 5.9): 23,625 tests passed.