stryker-mutator / stryker-net

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

Declare standard predefined symbols when building mutated assemblies #1828

Closed dupdob closed 2 years ago

dupdob commented 2 years ago

Is your feature request related to a problem? Please describe. See issue #1824

Describe the solution you'd like Stryker needs to declare predefined symbols when building the mutated assembly.

Describe alternatives you've considered Those symbols can be explicitly declared in the (VS/VC) project settings, but this defeats the purpose of predefined symbols.

Additional context It appears Roslyn does not add them automatically. So the code may have to declare them according the target framework version. Any official method would obviously be preferable.

psfinaki commented 2 years ago

So I still don't completely understand it. Why symbols like NET6_0 are understood whereas symbols like NET6_0_OR_GREATER are not? This basically says that all these _OR_GREATER symbols were added with .NET5.

dupdob commented 2 years ago

We need to test this, but are you certain that some symbols are automatically defined ? my understanding is that those are defined by MsBuild targets and Stryker does not use those (until we find a way to cleanly inject mutated source code during MsBuild builds).

psfinaki commented 2 years ago

Yes, actually Stryker currently works ideally for platform monikers other than _ORGREATER, and target-framework option in the config also performs correctly with that.

Look: Repro.zip

For this class:

image

This is what Stryker does:

image

100% behavior that we need.

psfinaki commented 2 years ago
image

It looks like internally something somewhere doesn't use the .NET5+ SDK.

rouke-broersma commented 2 years ago

@psfinaki the build system is msbuild. We don't use msbuild so we don't have those symbols by default is what my guess would be. Why we do have some of the symbols I do not know.

dupdob commented 2 years ago

update on this: Stryker uses Buildalyzer to capture the settings of the project. I guess that is how Stryker captures the predefined symbols, so maybe the problem lies within Buildalyzer. We need either to repro this or see if this is a known issue on Buildalyzer

richardwerkman commented 2 years ago

I was able to reproduce this issue and could not see a workaround. So I created an issue with buildalyzer.

psfinaki commented 2 years ago

Thanks for that, @richardwerkman

richardwerkman commented 2 years ago

I was able to fix the desired solution in Builalyzer so I created a PR. When it's merged and released we can fix this in Stryker