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

fix(instrumenter): switch case mutant placer #2518

Merged
merged 2 commits into from Oct 4, 2020

Conversation

nicojs
Copy link
Member

@nicojs nicojs commented Sep 30, 2020

Add a MutantPlacer for SwitchCase nodes. It places the mutants in the consequence part of the switch case. This can dramatically improve the performance of instrumenting large switch-case statements.

This:

switch(foo){
  case 'bar':
    console.log('bar');
    break;
  case 'baz':
    console.log('baz');
    break;

}

Is now instrumented as:

switch (foo) {
  case stryMutAct_9fa48(1) ? \\"\\" : (stryCov_9fa48(1), 'bar'):
    if (stryMutAct_9fa48(0)) {} else {
      stryCov_9fa48(0);
      console.log(stryMutAct_9fa48(2) ? \\"\\" : (stryCov_9fa48(2), 'bar'));
      break;
    }

  case stryMutAct_9fa48(4) ? \\"\\" : (stryCov_9fa48(4), 'baz'):
    if (stryMutAct_9fa48(3)) {} else {
      stryCov_9fa48(3);
      console.log(stryMutAct_9fa48(5) ? \\"\\" : (stryCov_9fa48(5), 'baz'));
      break;
    }
}

While previously the entire SwitchCaseExpression was duplicated for each empty switch case mutation.

Fixes #2401

Add a `MutantPlacer` for `SwitchCase` nodes. It places the mutants in the `concequence` part of the switch case. This can dramatically improve the performacne of instrumenting lage switch case statements.

This:

```js
switch(foo){
  case 'bar':
    console.log('bar');
    break;
  case 'baz':
    console.log('baz');
    break;

}
```

Is now instrumented as:

```js
switch (foo) {
  case stryMutAct_9fa48(1) ? \\"\\" : (stryCov_9fa48(1), 'bar'):
    if (stryMutAct_9fa48(0)) {} else {
      stryCov_9fa48(0);
      console.log(stryMutAct_9fa48(2) ? \\"\\" : (stryCov_9fa48(2), 'bar'));
      break;
    }

  case stryMutAct_9fa48(4) ? \\"\\" : (stryCov_9fa48(4), 'baz'):
    if (stryMutAct_9fa48(3)) {} else {
      stryCov_9fa48(3);
      console.log(stryMutAct_9fa48(5) ? \\"\\" : (stryCov_9fa48(5), 'baz'));
      break;
    }
}
```

While previously the entire `SwitchCaseExpression` was duplicated for each empty switch case mutation..
@nicojs
Copy link
Member Author

nicojs commented Sep 30, 2020

@brodybits

22:27:14 (25864) INFO InputFileResolver Found 1 of 6726 file(s) to be mutated.
22:27:16 (25864) INFO Instrumenter Instrumented 1 source file(s) with 6876 mutant(s)

Instrumenting printer-estree.js now takes a fraction of a second 👍

@nicojs nicojs changed the title fix(insturmenter): switch case mutant placer fix(instrumenter): switch case mutant placer Sep 30, 2020
@brodybits
Copy link

🎉 I hope to try it soon!

@nicojs
Copy link
Member Author

nicojs commented Oct 1, 2020

Feel free to review the code if you want 😎

@brodybits
Copy link

Unfortunately I still do not understand the mutation switching well enough to comment on the changes or on the test cases. Thanks for the investigation and work on this.

@nicojs nicojs merged commit a560711 into epic/mutation-switching Oct 4, 2020
@nicojs nicojs deleted the fix/switch-case-mutant-placer branch October 4, 2020 18:57
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

Successfully merging this pull request may close these issues.

Running Stryker 4.0 beta on prettier gives errors in initial test run
2 participants