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

Specify lines to mutate #1980

Closed
vitaly-rudenko opened this issue Jan 22, 2020 · 16 comments
Closed

Specify lines to mutate #1980

vitaly-rudenko opened this issue Jan 22, 2020 · 16 comments
Labels
🚀 Feature request New feature request ☠ stale Marked as stale by the stale bot, will be removed after a certain time.

Comments

@vitaly-rudenko
Copy link

vitaly-rudenko commented Jan 22, 2020

Is your feature request related to a problem? Please describe.
I would like to be able to specify certain lines to mutate. This is necessary to automatically test changes in pull requests.

Describe the solution you'd like
-m some/file.js:1-5;8-12,some/other/file.js:21,30-40 would mutate only 1-5, 8-12 lines of some/file.js, and 21, 30-40 lines of some/other/file.js

@vitaly-rudenko vitaly-rudenko added the 🚀 Feature request New feature request label Jan 22, 2020
@simondel
Copy link
Member

Isn’t what you’re looking for more in the lines of incremental analysis? #322

@vitaly-rudenko
Copy link
Author

I'm not sure. I need this to only perform mutation testing for specific lines that have been changed in a specific Pull Request. So I have list of files with corresponding lists of lines that have been changed. I want to provide that into the Stryker so it can check only specified lines of code.

@vitaly-rudenko
Copy link
Author

vitaly-rudenko commented Feb 1, 2020

I suppose "Incremental analysis" issue implies that the feature I describe exists.

@Djaler
Copy link
Contributor

Djaler commented Mar 18, 2020

I'm not sure. I need this to only perform mutation testing for specific lines that have been changed in a specific Pull Request. So I have list of files with corresponding lists of lines that have been changed. I want to provide that into the Stryker so it can check only specified lines of code.

But what if your PR changes test?

@vitaly-rudenko
Copy link
Author

vitaly-rudenko commented Mar 18, 2020

I need to run mutation test using all PR's specs, but only mutate selected lines of specified files.
Is this what you're asking?

I just need to check whether those lines are covered with tests.

@Garethp
Copy link
Contributor

Garethp commented May 17, 2020

I'd also really like this feature. My use-case is similar to incremental analysis, but more straightforward. I'm building a IntelliJ plugin for Stryker, and I'm looking to implement a Re-run failed mutants feature, similar to how you can rerun only failed Jest/Mocha tests. Knowing what mutants failed in the last test run, it'd be easy to just pass in the info needed to identify which mutants I want to run again.

Though the problem sounds the same as incremental analysis (being able to skip mutants you know are dead), I think the end user use-case is different (being able to only check changed code vs. being able to target specific mutants for specific reasons).

If there are Plugin API hooks that I could use to filter out mutants once they've been detected but before being finalised, I'd be happy to write a Plugin to take care of this feature

@Garethp
Copy link
Contributor

Garethp commented May 17, 2020

One example for an end-user where specifying lines to mutate would be better than incremental analysis would be a use-case where you've got your CI build telling you that lines 23 and 55 have surviving mutants, so you checkout master and want to run just those two lines through the mutator. No need to rebuild the incremental analysis when changing branches, just specify those two lines and run

@vitaly-rudenko
Copy link
Author

Yes, that's exactly what I meant. This feature will be very useful for CI and scripts.

@nicojs
Copy link
Member

nicojs commented May 18, 2020

Thanks for your feedback everyone.

If there are Plugin API hooks that I could use to filter out mutants once they've been detected but before being finalized, I'd be happy to write a Plugin to take care of this feature

We're busy with a complete overhaul of the code with #1514 . I think the plugin you want to request is similar to the type-checker plugin I've theorized there. I think we could make a more generic plugin that can mark mutants in any number of MutantStates (where we can also add Ignored, which is what you're looking for). The use case seems similar enough. Maybe we can rename it as a CheckerPlugin? @simondel what do you think?

@Garethp
Copy link
Contributor

Garethp commented May 18, 2020

@nicojs So, you're thinking of having a generic plugin that would allow for various forms of Mutant pre-checks (for lack of a better term off the top of my head), where you could have a pre-check for type compilation (that would be nice, being able to check for compilation errors before hitting the testRunner) or a pre-check for user excluded mutants and one for more context based filtering (for example, checking if a mutant is the dependants argument in a React Hook, or whatever else you might not want to mutate in your Domain).

I think that's pretty cool, it would allow a lot of flexibility for people to write plugins to help Stryker be more suited to their particular domain.

@nicojs
Copy link
Member

nicojs commented Jun 4, 2020

I've opened #2240 for a checker API. Here you can filter mutants before they are tested in a test runner.

However, the check api will have no knowledge of syntax. So checking if a mutant is the dependants argument in a React Hook is probably not possible (without again parsing the file). It's probably better to exclude those mutants, see #1472.

We're planning exclude functionality after the migration to mutation switching. No time line I can give at the moment unfortunately, but work is progressing.

@vitaly-rudenko
Copy link
Author

Thanks for the update! Is there anything I could help with?

@nicojs
Copy link
Member

nicojs commented Jun 4, 2020

@vitaly-rudenko you can help by reviewing the checker API as it stands now. Would allowing you to implement a CheckerPlugin solve your issue?

@vitaly-rudenko
Copy link
Author

@vitaly-rudenko you can help by reviewing the checker API as it stands now. Would allowing you to implement a CheckerPlugin solve your issue?

Yes, I'll review the PR asap. I'm not an expert in the stryker's source code though. But providing a simple API for implementing a custom checker would solve my issue, as I'm willing to create a plugin that suits my needs.

Thanks!

nicojs added a commit that referenced this issue Jun 9, 2020
Adds `Checker` plugin type, to be used in #1514 (and can later be used to filter mutants in #1980).

The idea is that, before mutation testing (or even before files are instrumented), we initialize the checker. It can be used as a sanity check. The `TypescriptChecker` can use this to load all files and compile once (with `--no-emit`) to make sure errors don't occur under normal circumstances. 

The `check` method is called one-by-one on each mutant. A checker can decide to assign any of a `CheckStatus`. If it `Passed` it proceeds to the next checker, or if it was the last checker it will be run in a test runner. If another status is assigned, it will stop processing that mutant and report it as done.
@stale
Copy link

stale bot commented Jun 9, 2021

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the ☠ stale Marked as stale by the stale bot, will be removed after a certain time. label Jun 9, 2021
@nicojs
Copy link
Member

nicojs commented Jun 9, 2021

We've implemented specifying specific lines to mutate a while ago: #2751. Closing this issue.

@nicojs nicojs closed this as completed Jun 9, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🚀 Feature request New feature request ☠ stale Marked as stale by the stale bot, will be removed after a certain time.
Projects
None yet
Development

No branches or pull requests

5 participants