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.

Mutate constant expressions

See original GitHub issue

Is your feature request related to a problem? Please describe. Currently, Stryker does not mutate constant expressions when assigned to fields

const int foo = 5 - 1;

With #1017, it will also not support mutating enum member declarations:

public enum Numbers
{
    One = 1,
    Two = (One + 1)
}

These syntax nodes are simply skipped, since Stryker will insert non-constant code during the mutation, which would cause code that does not compile:

public enum Numbers
{
    One = 1,
    // CS0133 The expression being assigned to 'MutantOrchestratorTests.Numbers.Two' must be constant
    Two = StrykerXGJbRBlHxqRdD9O.MutantControl.IsActive(0) ? One + 1 : One - 1
}

Describe the solution you’d like Stryker should mutate constant expressions in a way they compile, so that

const int foo = 5 - 1;

becomes

const int foo = 5 + 1;

This is a valid mutation that would break a piece of software and should be covered by unit tests. Therefore, it should be supported by Stryker to generate these kinds of mutations.

Probably deep changes are needed here, since generally, a ternary expression is inserted when mutating code. Instead, the code needs to be modified without inserting more function calls.

Describe alternatives you’ve considered Instead of changing the mutation generation for all code, constant expressions could be handled in a different way, but that would lead to an inconsistent code base without much benefit.

Additional context To avoid warnings until this feature is implemented, Issue #1016 and Pull Request #1017 have been created to skip EnumMemberDeclarationSyntax nodes. Otherwise, they would produce warnings when using Stryker on code containing those nodes.

Issue Analytics

  • State:open
  • Created 3 years ago
  • Comments:7 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
dupdobcommented, Apr 3, 2020

I think the easiest way to do this would be simply to build multiple assemblies. I dont think switching variable names would work. Consider this

 const int a = 0;
 const int b = a;

switching would mean something like

const int a = 0;
const int a_mutated = 1;
const int b = MutantControl.IsActive(0) ? a_mutated : a; // won't build

Switching enum implies polymorphism.

But having one assembly per mutant take care of everything, at the expense of run time. This could be considered as ‘intense’ mutation testing.

But IMHO, I am not sure this is a good direction. The point of Stryker is to generate the most interesting mutant, trying to find gaps in test. Not generating every possible alternate version of an assembly just so user can brag on how many mutants their tests kill.

0reactions
rouke-broersmacommented, Apr 3, 2020

I agree the idea is horrible once you start working out the implications :p

Read more comments on GitHub >

github_iconTop Results From Across the Web

r - Assigning a constant with mutate_each
I would like to set all values in each of several columns to NA . Normally, if I would like to modify several...
Read more >
Mutating const variables
Const (constants) are block-scoped variables, the const variables can't be redeclared and the values can't be reassigned. const temp = 5;
Read more >
Constant expressions
Defines an expression that can be evaluated at compile time. Such expressions can be used as non-type template arguments, array sizes, and in...
Read more >
Why We Can Mutate a JavaScript Object Initialized With " ...
You are creating a constant reference to that value. This means that you can't reassign the variable declared with const , but you...
Read more >
How does rust define mutating a const?
A constant item is an optionally named constant value which is not associated with a specific memory location in the program. Constants are ......
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