stryker-mutator / stryker-net

Mutation testing for .NET core and .NET framework!
https://stryker-mutator.io
Apache License 2.0
1.76k stars 177 forks source link

Null-conditional method calls are not filtered out by `ignore-methods` setting. #2653

Closed pentp closed 1 year ago

pentp commented 1 year ago

Describe the bug Method calls using null-conditional invocation syntax are not filtered out by ignore-methods configuration setting.

Expected behavior Method calls using null-conditional invocation syntax are filtered out by ignore-methods configuration like normal method invocations.

Desktop:

Additional context Probably because the Roslyn syntax tree looks quite different:

// regular invocation:
InvocationExpression(
    MemberAccessExpression(
        SyntaxKind.SimpleMemberAccessExpression,
        IdentifierName("value"),
        IdentifierName("ToString")))))}))

// null-conditional invocation:
ConditionalAccessExpression(
    IdentifierName("value"),
    InvocationExpression(
        MemberBindingExpression(
            IdentifierName("ToString"))))))}))
dupdob commented 1 year ago

could you please provide an example? We do have unit tests for conditional invocation, and those are supported as far as we know it.

pentp commented 1 year ago

I don't see any such tests and I just verified that if I remove the ?, such method invocations are ignored as expected:

Logger.Verbose.Log("This statement removal mutation is ignored");
Logger.Verbose?.Log("This statement removal mutation isn't ignored and survives");

Using this config: "ignore-methods": [ "Log" ]

Edit: found the unit test for conditional invocation filtering, so not sure why it's not working. Probably because the unit test only tests mutants inside the invocation, but not statement removal mutations.

dupdob commented 1 year ago

Tests are here https://github.com/stryker-mutator/stryker-net/blob/8772e19b4e78ba7c7fab07d2c0fd198de6098c83/src/Stryker.Core/Stryker.Core.UnitTest/MutantFilters/IgnoredMethodMutantFilterTests.cs#L103

but they may be ineffective as they do not work on actual mutations.