stryker-mutator / stryker-net

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

Preprocessor symbols not activated during testfile syntaxtree parsing #2501

Closed vbreuss closed 1 year ago

vbreuss commented 1 year ago

Describe the bug In my project Stryker shows an error message, where it worked with v3.7.1:

[16:04:59 INF] Initial testrun started.
[16:05:15 INF] Time Elapsed 00:01:13.8443548
Unhandled exception. System.InvalidOperationException: Sequence contains no matching element
   at System.Linq.ThrowHelper.ThrowNoMatchException()
   at System.Linq.Enumerable.First[TSource](IEnumerable`1 source, Func`2 predicate)
   at Stryker.Core.Initialisation.ProjectMutator.EnrichTestProjectsWithTestInfo(InitialTestRun initialTestRun, TestProjectsInfo testProjectsInfo)
   at Stryker.Core.Initialisation.ProjectMutator.MutateProject(StrykerOptions options, IReporter reporters, IEnumerable`1 solutionProjects)
   at Stryker.Core.Initialisation.ProjectOrchestrator.MutateProjects(StrykerOptions options, IReporter reporters)+MoveNext()
   at System.Collections.Generic.List`1..ctor(IEnumerable`1 collection)
   at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)
   at Stryker.Core.StrykerRunner.RunMutationTest(IStrykerInputs inputs, ILoggerFactory loggerFactory, IProjectOrchestrator projectOrchestrator)
   at Stryker.CLI.StrykerCli.RunStryker(IStrykerInputs inputs) in /_/src/Stryker.CLI/Stryker.CLI/StrykerCLI.cs:line 93
   at Stryker.CLI.StrykerCli.<>c__DisplayClass10_0.<Run>b__0() in /_/src/Stryker.CLI/Stryker.CLI/StrykerCLI.cs:line 68
   at McMaster.Extensions.CommandLineUtils.CommandLineApplication.<>c__DisplayClass143_0.<OnExecute>b__0(CancellationToken _)
   at McMaster.Extensions.CommandLineUtils.CommandLineApplication.ExecuteAsync(String[] args, CancellationToken cancellationToken)
   at McMaster.Extensions.CommandLineUtils.CommandLineApplication.Execute(String[] args)
   at Stryker.CLI.StrykerCli.Run(String[] args) in /_/src/Stryker.CLI/Stryker.CLI/StrykerCLI.cs:line 74
   at Stryker.CLI.Program.Main(String[] args) in /_/src/Stryker.CLI/Stryker.CLI/Program.cs:line 14
/home/runner/work/_temp/e6b4cac3-c1[27](https://github.com/Testably/Testably.Abstractions/actions/runs/4902459842/jobs/8754314766#step:5:28)-4f6d-b5f5-cf92c89680a7.sh: line 2:  1858 Aborted                 (core dumped) ../../tools/dotnet-stryker -f ../.github/stryker/Stryker.Config.Testing.json -v "${GITHUB_REF#refs/heads/}" -r "Dashboard" -r "cleartext"
Error: Process completed with exit code 1[34](https://github.com/Testably/Testably.Abstractions/actions/runs/4902459842/jobs/8754314766#step:5:35).

Logs See the test run on Github.

Expected behavior After reverting stryker to v3.7.1 the build was successful: https://github.com/Testably/Testably.Abstractions/actions/runs/4902612340

Desktop (please complete the following information):

Additional context This issue was copied from stryker-mutator/mutation-testing-elements#2493

rouke-broersma commented 1 year ago

I have found the issue, the syntaxnode for the unit test does not exist in the syntaxtree where we're trying to find the unit test location in the test code file where there is a #if NET6_0_OR_GREATER preprocessor directive: https://github.com/Testably/Testably.Abstractions/blob/main/Tests/Testably.Abstractions.Testing.Tests/MockFileSystemTests.cs#L284

Obviously since the unit test is discovered the directive is active during mutation testing, not sure why it's not being found when we're creating the syntax tree.

rouke-broersma commented 1 year ago

The fix has been released as 3.8.2

vbreuss commented 1 year ago

Thanks, @rouke-broersma ! I checked the new tool version and the error disappeared (although I still can't upload the report due to #2493 yet...)