From ef2d61cff43c995dcefb9325e8a38ca2cf17bb6e Mon Sep 17 00:00:00 2001 From: basarat Date: Sun, 10 Nov 2013 19:46:45 +1100 Subject: [PATCH] infrastructure: keep a reference to execResult instead of only exit code to possibly print the stderr stream contents --- _infrastructure/tests/runner.js | 48 ++++++++++++++------------ _infrastructure/tests/runner.ts | 61 ++++++++++++++++++++------------- 2 files changed, 63 insertions(+), 46 deletions(-) diff --git a/_infrastructure/tests/runner.js b/_infrastructure/tests/runner.js index 8f4eb9e4da..b42879cf39 100644 --- a/_infrastructure/tests/runner.js +++ b/_infrastructure/tests/runner.js @@ -794,12 +794,12 @@ var DefinitelyTyped; })(); ///////////////////////////// - // Used to get printable relative path to a file + // Represents the results of a test file execution ///////////////////////////// var File = (function () { - function File(name, hasError) { + function File(name, execResult) { this.name = name; - this.hasError = hasError; + this.execResult = execResult; } // From '/complete/path/to/file' to 'specfolder/specfile.d.ts' File.prototype.formatName = function (baseDir) { @@ -813,6 +813,9 @@ var DefinitelyTyped; return File; })(); + ///////////////////////////// + // Determine syntax errors in typings + ///////////////////////////// var SyntaxChecking = (function () { function SyntaxChecking(fileHandler, out) { this.fileHandler = fileHandler; @@ -824,7 +827,7 @@ var DefinitelyTyped; var list = []; for (var i = 0; i < this.files.length; i++) { - if (this.files[i].hasError) { + if (this.files[i].execResult.exitCode) { list.push(this.files[i]); } } @@ -836,7 +839,7 @@ var DefinitelyTyped; var list = []; for (var i = 0; i < this.files.length; i++) { - if (!this.files[i].hasError) { + if (!this.files[i].execResult.exitCode) { list.push(this.files[i]); } } @@ -869,19 +872,16 @@ var DefinitelyTyped; SyntaxChecking.prototype.run = function (it, file, len, maxLen, callback) { var _this = this; if (!endsWith(file.toUpperCase(), '-TESTS.TS') && endsWith(file.toUpperCase(), '.TS') && file.indexOf('../_infrastructure') < 0) { - new Test(file).run(function (o) { - var failed = false; - - if (o.exitCode === 1) { + new Test(file).run(function (execResult) { + if (execResult.exitCode === 1) { _this.out.printFailure(); - failed = true; len++; } else { _this.out.printSuccess(); len++; } - _this.files.push(new File(file, failed)); + _this.files.push(new File(file, execResult)); if (len > maxLen) { len = 0; @@ -928,6 +928,9 @@ var DefinitelyTyped; return SyntaxChecking; })(); + ///////////////////////////// + // Determines errors in typing tests + ///////////////////////////// var TestEval = (function () { function TestEval(fileHandler, out) { this.fileHandler = fileHandler; @@ -939,7 +942,7 @@ var DefinitelyTyped; var list = []; for (var i = 0; i < this.files.length; i++) { - if (this.files[i].hasError) { + if (this.files[i].execResult.exitCode) { list.push(this.files[i]); } } @@ -951,7 +954,7 @@ var DefinitelyTyped; var list = []; for (var i = 0; i < this.files.length; i++) { - if (!this.files[i].hasError) { + if (!this.files[i].execResult.exitCode) { list.push(this.files[i]); } } @@ -984,19 +987,16 @@ var DefinitelyTyped; TestEval.prototype.run = function (it, file, len, maxLen, callback) { var _this = this; if (endsWith(file.toUpperCase(), '-TESTS.TS')) { - new Test(file).run(function (o) { - var failed = false; - - if (o.exitCode === 1) { + new Test(file).run(function (execResult) { + if (execResult.exitCode === 1) { _this.out.printFailure(); - failed = true; len++; } else { _this.out.printSuccess(); len++; } - _this.files.push(new File(file, failed)); + _this.files.push(new File(file, execResult)); if (len > maxLen) { len = 0; @@ -1090,13 +1090,17 @@ var DefinitelyTyped; timer.start(); this.out.printHeader(); - this.out.printSyntaxChecking(); + // Run syntax tests + this.out.printSyntaxChecking(); this.sc.start(function (syntaxFailedCount, syntaxTotal) { + // Now run typing tests _this.out.printTypingTests(); _this.te.start(function (testFailedCount, testTotal) { - var total = _this.printTypingsWithoutTest(); + // Get the tests without any typing and simultaneously print their names + var totalTypingsWithoutTest = _this.printTypingsWithoutTest(); + // End total timer and print final messages timer.end(); _this.out.printDiv(); @@ -1106,7 +1110,7 @@ var DefinitelyTyped; _this.out.printElapsedTime(timer.asString, timer.time); _this.out.printSyntaxErrorCount(syntaxFailedCount, syntaxTotal); _this.out.printTestErrorCount(testFailedCount, testTotal); - _this.out.printWithoutTestCount(total, _this.fh.allTypings().length); + _this.out.printWithoutTestCount(totalTypingsWithoutTest, _this.fh.allTypings().length); _this.out.printDiv(); diff --git a/_infrastructure/tests/runner.ts b/_infrastructure/tests/runner.ts index 8ca2ecec8c..a98dfc2c00 100644 --- a/_infrastructure/tests/runner.ts +++ b/_infrastructure/tests/runner.ts @@ -26,8 +26,12 @@ module DefinitelyTyped.TestManager { } } + interface TscCallback { + (result: ExecResult): void; + } + class Tsc { - public static run(tsfile: string, callback: Function) { + public static run(tsfile: string, callback: TscCallback) { var command = 'node ./_infrastructure/tests/typescript/tsc.js --module commonjs '; if (IO.fileExists(tsfile + '.tscparams')) { command += '@' + tsfile + '.tscparams'; @@ -43,7 +47,7 @@ module DefinitelyTyped.TestManager { class Test { constructor(public tsfile: string) { } - public run(callback: Function) { + public run(callback: TscCallback) { Tsc.run(this.tsfile, callback); } } @@ -239,11 +243,11 @@ module DefinitelyTyped.TestManager { } ///////////////////////////// - // Used to get printable relative path to a file + // Represents the results of a test file execution ///////////////////////////// class File { - constructor(public name: string, public hasError: boolean) { } + constructor(public name: string, public execResult: ExecResult) { } // From '/complete/path/to/file' to 'specfolder/specfile.d.ts' public formatName(baseDir: string): string { @@ -256,6 +260,10 @@ module DefinitelyTyped.TestManager { } } + + ///////////////////////////// + // Determine syntax errors in typings + ///////////////////////////// class SyntaxChecking { private timer: Timer; @@ -266,7 +274,7 @@ module DefinitelyTyped.TestManager { var list: File[] = []; for (var i = 0; i < this.files.length; i++) { - if (this.files[i].hasError) { + if (this.files[i].execResult.exitCode) { list.push(this.files[i]); } } @@ -278,7 +286,7 @@ module DefinitelyTyped.TestManager { var list: File[] = []; for (var i = 0; i < this.files.length; i++) { - if (!this.files[i].hasError) { + if (!this.files[i].execResult.exitCode) { list.push(this.files[i]); } } @@ -314,19 +322,17 @@ module DefinitelyTyped.TestManager { private run(it, file, len, maxLen, callback: Function) { if (!endsWith(file.toUpperCase(), '-TESTS.TS') && endsWith(file.toUpperCase(), '.TS') && file.indexOf('../_infrastructure') < 0) { - new Test(file).run((o) => { - var failed = false; + new Test(file).run((execResult) => { - if (o.exitCode === 1) { - this.out.printFailure(); - failed = true; + if (execResult.exitCode === 1) { + this.out.printFailure(); len++; } else { this.out.printSuccess(); len++; } - this.files.push(new File(file, failed)); + this.files.push(new File(file, execResult)); if (len > maxLen) { len = 0; @@ -372,6 +378,9 @@ module DefinitelyTyped.TestManager { } } + ///////////////////////////// + // Determines errors in typing tests + ///////////////////////////// class TestEval { private timer: Timer; @@ -382,7 +391,7 @@ module DefinitelyTyped.TestManager { var list: File[] = []; for (var i = 0; i < this.files.length; i++) { - if (this.files[i].hasError) { + if (this.files[i].execResult.exitCode) { list.push(this.files[i]); } } @@ -394,7 +403,7 @@ module DefinitelyTyped.TestManager { var list: File[] = []; for (var i = 0; i < this.files.length; i++) { - if (!this.files[i].hasError) { + if (!this.files[i].execResult.exitCode) { list.push(this.files[i]); } } @@ -430,19 +439,17 @@ module DefinitelyTyped.TestManager { private run(it, file, len, maxLen, callback: Function) { if (endsWith(file.toUpperCase(), '-TESTS.TS')) { - new Test(file).run((o) => { - var failed = false; + new Test(file).run((execResult) => { - if (o.exitCode === 1) { + if (execResult.exitCode === 1) { this.out.printFailure(); - failed = true; len++; } else { this.out.printSuccess(); len++; } - this.files.push(new File(file, failed)); + this.files.push(new File(file, execResult)); if (len > maxLen) { len = 0; @@ -543,13 +550,19 @@ module DefinitelyTyped.TestManager { timer.start(); this.out.printHeader(); + + // Run syntax tests this.out.printSyntaxChecking(); - this.sc.start((syntaxFailedCount, syntaxTotal) => { - this.out.printTypingTests(); - this.te.start((testFailedCount, testTotal) => { - var total = this.printTypingsWithoutTest(); + // Now run typing tests + this.out.printTypingTests(); + this.te.start((testFailedCount, testTotal) => { + + // Get the tests without any typing and simultaneously print their names + var totalTypingsWithoutTest = this.printTypingsWithoutTest(); + + // End total timer and print final messages timer.end(); this.out.printDiv(); @@ -559,7 +572,7 @@ module DefinitelyTyped.TestManager { this.out.printElapsedTime(timer.asString, timer.time); this.out.printSyntaxErrorCount(syntaxFailedCount, syntaxTotal); this.out.printTestErrorCount(testFailedCount, testTotal); - this.out.printWithoutTestCount(total, this.fh.allTypings().length); + this.out.printWithoutTestCount(totalTypingsWithoutTest, this.fh.allTypings().length); this.out.printDiv();