2018-08-04 15:13:01 +00:00
|
|
|
import { ChildProcess } from 'child_process';
|
2018-08-04 12:23:07 +00:00
|
|
|
import { coloredString as cs } from '@pushrocks/consolecolor';
|
2018-08-03 17:18:42 +00:00
|
|
|
|
|
|
|
// ============
|
|
|
|
// combines different tap test files to an overall result
|
|
|
|
// ============
|
2018-08-04 15:13:01 +00:00
|
|
|
import * as plugins from './tstest.plugins';
|
|
|
|
import { TapTestResult } from './tstest.tap.testresult';
|
2018-08-03 17:18:42 +00:00
|
|
|
|
|
|
|
export class TapParser {
|
|
|
|
resultStore: TapTestResult[] = [];
|
2018-08-04 12:23:07 +00:00
|
|
|
|
|
|
|
expectedTestsRegex = /([0-9]*)\.\.([0-9]*)/;
|
2018-08-03 17:18:42 +00:00
|
|
|
expectedTests: number;
|
|
|
|
|
2018-08-04 12:23:07 +00:00
|
|
|
testStatusRegex = /(ok|not\sok)\s([0-9]+)\s-\s/;
|
|
|
|
activeTapTestResult: TapTestResult;
|
|
|
|
|
2018-08-04 15:13:01 +00:00
|
|
|
private _getNewTapTestResult() {
|
|
|
|
this.activeTapTestResult = new TapTestResult(this.resultStore.length + 1);
|
2018-08-04 12:23:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private _processLog(logChunk: Buffer | string) {
|
|
|
|
if (Buffer.isBuffer(logChunk)) {
|
2018-08-03 17:18:42 +00:00
|
|
|
logChunk = logChunk.toString();
|
|
|
|
}
|
2018-08-04 15:13:01 +00:00
|
|
|
const logLineArray = logChunk.split('\n');
|
|
|
|
if (logLineArray[logLineArray.length - 1] === '') {
|
2018-08-04 12:23:07 +00:00
|
|
|
logLineArray.pop();
|
|
|
|
}
|
|
|
|
|
|
|
|
// lets parse the log information
|
|
|
|
for (const logLine of logLineArray) {
|
|
|
|
let logLineIsTapProtocol = false;
|
|
|
|
if (!this.expectedTests && this.expectedTestsRegex.test(logLine)) {
|
|
|
|
logLineIsTapProtocol = true;
|
|
|
|
const regexResult = this.expectedTestsRegex.exec(logLine);
|
|
|
|
this.expectedTests = parseInt(regexResult[2]);
|
|
|
|
console.log(`:::TAP::: Expecting ${this.expectedTests} tests!`);
|
|
|
|
|
|
|
|
// initiating first TapResult
|
|
|
|
this._getNewTapTestResult();
|
|
|
|
} else if (this.testStatusRegex.test(logLine)) {
|
|
|
|
logLineIsTapProtocol = true;
|
|
|
|
const regexResult = this.testStatusRegex.exec(logLine);
|
|
|
|
const testId = parseInt(regexResult[2]);
|
|
|
|
const testOk = (() => {
|
2018-08-04 15:13:01 +00:00
|
|
|
if (regexResult[1] === 'ok') {
|
2018-08-04 12:23:07 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
})();
|
|
|
|
|
|
|
|
// test for protocol error
|
2018-08-04 15:13:01 +00:00
|
|
|
if (testId !== this.activeTapTestResult.id) {
|
|
|
|
console.log(`:::TAP PROTOCOL ERROR::: Something is strange! Test Ids are not equal!`);
|
2018-08-04 12:23:07 +00:00
|
|
|
}
|
|
|
|
this.activeTapTestResult.setTestResult(testOk);
|
|
|
|
|
2018-08-04 15:13:01 +00:00
|
|
|
if (testOk) {
|
|
|
|
console.log(cs(`:::TAP::: Success: Test ${testId} is ok!`, 'green', 'black'));
|
2018-08-04 12:23:07 +00:00
|
|
|
} else {
|
2018-08-04 15:13:01 +00:00
|
|
|
console.log(cs(`:::TAP::: Error: Test ${testId} is NOT ok!`, 'green', 'black'));
|
2018-08-04 12:23:07 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!logLineIsTapProtocol) {
|
|
|
|
if (this.activeTapTestResult) {
|
|
|
|
this.activeTapTestResult.addLogLine(logLine);
|
|
|
|
}
|
|
|
|
console.log(logLine);
|
|
|
|
}
|
|
|
|
|
2018-08-04 15:13:01 +00:00
|
|
|
if (this.activeTapTestResult && this.activeTapTestResult.testSettled) {
|
2018-08-04 12:23:07 +00:00
|
|
|
this.resultStore.push(this.activeTapTestResult);
|
|
|
|
this._getNewTapTestResult();
|
|
|
|
}
|
|
|
|
}
|
2018-08-03 17:18:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
async handleTapProcess(childProcessArg: ChildProcess) {
|
|
|
|
const done = plugins.smartpromise.defer();
|
2018-08-04 15:13:01 +00:00
|
|
|
childProcessArg.stdout.on('data', data => {
|
2018-08-04 12:23:07 +00:00
|
|
|
this._processLog(data);
|
|
|
|
});
|
2018-08-04 15:13:01 +00:00
|
|
|
childProcessArg.stderr.on('data', data => {
|
2018-08-04 12:23:07 +00:00
|
|
|
this._processLog(data);
|
|
|
|
});
|
2018-08-04 15:13:01 +00:00
|
|
|
childProcessArg.on('exit', () => {
|
2018-08-04 12:23:07 +00:00
|
|
|
done.resolve();
|
|
|
|
});
|
2018-08-03 17:18:42 +00:00
|
|
|
await done.promise;
|
|
|
|
}
|
|
|
|
}
|