Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Commented out code marked as mutated in html report #1931

Open
Bforslund opened this issue Jun 12, 2022 · 6 comments
Open

Commented out code marked as mutated in html report #1931

Bforslund opened this issue Jun 12, 2022 · 6 comments
Labels

Comments

@Bforslund
Copy link

Bforslund commented Jun 12, 2022

Describe the bug
It seems that code that is commented out when part of a block mutation is marked as mutated code. I think the report should ignore lines that are comments from the visualisation.

Desktop (please complete the following information):

  • OS: Windows
  • Type of project: Dotnet core webapi
  • Framework Version: Dotnet 6
  • Stryker Version: 2.0.0

Additional context
image

@Bforslund Bforslund changed the title Commented out code seems to get mutated Commented out code marked as mutated in html report Jun 12, 2022
@dupdob
Copy link
Member

dupdob commented Jun 12, 2022

Stryker uses Roslyn to parse the source and then mutate the resulting syntax tree. Actually it cannot mutate commented out code, because Roslyn reports it as comments, which are not mutated.

What you see here is the mutation for the whole code block, it appears in green below. Block mutations do not preserve comments.

@rouke-broersma
Copy link
Member

We should move this to mutation testing elements. It can be confusing to see a comment marked as being a part of a mutation and users might interpret this as commented code being mutated.

@richardwerkman richardwerkman transferred this issue from stryker-mutator/stryker-net Jun 13, 2022
@hugo-vrijswijk
Copy link
Member

I'm not sure what would be a good solution here. I'd be happy to hear suggestions.

IMO marking the whole block as NoCoverage makes sense, because the entire block has no coverage. It's different from e.g. just the await statement being mutated

Also, on a technical level I think this could be fairly complex to implement and make exclusions for

@dupdob
Copy link
Member

dupdob commented Jun 17, 2022

Side comment: not sure why this mutation happened since I have added a logic preventing mutating bloc with a single statement, as it doubles with the statement mutator.
Technically, the comment IS mutated, since the mutation bears no comment at all.

Is this a problem only because there is code in the comment ? What about code in a string ? Would people expect it to be mutated as well.

This problem exists (as well as other) because users have strong assumptions about how Stryker works (by altering source code text).

Just thinking out loud here, not saying nothing should be done, but I tend to think somehow excluding the comment is not the best way to address this concern.

@rouke-broersma
Copy link
Member

Perhaps we could add an optional property to the schema for lines that are included for visual reasons only. It would then be up to the tool to decide which lines if any are not mutated code.

@rouke-broersma
Copy link
Member

Is this a problem only because there is code in the comment ? What about code in a string ? Would people expect it to be mutated as well.

I think it is only a problem because there is code in a comment. You're refactoring, you're commenting out some code you want to remove etc yet in the mutation report or appears as if the code was active.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants