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

Ability to disable mutant, that end up with timeout #2905

Open
CzBuCHi opened this issue Apr 10, 2024 · 6 comments
Open

Ability to disable mutant, that end up with timeout #2905

CzBuCHi opened this issue Apr 10, 2024 · 6 comments
Labels
🚀 Feature request New feature or request

Comments

@CzBuCHi
Copy link

CzBuCHi commented Apr 10, 2024

Is your feature request related to a problem? Please describe.

I have this code:

List<string> list = new List<string>();
string Aggregate() { 
    var top = list[0];
    list.RemoveAt(0); 

    if (top.All(char.IsNumber)) {
        return top;
    }

    var left = Aggregate();
    var right = Aggregate();
    return "(" + left + top + right + ")";
}

when stryker removes list.RemoveAt(0); it will result in surviving mutant due to timeout ...

Describe the solution you'd like
Ability to use 'timeout' keyword when disabling mutators via comments:

// Stryker disable once timeout
list.RemoveAt(0); 

Describe alternatives you've considered
im currently using // Stryker disable once all but that feels wrong because some mutant may still squeeze in there ...

Additional context
Same thing applies to uncovered parts of code:

public string Foo(int bar){
    if (bar == 3 || bar == 5) {
        return FooImpl(bar); // this is the only call to FooImpl
    }

    return "BAZ";
}

private string FooImpl(int bar) {
    return bar switch {
               3 => "FOO",
               5 => "BAR",
               // Stryker disable once all     <= this is a hole for mutant to sneak thru...
              // dotCover disable next line <= dotCover will not count next line to coverage
               _ => throw new UnreachableException(),
           };
}
@CzBuCHi CzBuCHi added the 🚀 Feature request New feature or request label Apr 10, 2024
@rouke-broersma
Copy link
Member

We wouldn't know it's a timeout until after testing, so how can we disable the mutant from testing?

Instead of disable all you can specify the type of mutator to disable here.

@CzBuCHi
Copy link
Author

CzBuCHi commented Apr 11, 2024

i would interpret // Stryker disable once timeout as if timeout occurs after this line, do not show it in report

@richardwerkman
Copy link
Member

it will result in surviving mutant due to timeout ...

This is not true, timeouts are counted as killed when calculating the mutation score. So why would you want to exclude timeouts from the report?

im currently using // Stryker disable once all but that feels wrong because some mutant may still squeeze in there ...

How would any mutant be generated here? Maybe I'm not following correctly.

@dupdob
Copy link
Member

dupdob commented Apr 11, 2024

@CzBuCHi : what is exactly the problem you are trying to solve here?

@CzBuCHi
Copy link
Author

CzBuCHi commented Apr 11, 2024

probably my own confusion ( after reading @richardwerkman answer ) - i considered timeouts as bad & need to be fixed (its not green :/)

but i think this can still be applied to uncovered parts of code:

public string Foo(int bar){
    if (bar == 3 || bar == 5) {
        return FooImpl(bar); // this is the only call to FooImpl 
    }

    return "BAZ";
}
private string FooImpl(int bar) {
    return bar switch {
               3 => "FOO",
               5 => "BAR",
              // dotCover disable next line
               _ => throw new UnreachableException(), // this will be never called, but compiler requires it ...
           };
}

because in this case stryker will complain about uncovered parts of code ... (idk right now it that one is red or yellow)

@dupdob
Copy link
Member

dupdob commented Apr 15, 2024

Stryker comments can be used for uncovered parts of the code, so this is already possible.
The only feature request I can see here is recognizing/reusing existing comments (such as dotCover here)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🚀 Feature request New feature or request
Projects
None yet
Development

No branches or pull requests

4 participants