From 66f0715a84375cf0d112950085b96457bdeb5ec0 Mon Sep 17 00:00:00 2001 From: Yui T Date: Fri, 27 Mar 2015 10:30:45 -0700 Subject: [PATCH 1/2] Allow RWC runner to use default library instead of the one in json file --- src/harness/harness.ts | 8 +++++++ src/harness/loggedIO.ts | 1 + src/harness/rwcRunner.ts | 51 +++++++++++++++++++++++++++++----------- 3 files changed, 46 insertions(+), 14 deletions(-) diff --git a/src/harness/harness.ts b/src/harness/harness.ts index 90ffcef07ff..90ca94b4ab6 100644 --- a/src/harness/harness.ts +++ b/src/harness/harness.ts @@ -1703,6 +1703,14 @@ module Harness { return (Path.getFileName(filePath) === 'lib.d.ts') || (Path.getFileName(filePath) === 'lib.core.d.ts'); } + export function getDefaultLibraryFile(): { unitName: string, content: string } { + var libFile = Harness.userSpecifiedroot + Harness.libFolder + "/" + "lib.d.ts"; + return { + unitName: libFile, + content: IO.readFile(libFile) + } + } + if (Error) (Error).stackTraceLimit = 1; } diff --git a/src/harness/loggedIO.ts b/src/harness/loggedIO.ts index d9418c0e6ae..b4c88898a51 100644 --- a/src/harness/loggedIO.ts +++ b/src/harness/loggedIO.ts @@ -15,6 +15,7 @@ interface IOLog { arguments: string[]; executingPath: string; currentDirectory: string; + useDefaultLibFile?: boolean; filesRead: { path: string; codepage: number; diff --git a/src/harness/rwcRunner.ts b/src/harness/rwcRunner.ts index c1c3251cf02..1578d0665ca 100644 --- a/src/harness/rwcRunner.ts +++ b/src/harness/rwcRunner.ts @@ -32,6 +32,7 @@ module RWC { }; var baseName = /(.*)\/(.*).json/.exec(ts.normalizeSlashes(jsonPath))[2]; var currentDirectory: string; + var useDefaultLibFile: boolean; after(() => { // Mocha holds onto the closure environment of the describe callback even after the test is done. @@ -43,6 +44,10 @@ module RWC { baselineOpts = undefined; baseName = undefined; currentDirectory = undefined; + // useDefaultLibFile is a flag specified in the json object to indicate whether to use built/local/lib.d.ts + // or to use lib.d.ts inside the json object. If the flag is true or undefine, use the build/local/lib.d.ts + // otherwise use the lib.d.ts from the json object. + useDefaultLibFile = undefined; }); it('can compile', () => { @@ -51,32 +56,52 @@ module RWC { var ioLog: IOLog = JSON.parse(Harness.IO.readFile(jsonPath)); currentDirectory = ioLog.currentDirectory; + useDefaultLibFile = ioLog.useDefaultLibFile; + if (useDefaultLibFile === undefined) { + useDefaultLibFile = true; + } runWithIOLog(ioLog, () => { opts = ts.parseCommandLine(ioLog.arguments); assert.equal(opts.errors.length, 0); + + // To provide test coverage of output javascript file, + // we will set noEmitOnError flag to be false. + opts.options.noEmitOnError = false; }); runWithIOLog(ioLog, () => { harnessCompiler.reset(); + // Load the files ts.forEach(opts.fileNames, fileName => { inputFiles.push(getHarnessCompilerInputUnit(fileName)); }); - if (!opts.options.noLib) { - // Find the lib.d.ts file in the input file and add it to the input files list - var libFile = ts.forEach(ioLog.filesRead, fileRead=> Harness.isLibraryFile(fileRead.path) ? fileRead.path : undefined); - if (libFile) { - inputFiles.push(getHarnessCompilerInputUnit(libFile)); - } - } - + // Add files to compilation ts.forEach(ioLog.filesRead, fileRead => { + // Check if the file is already added into the set of input files. var resolvedPath = ts.normalizeSlashes(ts.sys.resolvePath(fileRead.path)); var inInputList = ts.forEach(inputFiles, inputFile=> inputFile.unitName === resolvedPath); - if (!inInputList) { - // Add the file to other files - otherFiles.push(getHarnessCompilerInputUnit(fileRead.path)); + + if (!Harness.isLibraryFile(fileRead.path)) { + if (!inInputList) { + otherFiles.push(getHarnessCompilerInputUnit(fileRead.path)); + } + } + else if (!opts.options.noLib && Harness.isLibraryFile(fileRead.path)){ + if (!inInputList) { + // If useDefaultLibFile is true, we will use built/local/lib.d.ts + // instead of the provided lib.d.ts from json object. + // Majority of RWC code will be using built/local/lib.d.ts instead of + // lib.d.ts inside json file. However, some RWC cases will still use + // their own version of lib.d.ts because they have customized lib.d.ts + if (useDefaultLibFile) { + inputFiles.push(Harness.getDefaultLibraryFile()); + } + else { + inputFiles.push(getHarnessCompilerInputUnit(fileRead.path)); + } + } } }); @@ -115,9 +140,7 @@ module RWC { it('has the expected declaration file content', () => { Harness.Baseline.runBaseline('has the expected declaration file content', baseName + '.d.ts', () => { - if (compilerResult.errors.length || !compilerResult.declFilesCode.length) { - return null; - } + if (!compilerResult.declFilesCode.length) { return null; } return Harness.Compiler.collateOutputs(compilerResult.declFilesCode); }, false, baselineOpts); }); From a8e4f27e50448579e7775bfe0eaf442c3573e5fd Mon Sep 17 00:00:00 2001 From: Yui T Date: Fri, 27 Mar 2015 16:12:19 -0700 Subject: [PATCH 2/2] Address code review --- src/harness/loggedIO.ts | 2 +- src/harness/rwcRunner.ts | 41 ++++++++++++++++++++-------------------- 2 files changed, 22 insertions(+), 21 deletions(-) diff --git a/src/harness/loggedIO.ts b/src/harness/loggedIO.ts index b4c88898a51..8ba38043e78 100644 --- a/src/harness/loggedIO.ts +++ b/src/harness/loggedIO.ts @@ -15,7 +15,7 @@ interface IOLog { arguments: string[]; executingPath: string; currentDirectory: string; - useDefaultLibFile?: boolean; + useCustomLibraryFile?: boolean; filesRead: { path: string; codepage: number; diff --git a/src/harness/rwcRunner.ts b/src/harness/rwcRunner.ts index 1578d0665ca..49a15112e9f 100644 --- a/src/harness/rwcRunner.ts +++ b/src/harness/rwcRunner.ts @@ -32,7 +32,7 @@ module RWC { }; var baseName = /(.*)\/(.*).json/.exec(ts.normalizeSlashes(jsonPath))[2]; var currentDirectory: string; - var useDefaultLibFile: boolean; + var useCustomLibraryFile: boolean; after(() => { // Mocha holds onto the closure environment of the describe callback even after the test is done. @@ -44,10 +44,10 @@ module RWC { baselineOpts = undefined; baseName = undefined; currentDirectory = undefined; - // useDefaultLibFile is a flag specified in the json object to indicate whether to use built/local/lib.d.ts - // or to use lib.d.ts inside the json object. If the flag is true or undefine, use the build/local/lib.d.ts - // otherwise use the lib.d.ts from the json object. - useDefaultLibFile = undefined; + // useCustomLibraryFile is a flag specified in the json object to indicate whether to use built/local/lib.d.ts + // or to use lib.d.ts inside the json object. If the flag is true, use the lib.d.ts inside json file + // otherwise use the lib.d.ts from built/local + useCustomLibraryFile = undefined; }); it('can compile', () => { @@ -56,10 +56,7 @@ module RWC { var ioLog: IOLog = JSON.parse(Harness.IO.readFile(jsonPath)); currentDirectory = ioLog.currentDirectory; - useDefaultLibFile = ioLog.useDefaultLibFile; - if (useDefaultLibFile === undefined) { - useDefaultLibFile = true; - } + useCustomLibraryFile = ioLog.useCustomLibraryFile; runWithIOLog(ioLog, () => { opts = ts.parseCommandLine(ioLog.arguments); assert.equal(opts.errors.length, 0); @@ -78,32 +75,33 @@ module RWC { }); // Add files to compilation - ts.forEach(ioLog.filesRead, fileRead => { + for(let fileRead of ioLog.filesRead) { // Check if the file is already added into the set of input files. var resolvedPath = ts.normalizeSlashes(ts.sys.resolvePath(fileRead.path)); - var inInputList = ts.forEach(inputFiles, inputFile=> inputFile.unitName === resolvedPath); + var inInputList = ts.forEach(inputFiles, inputFile => inputFile.unitName === resolvedPath); if (!Harness.isLibraryFile(fileRead.path)) { - if (!inInputList) { - otherFiles.push(getHarnessCompilerInputUnit(fileRead.path)); + if (inInputList) { + continue; } + otherFiles.push(getHarnessCompilerInputUnit(fileRead.path)); } else if (!opts.options.noLib && Harness.isLibraryFile(fileRead.path)){ if (!inInputList) { - // If useDefaultLibFile is true, we will use built/local/lib.d.ts - // instead of the provided lib.d.ts from json object. + // If useCustomLibraryFile is true, we will use lib.d.ts from json object + // otherwise use the lib.d.ts from built/local // Majority of RWC code will be using built/local/lib.d.ts instead of // lib.d.ts inside json file. However, some RWC cases will still use // their own version of lib.d.ts because they have customized lib.d.ts - if (useDefaultLibFile) { - inputFiles.push(Harness.getDefaultLibraryFile()); + if (useCustomLibraryFile) { + inputFiles.push(getHarnessCompilerInputUnit(fileRead.path)); } else { - inputFiles.push(getHarnessCompilerInputUnit(fileRead.path)); + inputFiles.push(Harness.getDefaultLibraryFile()); } } } - }); + } // do not use lib since we already read it in above opts.options.noLib = true; @@ -140,7 +138,10 @@ module RWC { it('has the expected declaration file content', () => { Harness.Baseline.runBaseline('has the expected declaration file content', baseName + '.d.ts', () => { - if (!compilerResult.declFilesCode.length) { return null; } + if (!compilerResult.declFilesCode.length) { + return null; + } + return Harness.Compiler.collateOutputs(compilerResult.declFilesCode); }, false, baselineOpts); });