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

Add mutation for ternary operators #196

Open
ryanfreckleton opened this issue Jan 8, 2021 · 3 comments
Open

Add mutation for ternary operators #196

ryanfreckleton opened this issue Jan 8, 2021 · 3 comments

Comments

@ryanfreckleton
Copy link

Ternary operator errors of not covering both branches can't be detected by coverage, so it would be useful to mutate these to enable/disable each branch. E.g.

mark = "x" if count % 2 else "o"

mutation into:

mark = "x" if count % 2 and False else "o"

and

mark = "x" if count % 2 or True else "o"

This types of mutations aren't as useful for normal if statements, because branch coverage can detect when one of the alternatives isn't covered.

@boxed
Copy link
Owner

boxed commented Jan 9, 2021

Seems reasonable. Would you like to give it a shot to implement this?

@ryanfreckleton
Copy link
Author

Sure! Apologies for the late response.

I’ll post right before I start implementing, in case anyone else wants to take it on.

@brodycj
Copy link

brodycj commented Feb 19, 2024

I would love to see this get done. My workaround is to keep a special git stash of changes to replace all ternaries with expanded if/else blocks. And mutation testing with this stash of changes did give me a surviving mutant in some private code I was working on. (I actually use my own fork with some extra hackage to raise a RuntimeError in case it finds any ternaries in the code to mutate.)

When I tried hacking in the existing code, it looks like the code in __init__.py can handle multiple mutations of single tokens such as operators, but not for anything bigger at this time. I am sure it should be pretty straightforward to update the code to support multiple mutations of larger pieces of code, unfortunately I have not yet succeeded with this.

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

No branches or pull requests

3 participants