question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Ternary statement mutations

See original GitHub issue

At the moment, mutations are being placed inside if statements like this

if(Environment.GetEnvironmentVariable("ActiveMutation") == "<id>") {
    // mutation
} else {
    // original
}

Not all mutations can be inserted like this. Some mutations can only be inserted using ternary statements like this:

var localVariable = if(Environment.GetEnvironmentVariable("ActiveMutation") == "<id>") ? // mutation : //original

These kind of mutations should also be rollbacked different. My suggestion is an interface for both type of mutant placements. Something like:

public interface IMutantPlacement {
    SyntaxNode InsertMutant(SyntaxNode, Mutant);
    SyntaxNode RemoveMutant(SyntaxNode, Mutant);
}

It would have two implementations. One for if statements and one for ternary mutations.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:17 (17 by maintainers)

github_iconTop GitHub Comments

2reactions
kevinlylescommented, Oct 17, 2018

Alright, I think I have things working. We end up using ternary mutations for expressions and if mutations only for statements, which means a lot more ternary mutations but often a lot less code overall.

I have a proof of concept (with some new tests and all tests passing) at https://github.com/kevinlyles/stryker-net/tree/issue-17, but I probably won’t have time to clean things up until next week. Feel free to have a look, and let me know what you think.

1reaction
richardwerkmancommented, Oct 28, 2018

Well the type LocalFunctionStatement can contain a Body,

int Add(int x, int y) {
    return x + y;
}

or an ExpressionBody

int Add(int x, int y) => x + y;

One should be mutated by IfStatements, the other by ConditionalExpression. But I think I have figured out a way to nicely handle this.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Add mutation for conditional (ternary) operator · Issue #757
I propose adding a mutation for conditional operator: Original Mutated a ? b : c a ? c : b Also, I am...
Read more >
Nested Ternaries are Great
In functional programming, we tend to avoid mutations and other side-effects. Since if in JavaScript naturally affords mutation and side effects ...
Read more >
Assigning apollo mutations with a ternary in an onClick?
Using react-apollo, how to define 2 mutations in the same component with TypeScript? 7 · How to type a mutation in typescript +...
Read more >
Using Conditional Mutation to Increase the Efficiency of ...
Another do smarter ap- proach is weak mutation testing [8] where a mutant is said to be killed if its internal state, after...
Read more >
Why I'm phasing out ternary statements
Why I've stopped using ternary statements. ... Variables that can be mutated add mental load and make the program harder to follow.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found