Skip to content

Commit

Permalink
proof of concept multi match
Browse files Browse the repository at this point in the history
  • Loading branch information
bttmly committed Aug 9, 2015
1 parent 8e5d64d commit a88037d
Show file tree
Hide file tree
Showing 21 changed files with 40 additions and 44 deletions.
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
test:
test: lint
NODE_ENV=testing ./node_modules/.bin/_mocha ./test/**/*.js

lint:
./node_modules/.bin/jshint ./**/*.js
./node_modules/.bin/eslint ./lib/**/*.js

test-example:
./node_modules/.bin/_mocha ./example/test/**/*-test.js
Expand Down
1 change: 1 addition & 0 deletions bin/_perturb
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ function reporter (err, data) {
console.log(data.meta);
}

// figure out how exec handles command line args
function runTests (settings, cb) {
var cmd = settings.testCmd || MESSAGES.DefaultTest;
console.log(MESSAGES.ExecutingTests, cmd);
Expand Down
22 changes: 12 additions & 10 deletions bin/perturb
Original file line number Diff line number Diff line change
Expand Up @@ -51,28 +51,30 @@ timeout = timeout || ONE_MINUTE;

console.log([bin].concat(args).join(" "));

var child = spawn(bin, args, {stdio: "inherit"});
var child = spawn(bin, args, {
stdio: "inherit",
});

child.on("exit", function (code, signal) {
console.log("child exiting...", code);
process.on("exit", function(){
if (signal) {
process.kill(process.pid, signal);
} else {
process.exit(code);
}
});
if (signal) {
throw new Error("Child received signal " + signal);
}

if (code === 0) return;

throw new Error("Child exited with code " + code);
});

child.on("error", function (err) {
console.log("child errored...", err);
throw err;
});

// terminate children.
process.on("SIGINT", function () {
child.kill("SIGINT"); // calls runner.abort()
child.kill("SIGTERM"); // if that didn"t work, we"re probably in an infinite loop, so make it die.
process.kill(process.pid, "SIGINT");
throw new Error("Main process received SIGINT");
});

setTimeout(function () {
Expand Down
4 changes: 2 additions & 2 deletions lib/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ var DEFAULT_GLOB = "/**/*.js";
function createDefaultCacheInvalidator (config) {
return function shouldInvalidate (modulePath) {
assert(isString(modulePath), "Expected a string module path");
return modulePath.indexOf(config.originalSourceDir) !== -1;
return modulePath.indexOf(config.perturbDirName) !== -1;
};
}

Expand Down Expand Up @@ -54,7 +54,7 @@ function generateConfig (userConfig) {
var result = calculateExtraConfig(assign({}, defaultConfig, userConfig));

// TODO let configuration dictate which matchers and reporters are used
result.matcher = require("./matchers/comparative-matcher")(result);
result.matcher = require("./matchers/contains-comparative-matcher")(result);
result.mutantReporter = require("./reporters").mutantReporter;

try {
Expand Down
2 changes: 1 addition & 1 deletion lib/constant/binary-operator-swaps.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,5 @@ module.exports = constObj({
"^": "&",
"<<": ">>",
">>": "<<",
">>>": "<<<"
">>>": "<<<",
});
2 changes: 1 addition & 1 deletion lib/constant/errors.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@ module.exports = constObj({
NoMatches: "Unable to match any source and test files",
InvalidRunner: "No test runner named '%s' found.",
InvalidMutator: "Invalid mutator",
NoCallback: "Must Provide a callback function."
NoCallback: "Must Provide a callback function.",
});
2 changes: 1 addition & 1 deletion lib/constant/func-nodes.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ var mapMirror = require("../util/map-mirror");
module.exports = mapMirror([
NODE_TYPES.FunctionDeclaration,
NODE_TYPES.FunctionExpression,
NODE_TYPES.ArrowFunctionExpression
NODE_TYPES.ArrowFunctionExpression,
]);
2 changes: 1 addition & 1 deletion lib/constant/js-types.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@ module.exports = constObj({
str: "string",
num: "number",
obj: "object",
sym: "symbol"
sym: "symbol",
});
2 changes: 1 addition & 1 deletion lib/constant/messages.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ var constObj = require("../util/const-obj");
module.exports = constObj({
TestsPassed: "Test command exited with `0`. Continuing...",
ExecutingTests: "executing `%s` ...",
DefaultTest: "npm test"
DefaultTest: "npm test",
});
2 changes: 1 addition & 1 deletion lib/constant/node-attrs.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@ module.exports = mapMirror([
"test",
"argument",
"arguments",
"params"
"params",
]);
2 changes: 1 addition & 1 deletion lib/constant/node-types.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,5 +42,5 @@ module.exports = mapMirror([
"VariableDeclaration",
"VariableDeclarator",
"WhileStatement",
"WithStatement"
"WithStatement",
]);
4 changes: 2 additions & 2 deletions lib/constant/test-nodes.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@ module.exports = mapMirror([
NODE_TYPES.DoWhileStatement,
NODE_TYPES.ForStatement,
NODE_TYPES.ConditionalExpression,
NODE_TYPES.SwitchCase
]);
NODE_TYPES.SwitchCase,
]);
7 changes: 2 additions & 5 deletions lib/handle-multi-match.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ function createMatchHandler (config) {
return function handleMultiMatch (multiMatch, done) {

console.log("HANDLE MULTI MATCH", multiMatch.sourceFile);
console.log("MATCHED TESTS", multiMatch.testFiles);

var tests = multiMatch.testFiles.slice();
var sourceFile = multiMatch.sourceFile;
Expand Down Expand Up @@ -81,11 +82,7 @@ function createMatchHandler (config) {
return m.failed;
});

if (failed.length) {
console.log("FOUND FAILURES", failed.length, "OF", result.mutants.length, "IN", sourceFile);
failed.map(function (m) { console.log(m.failed); });
return done(null, output);
}
if (failed.length) return done(null, output);

console.log("RETRYING");
setImmediate(doNext);
Expand Down
6 changes: 3 additions & 3 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

// bad stuff
Error.stackTraceLimit = 100;
process.env.PERTURB = true;
// process.setMaxListeners(0);

var assert = require("assert");
Expand Down Expand Up @@ -47,9 +48,8 @@ function perturb (config, done) {
if (err) return cleanup(err);

// now we're at the per-source file level
processedMatches = _.flatten(processedMatches);

var mutants = _.flatten(_.pluck(processedMatches, "mutants"));
var oneToOneMatches = _.flatten(processedMatches);
var mutants = _.flatten(_.pluck(oneToOneMatches, "mutants"));

var meta = {
duration: Date.now() - start,
Expand Down
2 changes: 1 addition & 1 deletion lib/mutations/tweak-array-literal.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ module.exports = {
},
mutator: function (node) {
return arrayLiteralTweakFn(node);
}
},
};

function arrayLiteralTweakFn (node) {
Expand Down
6 changes: 3 additions & 3 deletions lib/run-mutant.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@ function createMutantRunner (config) {
function clearCache (mutation) {
delete require.cache[mutation.testFile];
delete require.cache[mutation.sourceFile];
// if (config.cacheInvalidationPredicate) {
// invalidateRequireCache(config.cacheInvalidationPredicate);
// }
if (config.cacheInvalidationPredicate) {
invalidateRequireCache(config.cacheInvalidationPredicate);
}
}

// note: finish does NOT cleanup after a run. This is to reduce the number of
Expand Down
1 change: 0 additions & 1 deletion lib/util/invalidate-require-cache.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
function invalidateRequireCache (predicate) {
Object.keys(require.cache).forEach(function (modulePath) {
if (predicate(modulePath)) {
console.log("deleting", modulePath);
delete require.cache[modulePath];
}
});
Expand Down
2 changes: 1 addition & 1 deletion lib/util/set-node-value.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
function setNodeValue (node, value) {
return node.merge({
value: value,
raw: JSON.stringify(value)
raw: JSON.stringify(value),
});
}

Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
"commander": "^2.6.0",
"diff": "^1.2.1",
"escodegen": "^1.5.0",
"eslint": "^1.1.0",
"esprima": "^2.0.0",
"fs-extra": "^0.16.3",
"glob": "^4.3.2",
Expand Down
1 change: 1 addition & 0 deletions test/mutations/drop-operator-deux.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
console.log("XXX RAN XXX");
9 changes: 2 additions & 7 deletions test/pkg-util.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ describe("#mapMirror", function () {
expect(result).to.deep.equal({
one: "one",
two: "two",
three: "three"
three: "three",
});
});

Expand All @@ -39,18 +39,13 @@ describe("#mapMirror", function () {
expect(result).to.deep.equal({
one: "one",
two: "two",
three: "three"
three: "three",
});
});
});

});

// describe("#constObj", function () {

// });


describe("#mutantIsDead", function () {
it("just returns the boolean cast of the input's `failed` property", function () {
expect(util.mutantIsDead({failed: 0})).to.equal(false);
Expand Down

0 comments on commit a88037d

Please sign in to comment.