TypeScript/scripts/bisect-test.ts

64 lines
2.4 KiB
TypeScript
Raw Normal View History

/**
* You should have ts-node installed globally before executing this, probably!
* Otherwise you'll need to compile this script before you start bisecting!
*/
2019-06-14 11:18:27 +02:00
import cp = require("child_process");
import fs = require("fs");
2015-01-20 00:39:21 +01:00
2018-10-25 08:55:28 +02:00
// Slice off 'node bisect-test.js' from the command line args
2019-06-20 09:51:29 +02:00
const args = process.argv.slice(2);
2015-01-20 00:39:21 +01:00
function tsc(tscArgs: string, onExit: (exitCode: number) => void) {
2019-06-20 09:51:29 +02:00
const tsc = cp.exec("node built/local/tsc.js " + tscArgs,() => void 0);
2019-06-14 11:18:27 +02:00
tsc.on("close", tscExitCode => {
onExit(tscExitCode);
});
}
// TODO: Rewrite bisect script to handle the post-jake/gulp swap period
2019-06-20 09:51:29 +02:00
const jake = cp.exec("jake clean local", () => void 0);
2019-06-14 11:18:27 +02:00
jake.on("close", jakeExitCode => {
if (jakeExitCode === 0) {
2015-01-20 00:39:21 +01:00
// See what we're being asked to do
2019-06-14 11:18:27 +02:00
if (args[1] === "compiles" || args[1] === "!compiles") {
tsc(args[0], tscExitCode => {
2019-06-14 11:18:27 +02:00
if ((tscExitCode === 0) === (args[1] === "compiles")) {
console.log("Good");
2015-01-20 00:39:21 +01:00
process.exit(0); // Good
2019-06-14 09:51:09 +02:00
}
else {
2019-06-14 11:18:27 +02:00
console.log("Bad");
2015-01-20 00:39:21 +01:00
process.exit(1); // Bad
}
});
2019-06-14 09:51:09 +02:00
}
2019-06-14 11:18:27 +02:00
else if (args[1] === "emits" || args[1] === "!emits") {
tsc(args[0], tscExitCode => {
2019-06-14 11:18:27 +02:00
fs.readFile(args[2], "utf-8", (err, data) => {
2019-06-20 09:51:29 +02:00
const doesContains = data.indexOf(args[3]) >= 0;
2019-06-14 11:18:27 +02:00
if (doesContains === (args[1] === "emits")) {
console.log("Good");
2015-01-20 00:39:21 +01:00
process.exit(0); // Good
2019-06-14 09:51:09 +02:00
}
else {
2019-06-14 11:18:27 +02:00
console.log("Bad");
2015-01-20 00:39:21 +01:00
process.exit(1); // Bad
}
});
});
2019-06-14 09:51:09 +02:00
}
else {
2019-06-14 11:18:27 +02:00
console.log("Unknown command line arguments.");
console.log("Usage (compile errors): git bisect run ts-node scripts\bisect-test.ts '../failure.ts --module amd' !compiles");
console.log("Usage (emit check): git bisect run ts-node scripts\bisect-test.ts bar.ts emits bar.js '_this = this'");
// Aborts the 'git bisect run' process
2015-01-20 00:39:21 +01:00
process.exit(-1);
}
2019-06-14 09:51:09 +02:00
}
else {
// Compiler build failed; skip this commit
2019-06-14 11:18:27 +02:00
console.log("Skip");
2015-01-20 00:39:21 +01:00
process.exit(125); // bisect skip
}
});