Skip to content

Commit

Permalink
implement kill rate checking
Browse files Browse the repository at this point in the history
  • Loading branch information
bttmly committed Oct 5, 2018
1 parent e521e2d commit a82a252
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 13 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
language: node_js
node_js:
- '8'
script: npm t
script: make ci
3 changes: 3 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,7 @@ dogfood: compile
rm -rf ./.perturb
node ./lib/cli -s lib

ci: compile
node ./lib/cli -s lib -k 85

.PHONY: test example
15 changes: 13 additions & 2 deletions src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ program
.option("-x, --testGlob <testGlob>", "glob for selecting files in test directory")
.option("-y, --sourceGlob <sourceGlob>", "glob for selecting files in source directory")
.option("-c, --testCmd <testCmd>", "test command")
.option("-k, --killRate", "minimum kill rate to exit with code 0")
.option("-k, --killRateMin <i>", "minimum kill rate to exit with code 0", parseInt)
.option("-u, --runner <runner>", "name of runner or runner plugin")
.parse(process.argv);

Expand All @@ -40,6 +40,7 @@ const args: OptionalPerturbConfig = R.pickBy(R.complement(R.isNil), {
sourceGlob: program.sourceGlob,
testCmd: program.testCmd,
runner: program.runner,
killRateMin: program.killRateMin,
});

// sync errors inside perturb don't seem to properly cause a non-zero exit w/o this
Expand All @@ -55,6 +56,16 @@ process.on("unhandledRejection", (err) => {

// start!
(async function main() {
const results = await perturb(args);
const { results, config } = await perturb(args);
console.log("DONE -- COUNT:", results.length);

const killed = results.filter(r => r.error);
const killRate = Number((killed.length / results.length).toFixed(4)) * 100;

if (killRate < config.killRateMin) {
console.error(`❌ Mutant kill rate was ${killRate} which is below minimum acceptable value ${config.killRateMin}`)
process.exitCode = 1;
} else {
console.log(`✅ Mutant kill rate was ${killRate} which is above minimum acceptable value ${config.killRateMin}`)
}
})();
20 changes: 10 additions & 10 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,22 +30,22 @@ export default async function perturb(inputCfg: OptionalPerturbConfig) {
"*********************************************************\n",
);

const cfg = makeConfig(inputCfg);
const config = makeConfig(inputCfg);

console.log("init with config\n", cfg);
console.log("init with config\n", config);

const { setup, teardown, paths } = fileSystem(cfg);
const { setup, teardown, paths } = fileSystem(config);

const matcher = getMatcher(cfg);
const runner = getRunner(cfg.runner);
const reporter = getReporter(cfg.reporter);
const matcher = getMatcher(config);
const runner = getRunner(config.runner);
const reporter = getReporter(config.reporter);
const handler = makeMutantHandler(runner, reporter);
const locator = locateMutants(mutators.getMutatorsForNode);

// const testRun: Promise<void> = process.env.SKIP_TEST ? Promise.resolve() : runTest(cfg);
// const testRun: Promise<void> = process.env.SKIP_TEST ? Promise.resolve() : runTest(config);

// first run the tests, otherwise why bother at all?
await spawnP(cfg.testCmd);
await spawnP(config.testCmd);

try {
// then, set up the "shadow" file system that we'll work against
Expand Down Expand Up @@ -109,15 +109,15 @@ export default async function perturb(inputCfg: OptionalPerturbConfig) {
const metadata = { duration };

if (reporter.onFinish) {
reporter.onFinish(results, cfg, metadata);
reporter.onFinish(results, config, metadata);
}

// TODO -- provide some run metadata here:
// duration: number
// runner: string
// sourceCount: number

return results;
return { results, config };
} finally {
await teardown();
}
Expand Down
2 changes: 2 additions & 0 deletions src/make-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ const defaultConfig: PerturbConfig = {
reporter: "diff",
matcher: DEFAULT_MATCHER,
runner: DEFAULT_RUNNER,

killRateMin: 0,
};

export default function makeConfig(userConfig: OptionalPerturbConfig = {}): PerturbConfig {
Expand Down
2 changes: 2 additions & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,8 @@ export interface PerturbConfig {

sourceGlob: string;
testGlob: string;

killRateMin: number;
}

export type OptionalPerturbConfig = Partial<PerturbConfig>;
Expand Down

0 comments on commit a82a252

Please sign in to comment.