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

Stryker messes with compiler directives #3081

Open
dupdob opened this issue Oct 23, 2024 · 5 comments · Fixed by #3087 · May be fixed by #3116
Open

Stryker messes with compiler directives #3081

dupdob opened this issue Oct 23, 2024 · 5 comments · Fixed by #3087 · May be fixed by #3116
Labels
🐛 Bug Something isn't working Priority: Low An annoyance. Not of importance, choose whenever be fixed

Comments

@dupdob
Copy link
Member

dupdob commented Oct 23, 2024

Describe the bug
Mutated code may end up containing ill-formed compiler directives. I.e, Stryker does not ensure directives appear at the beginning of source lines. They may end up being captured within flow control statements.

Logs
When mutating this method

public void SomeMethod() {
    var x = 0;
#if !DEBUG
    x++;
#endif
}

Stryker generates this version

public void SomeMethod() {if(StrykerNamespace.MutantControl.IsActive(0)){}else{
    var x = 0;
if(StrykerNamespace.MutantControl.IsActive(1)){;}else{if(StrykerNamespace.MutantControl.IsActive(2)){#if !DEBUG
    x--;
}else{#if !DEBUG
    x++;
}}#endif
}}

Expected behavior
Compiler directives should not be transformed by the mutation step.
Previous example should result in something like this:

public void SomeMethod() {if(StrykerNamespace.MutantControl.IsActive(0)){}else{
    var x = 0;
#if !DEBUG
if(StrykerNamespace.MutantControl.IsActive(1)){;}else{if(StrykerNamespace.MutantControl.IsActive(2)){    x--;
}else{
    x++;
}}
#endif    
}}

Desktop (please complete the following information):

  • OS: NA
  • Type of project NA
  • Framework Version NA
  • Stryker Version 4.3 , and earlier versions
@dupdob dupdob added the 🐛 Bug Something isn't working label Oct 23, 2024
@dupdob dupdob reopened this Nov 11, 2024
@dupdob dupdob added the Priority: Low An annoyance. Not of importance, choose whenever be fixed label Nov 11, 2024
@dupdob
Copy link
Member Author

dupdob commented Nov 11, 2024

No fix has been provided for that. I suspect this triggers avoidable CompilationError mutations, so nothing urgent here.

@dupdob
Copy link
Member Author

dupdob commented Nov 14, 2024

I started to look into that, and integrated the actual result from the first unit test I made.
Directives are described via Roslyn's trivia mechanism, which also deals with comments, end of line and white spaces in general. So directives are transformed along with the syntaxnode they are attached to.

Thinking about it, it looks like Stryker should have a dedicated logic for trivia. Something along the lines of:
All trivia should be moved from the original (i.e non mutated) syntax node and attached to the mutation switching logic instead. There should be a special case for leading and trailing white spaces (to ensure resulting code is legible).

@dupdob
Copy link
Member Author

dupdob commented Nov 14, 2024

That being said, fixing this will probably have quite an impact on the mutation step design. Nothing to worry about, but it may change some historical signatures. Mutation workflow will be impacted as more steps are required: strip undesired trivia during mutation generation and restoring them when injecting mutations

@dupdob
Copy link
Member Author

dupdob commented Nov 15, 2024

Arghh: I forgot how hard it was to work with Roslyn's immutability approach...

@dupdob
Copy link
Member Author

dupdob commented Nov 16, 2024

update: finally making progress

public void SomeMethod() {if(StrykerNamespace.MutantControl.IsActive(0)){}else{
    var x = 0;
#if !DEBUG
    if(StrykerNamespace.MutantControl.IsActive(1)){;}else{if(StrykerNamespace.MutantControl.IsActive(2)){#if !DEBUG
    x--;
}else{x++;}}
#endif
}

directives are still part of the mutations, but are properly handled by switching logic

@dupdob dupdob linked a pull request Nov 21, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🐛 Bug Something isn't working Priority: Low An annoyance. Not of importance, choose whenever be fixed
Projects
None yet
1 participant