TypeScript/src/harness/fourslashRunner.ts

114 lines
4.7 KiB
TypeScript
Raw Normal View History

2014-07-13 01:04:16 +02:00
///<reference path='fourslash.ts' />
///<reference path='harness.ts'/>
///<reference path='runnerbase.ts' />
const enum FourSlashTestType {
2015-02-05 00:36:13 +01:00
Native,
2015-02-12 04:43:30 +01:00
Shims,
Server
2015-02-05 00:36:13 +01:00
}
class FourSlashRunner extends RunnerBase {
protected basePath: string;
protected testSuiteName: string;
2014-07-13 01:04:16 +02:00
2015-02-05 00:36:13 +01:00
constructor(private testType: FourSlashTestType) {
2014-07-13 01:04:16 +02:00
super();
2015-02-05 00:36:13 +01:00
switch (testType) {
case FourSlashTestType.Native:
this.basePath = 'tests/cases/fourslash';
this.testSuiteName = 'fourslash';
break;
case FourSlashTestType.Shims:
this.basePath = 'tests/cases/fourslash/shims';
this.testSuiteName = 'fourslash-shims';
break;
2015-02-12 04:43:30 +01:00
case FourSlashTestType.Server:
this.basePath = 'tests/cases/fourslash/server';
this.testSuiteName = 'fourslash-server';
break;
2015-02-05 00:36:13 +01:00
}
2014-07-13 01:04:16 +02:00
}
public initializeTests() {
if (this.tests.length === 0) {
2015-02-05 00:36:13 +01:00
this.tests = this.enumerateFiles(this.basePath, /\.ts/i, { recursive: false });
2014-07-13 01:04:16 +02:00
}
2015-07-11 03:10:18 +02:00
describe(this.testSuiteName + ' tests', () => {
2014-07-13 01:04:16 +02:00
this.tests.forEach((fn: string) => {
describe(fn, () => {
fn = ts.normalizeSlashes(fn);
var justName = fn.replace(/^.*[\\\/]/, '');
2015-07-11 03:10:18 +02:00
// Convert to relative path
var testIndex = fn.indexOf('tests/');
if (testIndex >= 0) fn = fn.substr(testIndex);
2014-07-13 01:04:16 +02:00
2015-07-11 03:10:18 +02:00
if (justName && !justName.match(/fourslash\.ts$/i) && !justName.match(/\.d\.ts$/i)) {
2015-07-15 01:16:30 +02:00
it(this.testSuiteName + ' test ' + justName + ' runs correctly', () => {
FourSlash.runFourSlashTest(this.basePath, this.testType, fn);
});
}
});
2015-07-11 03:10:18 +02:00
});
2014-07-13 01:04:16 +02:00
describe('Generate Tao XML', () => {
var invalidReasons: any = {};
FourSlash.xmlData.forEach(xml => {
if (xml.invalidReason !== null) {
invalidReasons[xml.invalidReason] = (invalidReasons[xml.invalidReason] || 0) + 1;
}
});
var invalidReport: { reason: string; count: number }[] = [];
for (var reason in invalidReasons) {
if (invalidReasons.hasOwnProperty(reason)) {
invalidReport.push({ reason: reason, count: invalidReasons[reason] });
}
2014-07-13 01:04:16 +02:00
}
invalidReport.sort((lhs, rhs) => lhs.count > rhs.count ? -1 : lhs.count === rhs.count ? 0 : 1);
2014-07-13 01:04:16 +02:00
var lines: string[] = [];
lines.push('<!-- Blocked Test Report');
invalidReport.forEach((reasonAndCount) => {
lines.push(reasonAndCount.count + ' tests blocked by ' + reasonAndCount.reason);
});
lines.push('-->');
lines.push('<TaoTest xmlns="http://microsoft.com/schemas/VSLanguages/TAO">');
lines.push(' <InitTest>');
lines.push(' <StartTarget />');
lines.push(' </InitTest>');
lines.push(' <ScenarioList>');
FourSlash.xmlData.forEach(xml => {
if (xml.invalidReason !== null) {
lines.push('<!-- Skipped ' + xml.originalName + ', reason: ' + xml.invalidReason + ' -->');
} else {
lines.push(' <Scenario Name="' + xml.originalName + '">');
xml.actions.forEach(action => {
lines.push(' ' + action);
});
lines.push(' </Scenario>');
}
});
lines.push(' </ScenarioList>');
lines.push(' <CleanupScenario>');
lines.push(' <CloseAllDocuments />');
lines.push(' <CleanupCreatedFiles />');
lines.push(' </CleanupScenario>');
lines.push(' <CleanupTest>');
lines.push(' <CloseTarget />');
lines.push(' </CleanupTest>');
lines.push('</TaoTest>');
Harness.IO.writeFile('built/local/fourslash.xml', lines.join('\r\n'));
2014-07-13 01:04:16 +02:00
});
});
}
}
2015-02-05 00:36:13 +01:00
class GeneratedFourslashRunner extends FourSlashRunner {
constructor(testType: FourSlashTestType) {
super(testType);
2014-07-13 01:04:16 +02:00
this.basePath += '/generated/';
}
}