Skip to content

Commit

Permalink
executable fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
bttmly committed Nov 27, 2016
1 parent ddfe643 commit 649d4be
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 134 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ example-events: compile

dogfood: compile
rm -rf ./.perturb
node ./script/run.js dogfood $(RUNNER)
node ./bin/perturb -s built

build:
./node_modules/.bin/tsc --strictNullChecks
Expand Down
59 changes: 0 additions & 59 deletions bin/_perturb

This file was deleted.

120 changes: 47 additions & 73 deletions bin/perturb
Original file line number Diff line number Diff line change
@@ -1,85 +1,59 @@
#!/usr/bin/env node

throw new Error("The CLI is currently out of sync with the library :( -- use the library directly");

// shamelessly appropriated from mocha

"use strict";

var path = require("path");

var spawn = require("child_process").spawn;
var perturb = path.join(__dirname, "_perturb");
var args = [perturb];

var bin = process.argv[0];

var timeout, ONE_MINUTE = 60 * 1000;

process.argv.slice(2).forEach(function (arg) {
var flag = arg.split("=")[0];
var val = arg.split("=")[1];

switch (flag) {

case "timeout":
timeout = Number(val);
if (isNaN(timeout)) throw new Error("Invalid timeout");
return;

case "--iojs":
bin = "iojs";
return;

case "--harmony":
case "--harmony-proxies":
case "--harmony-collections":
case "--harmony-generators":
case "--harmony_shipping":
case "--harmony_arrow_functions":
case "--harmony_proxies":
args.unshift(arg);
return;

default:
args.push(arg);
return;
}

});


timeout = timeout || ONE_MINUTE;

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

var child = spawn(bin, args, {
stdio: "inherit",
var program = require("commander");
var makeConfig = require("../built/make-config");
var MESSAGES = require("../built/constants/messages");

var pkg = require("../package.json");
var perturb = require("../");

program
.version(pkg.version)
.option("-r, --projectRoot <rootDir>", "root directory of the project")
.option("-t, --testDir <testDir>", "test directory relative to root directory")
.option("-s, --sourceDir <sourceDir>", "source directory relative to root directory")
.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("-u, --runner <runner>", "name of runner or runner plugin")
.parse(process.argv);

if (program.rootDir && program.rootDir[0] !== "/") {
program.rootDir = path.join(process.cwd(), program.rootDir);
}

var userConfig = omitUndefined({
rootDir: program.rootDir,
testDir: program.testDir,
sourceDir: program.sourceDir,
testGlob: program.testGlob,
sourceGlob: program.sourceGlob,
testCmd: program.testCmd,
runner: program.runner,
});

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

if (code === 0) return;

throw new Error("Child exited with code " + code);
// sync errors inside perturb don't seem to properly cause a non-zero exit w/o this
process.on("uncaughtException", function (err) {
console.log("uncaught error in perturb process", err);
throw err;
});

child.on("error", function (err) {
// sync errors inside perturb don't seem to properly cause a non-zero exit w/o this
process.on("unhandledRejection", function (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.
throw new Error("Main process received SIGINT");
// start!
perturb(userConfig).then(function (results) {
console.log("DONE -- COUNT:", results.length);
});

setTimeout(function () {
console.log("Timeout exceeded.");
child.kill("SIGINT");
}, timeout).unref();
function omitUndefined (obj) {
const ret = {};
for (key in obj) {
if (obj[key] != null) ret[key] = obj[key]
}
return ret;
}
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
"main": "built/index.js",
"bin": {
"perturb": "./bin/perturb",
"_perturb": "./bin/_perturb"
},
"repository": "git@github.com:nickb1080/perturb.git",
"dependencies": {
Expand Down

0 comments on commit 649d4be

Please sign in to comment.