hcoles / pitest

State of the art mutation testing system for the JVM
Apache License 2.0
1.68k stars 358 forks source link

excludedMethods is not working with lambdas #485

Open sergiomazoodigeo opened 6 years ago

sergiomazoodigeo commented 6 years ago

Hi all,

I've got following method in my code:

    private Set<String> getMissingOutputFields(Map<String, ?> obtained, Map<String, ?> expected) {
        return obtained.keySet().stream().filter(key -> !expected.containsKey(key)).collect(Collectors.toSet());
    }

When I try to exclude it from pitest plugin, the call to that is still analysed. However, if I remove lambda expression, the plugin excludes the method correctly.

Are lambda expressions supported? Best regards.

hcoles commented 6 years ago

Thanks for the report - can you provide a minimal project that demonstrates the issue?

mendesda commented 5 years ago

Thanks for the report - can you provide a minimal project that demonstrates the issue? @hcoles

Hello all, In the project I'm working on we also have this issue so I took the liberty of preparing this minimal project for you.

<excludedMethods> <param>methodUsingStreamApi</param> <param>methodNotUsingStreamApi</param> </excludedMethods>

And when running mvn clean install org.pitest:pitest-maven:mutationCoverage the exclusion is not taken into account (only for the method using the stream api)

PMS-819.zip

hcoles commented 5 years ago

@mendesda Thanks - I see the issue now. The method exclusion is based on a straight match against the method name, but the code will actually be contained in synthetic method named lambda$methodUsingStreamApi$0.

The simplest fix is probably to auto convert simple method names to globs/regexes that also match any generated lambda.