Skip to content

Commit

Permalink
Merge pull request microsoft#3863 from Microsoft/tslintHarnessCode
Browse files Browse the repository at this point in the history
Update harness code for TSLint rules
  • Loading branch information
danquirk committed Jul 15, 2015
2 parents c27b379 + 26636f5 commit 32a040b
Show file tree
Hide file tree
Showing 14 changed files with 813 additions and 809 deletions.
19 changes: 11 additions & 8 deletions Jakefile.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ var languageServiceLibrarySources = [
return path.join(serverDirectory, f);
}).concat(servicesSources);

var harnessSources = [
var harnessCoreSources = [
"harness.ts",
"sourceMapRecorder.ts",
"harnessLanguageService.ts",
Expand All @@ -129,7 +129,9 @@ var harnessSources = [
"runner.ts"
].map(function (f) {
return path.join(harnessDirectory, f);
}).concat([
});

var harnessSources = harnessCoreSources.concat([
"incrementalParser.ts",
"jsDocParsing.ts",
"services/colorization.ts",
Expand Down Expand Up @@ -730,12 +732,13 @@ task("update-sublime", ["local", serverFile], function() {
// run this task automatically
desc("Runs tslint on the compiler sources");
task("lint", [], function() {
for(var i in compilerSources) {
var f = compilerSources[i];
function success(f) { return function() { console.log('SUCCESS: No linter errors in ' + f + '\n'); }};
function failure(f) { return function() { console.log('FAILURE: Please fix linting errors in ' + f + '\n') }};

var lintTargets = compilerSources.concat(harnessCoreSources);
for(var i in lintTargets) {
var f = lintTargets[i];
var cmd = 'tslint -f ' + f;
exec(cmd,
function() { console.log('SUCCESS: No linter errors'); },
function() { console.log('FAILURE: Please fix linting errors in ' + f + '\n');
});
exec(cmd, success(f), failure(f));
}
}, { async: true });
79 changes: 39 additions & 40 deletions src/harness/compilerRunner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,27 +42,26 @@ class CompilerBaselineRunner extends RunnerBase {
describe('compiler tests for ' + fileName, () => {
// Mocha holds onto the closure environment of the describe callback even after the test is done.
// Everything declared here should be cleared out in the "after" callback.
var justName: string;
var content: string;
var testCaseContent: { settings: Harness.TestCaseParser.CompilerSetting[]; testUnitData: Harness.TestCaseParser.TestUnitData[]; }
let justName: string;
let content: string;
let testCaseContent: { settings: Harness.TestCaseParser.CompilerSetting[]; testUnitData: Harness.TestCaseParser.TestUnitData[]; };

var units: Harness.TestCaseParser.TestUnitData[];
var tcSettings: Harness.TestCaseParser.CompilerSetting[];
var createNewInstance: boolean;
let units: Harness.TestCaseParser.TestUnitData[];
let tcSettings: Harness.TestCaseParser.CompilerSetting[];

var lastUnit: Harness.TestCaseParser.TestUnitData;
var rootDir: string;
let lastUnit: Harness.TestCaseParser.TestUnitData;
let rootDir: string;

var result: Harness.Compiler.CompilerResult;
var program: ts.Program;
var options: ts.CompilerOptions;
let result: Harness.Compiler.CompilerResult;
let program: ts.Program;
let options: ts.CompilerOptions;
// equivalent to the files that will be passed on the command line
var toBeCompiled: { unitName: string; content: string }[];
let toBeCompiled: { unitName: string; content: string }[];
// equivalent to other files on the file system not directly passed to the compiler (ie things that are referenced by other files)
var otherFiles: { unitName: string; content: string }[];
var harnessCompiler: Harness.Compiler.HarnessCompiler;
let otherFiles: { unitName: string; content: string }[];
let harnessCompiler: Harness.Compiler.HarnessCompiler;

var createNewInstance = false;
let createNewInstance = false;

before(() => {
justName = fileName.replace(/^.*[\\\/]/, ''); // strips the fileName from the path.
Expand Down Expand Up @@ -105,7 +104,7 @@ class CompilerBaselineRunner extends RunnerBase {
/* The compiler doesn't handle certain flags flipping during a single compilation setting. Tests on these flags will need
a fresh compiler instance for themselves and then create a fresh one for the next test. Would be nice to get dev fixes
eventually to remove this limitation. */
for (var i = 0; i < tcSettings.length; ++i) {
for (let i = 0; i < tcSettings.length; ++i) {
// noImplicitAny is passed to getCompiler, but target is just passed in the settings blob to setCompilerSettings
if (!createNewInstance && (tcSettings[i].flag == "noimplicitany" || tcSettings[i].flag === 'target')) {
harnessCompiler = Harness.Compiler.getCompiler();
Expand Down Expand Up @@ -162,7 +161,7 @@ class CompilerBaselineRunner extends RunnerBase {
it('Correct sourcemap content for ' + fileName, () => {
if (options.sourceMap || options.inlineSourceMap) {
Harness.Baseline.runBaseline('Correct sourcemap content for ' + fileName, justName.replace(/\.tsx?$/, '.sourcemap.txt'), () => {
var record = result.getSourceMapRecord();
let record = result.getSourceMapRecord();
if (options.noEmitOnError && result.errors.length !== 0 && record === undefined) {
// Because of the noEmitOnError option no files are created. We need to return null because baselining isn't required.
return null;
Expand All @@ -180,33 +179,33 @@ class CompilerBaselineRunner extends RunnerBase {

// check js output
Harness.Baseline.runBaseline('Correct JS output for ' + fileName, justName.replace(/\.tsx?/, '.js'), () => {
var tsCode = '';
var tsSources = otherFiles.concat(toBeCompiled);
let tsCode = '';
let tsSources = otherFiles.concat(toBeCompiled);
if (tsSources.length > 1) {
tsCode += '//// [' + fileName + '] ////\r\n\r\n';
}
for (var i = 0; i < tsSources.length; i++) {
for (let i = 0; i < tsSources.length; i++) {
tsCode += '//// [' + Harness.Path.getFileName(tsSources[i].unitName) + ']\r\n';
tsCode += tsSources[i].content + (i < (tsSources.length - 1) ? '\r\n' : '');
}

var jsCode = '';
for (var i = 0; i < result.files.length; i++) {
let jsCode = '';
for (let i = 0; i < result.files.length; i++) {
jsCode += '//// [' + Harness.Path.getFileName(result.files[i].fileName) + ']\r\n';
jsCode += getByteOrderMarkText(result.files[i]);
jsCode += result.files[i].code;
}

if (result.declFilesCode.length > 0) {
jsCode += '\r\n\r\n';
for (var i = 0; i < result.declFilesCode.length; i++) {
for (let i = 0; i < result.declFilesCode.length; i++) {
jsCode += '//// [' + Harness.Path.getFileName(result.declFilesCode[i].fileName) + ']\r\n';
jsCode += getByteOrderMarkText(result.declFilesCode[i]);
jsCode += result.declFilesCode[i].code;
}
}

var declFileCompilationResult = harnessCompiler.compileDeclarationFiles(toBeCompiled, otherFiles, result, function (settings) {
let declFileCompilationResult = harnessCompiler.compileDeclarationFiles(toBeCompiled, otherFiles, result, function (settings) {
harnessCompiler.setCompilerSettings(tcSettings);
}, options);

Expand Down Expand Up @@ -244,8 +243,8 @@ class CompilerBaselineRunner extends RunnerBase {
return null;
}

var sourceMapCode = '';
for (var i = 0; i < result.sourceMaps.length; i++) {
let sourceMapCode = '';
for (let i = 0; i < result.sourceMaps.length; i++) {
sourceMapCode += '//// [' + Harness.Path.getFileName(result.sourceMaps[i].fileName) + ']\r\n';
sourceMapCode += getByteOrderMarkText(result.sourceMaps[i]);
sourceMapCode += result.sourceMaps[i].code;
Expand Down Expand Up @@ -293,7 +292,7 @@ class CompilerBaselineRunner extends RunnerBase {

// Produce baselines. The first gives the types for all expressions.
// The second gives symbols for all identifiers.
var e1: Error, e2: Error;
let e1: Error, e2: Error;
try {
checkBaseLines(/*isSymbolBaseLine:*/ false);
}
Expand Down Expand Up @@ -335,32 +334,32 @@ class CompilerBaselineRunner extends RunnerBase {
let typeMap: { [fileName: string]: { [lineNum: number]: string[]; } } = {};

allFiles.forEach(file => {
var codeLines = file.content.split('\n');
let codeLines = file.content.split('\n');
typeWriterResults[file.unitName].forEach(result => {
if (isSymbolBaseline && !result.symbol) {
return;
}

var typeOrSymbolString = isSymbolBaseline ? result.symbol : result.type;
var formattedLine = result.sourceText.replace(/\r?\n/g, "") + " : " + typeOrSymbolString;
let typeOrSymbolString = isSymbolBaseline ? result.symbol : result.type;
let formattedLine = result.sourceText.replace(/\r?\n/g, "") + " : " + typeOrSymbolString;
if (!typeMap[file.unitName]) {
typeMap[file.unitName] = {};
}

var typeInfo = [formattedLine];
var existingTypeInfo = typeMap[file.unitName][result.line];
let typeInfo = [formattedLine];
let existingTypeInfo = typeMap[file.unitName][result.line];
if (existingTypeInfo) {
typeInfo = existingTypeInfo.concat(typeInfo);
}
typeMap[file.unitName][result.line] = typeInfo;
});

typeLines.push('=== ' + file.unitName + ' ===\r\n');
for (var i = 0; i < codeLines.length; i++) {
var currentCodeLine = codeLines[i];
for (let i = 0; i < codeLines.length; i++) {
let currentCodeLine = codeLines[i];
typeLines.push(currentCodeLine + '\r\n');
if (typeMap[file.unitName]) {
var typeInfo = typeMap[file.unitName][i];
let typeInfo = typeMap[file.unitName][i];
if (typeInfo) {
typeInfo.forEach(ty => {
typeLines.push('>' + ty + '\r\n');
Expand Down Expand Up @@ -388,13 +387,13 @@ class CompilerBaselineRunner extends RunnerBase {
public initializeTests() {
describe(this.testSuiteName + ' tests', () => {
describe("Setup compiler for compiler baselines", () => {
var harnessCompiler = Harness.Compiler.getCompiler();
let harnessCompiler = Harness.Compiler.getCompiler();
this.parseOptions();
});

// this will set up a series of describe/it blocks to run between the setup and cleanup phases
if (this.tests.length === 0) {
var testFiles = this.enumerateFiles(this.basePath, /\.tsx?$/, { recursive: true });
let testFiles = this.enumerateFiles(this.basePath, /\.tsx?$/, { recursive: true });
testFiles.forEach(fn => {
fn = fn.replace(/\\/g, "/");
this.checkTestCodeOutput(fn);
Expand All @@ -405,7 +404,7 @@ class CompilerBaselineRunner extends RunnerBase {
}

describe("Cleanup after compiler baselines", () => {
var harnessCompiler = Harness.Compiler.getCompiler();
let harnessCompiler = Harness.Compiler.getCompiler();
});
});
}
Expand All @@ -417,8 +416,8 @@ class CompilerBaselineRunner extends RunnerBase {
this.decl = false;
this.output = false;

var opts = this.options.split(',');
for (var i = 0; i < opts.length; i++) {
let opts = this.options.split(',');
for (let i = 0; i < opts.length; i++) {
switch (opts[i]) {
case 'error':
this.errors = true;
Expand Down
Loading

0 comments on commit 32a040b

Please sign in to comment.