Refactoring test framework to use short-hand

This commit is contained in:
Yui T
2014-11-18 12:30:58 -08:00
parent dcf51d85f4
commit 999e4f1a0b
4 changed files with 36 additions and 36 deletions

View File

@@ -2250,7 +2250,7 @@ module FourSlash {
if (errs.length > 0) {
throw new Error('Error compiling ' + fileName + ': ' + errs.map(e => e.messageText).join('\r\n'));
}
checker.emitFiles();
checker.invokeEmitter();
result = result || ''; // Might have an empty fourslash file
// Compile and execute the test
@@ -2284,7 +2284,7 @@ module FourSlash {
// List of all the subfiles we've parsed out
var files: FourSlashFile[] = [];
// Global options
var opts: { [s: string]: string; } = {};
var globalOptions: { [s: string]: string; } = {};
// Marker positions
// Split up the input file by line
@@ -2292,7 +2292,7 @@ module FourSlash {
// we have to string-based splitting instead and try to figure out the delimiting chars
var lines = contents.split('\n');
var markerMap: MarkerMap = {};
var markerPositions: MarkerMap = {};
var markers: Marker[] = [];
var ranges: Range[] = [];
@@ -2333,7 +2333,7 @@ module FourSlash {
} else if (fileMetadataNamesIndex === fileMetadataNames.indexOf(testOptMetadataNames.filename)) {
// Found an @Filename directive, if this is not the first then create a new subfile
if (currentFileContent) {
var file = parseFileContent(currentFileContent, currentFileName, markerMap, markers, ranges);
var file = parseFileContent(currentFileContent, currentFileName, markerPositions, markers, ranges);
file.fileOptions = currentFileOptions;
// Store result file
@@ -2353,10 +2353,10 @@ module FourSlash {
}
} else {
// Check if the match is already existed in the global options
if (opts[match[1]] !== undefined) {
if (globalOptions[match[1]] !== undefined) {
throw new Error("Global Option : '" + match[1] + "' is already existed");
}
opts[match[1]] = match[2];
globalOptions[match[1]] = match[2];
}
}
} else if (line == '' || lineLength === 0) {
@@ -2365,7 +2365,7 @@ module FourSlash {
} else {
// Empty line or code line, terminate current subfile if there is one
if (currentFileContent) {
var file = parseFileContent(currentFileContent, currentFileName, markerMap, markers, ranges);
var file = parseFileContent(currentFileContent, currentFileName, markerPositions, markers, ranges);
file.fileOptions = currentFileOptions;
// Store result file
@@ -2380,11 +2380,11 @@ module FourSlash {
}
return {
markerPositions: markerMap,
markers: markers,
globalOptions: opts,
files: files,
ranges: ranges
markerPositions,
markers,
globalOptions,
files,
ranges
};
}

View File

@@ -589,8 +589,8 @@ module Harness {
}
},
getDefaultLibFilename: () => defaultLibFileName,
writeFile: writeFile,
getCanonicalFileName: getCanonicalFileName,
writeFile,
getCanonicalFileName,
useCaseSensitiveFileNames: () => useCaseSensitiveFileNames,
getNewLine: ()=> sys.newLine
};
@@ -806,7 +806,7 @@ module Harness {
// only emit if there weren't parse errors
var emitResult: ts.EmitResult;
if (!isEmitBlocked) {
emitResult = checker.emitFiles();
emitResult = checker.invokeEmitter();
}
var errors: HarnessDiagnostic[] = [];
@@ -845,7 +845,7 @@ module Harness {
declResult = compileResult;
}, settingsCallback, options);
return { declInputFiles: declInputFiles, declOtherFiles: declOtherFiles, declResult: declResult };
return { declInputFiles, declOtherFiles, declResult };
}
function addDtsFile(file: { unitName: string; content: string }, dtsFiles: { unitName: string; content: string }[]) {
@@ -1169,7 +1169,7 @@ module Harness {
var settings = extractCompilerSettings(code);
// List of all the subfiles we've parsed out
var files: TestUnitData[] = [];
var testUnitData: TestUnitData[] = [];
var lines = Utils.splitContentByNewlines(code);
@@ -1205,7 +1205,7 @@ module Harness {
originalFilePath: fileName,
references: refs
};
files.push(newTestFile);
testUnitData.push(newTestFile);
// Reset local data
currentFileContent = null;
@@ -1230,7 +1230,7 @@ module Harness {
}
// normalize the fileName for the single file case
currentFileName = files.length > 0 ? currentFileName : Path.getFileName(fileName);
currentFileName = testUnitData.length > 0 ? currentFileName : Path.getFileName(fileName);
// EOF, push whatever remains
var newTestFile2 = {
@@ -1240,9 +1240,9 @@ module Harness {
originalFilePath: fileName,
references: refs
};
files.push(newTestFile2);
testUnitData.push(newTestFile2);
return { settings: settings, testUnitData: files };
return { settings, testUnitData };
}
}
@@ -1338,7 +1338,7 @@ module Harness {
actual = actual.replace(/\r\n?/g, '\n');
}
return { expected: expected, actual: actual };
return { expected, actual };
}
function writeComparison(expected: string, actual: string, relativeFilename: string, actualFilename: string, descriptionForDescribe: string) {

View File

@@ -131,7 +131,7 @@ class ProjectRunner extends RunnerBase {
if (!errors.length) {
var checker = program.getTypeChecker(/*fullTypeCheck*/ true);
errors = checker.getDiagnostics();
var emitResult = checker.emitFiles();
var emitResult = checker.invokeEmitter();
errors = ts.concatenate(errors, emitResult.errors);
sourceMapData = emitResult.sourceMaps;
@@ -148,10 +148,10 @@ class ProjectRunner extends RunnerBase {
}
return {
moduleKind: moduleKind,
program: program,
errors: errors,
sourceMapData: sourceMapData
moduleKind,
program,
errors,
sourceMapData
};
function createCompilerOptions(): ts.CompilerOptions {
@@ -183,10 +183,10 @@ class ProjectRunner extends RunnerBase {
function createCompilerHost(): ts.CompilerHost {
return {
getSourceFile: getSourceFile,
getSourceFile,
getDefaultLibFilename: () => "lib.d.ts",
writeFile: writeFile,
getCurrentDirectory: getCurrentDirectory,
writeFile,
getCurrentDirectory,
getCanonicalFileName: Harness.Compiler.getCanonicalFileName,
useCaseSensitiveFileNames: () => sys.useCaseSensitiveFileNames,
getNewLine: () => sys.newLine
@@ -201,12 +201,12 @@ class ProjectRunner extends RunnerBase {
var projectCompilerResult = compileProjectFiles(moduleKind, () => testCase.inputFiles, getSourceFileText, writeFile);
return {
moduleKind: moduleKind,
moduleKind,
program: projectCompilerResult.program,
sourceMapData: projectCompilerResult.sourceMapData,
outputFiles: outputFiles,
outputFiles,
errors: projectCompilerResult.errors,
nonSubfolderDiskFiles: nonSubfolderDiskFiles,
nonSubfolderDiskFiles,
};
function getSourceFileText(filename: string): string {

View File

@@ -117,14 +117,14 @@ module RWC {
});
function getHarnessCompilerInputUnit(fileName: string) {
var resolvedPath = ts.normalizeSlashes(sys.resolvePath(fileName));
var unitName = ts.normalizeSlashes(sys.resolvePath(fileName));
try {
var content = sys.readFile(resolvedPath);
var content = sys.readFile(unitName);
}
catch (e) {
// Leave content undefined.
}
return { unitName: resolvedPath, content: content };
return { unitName, content };
}
});