diff --git a/src/harness/harness.ts b/src/harness/harness.ts index 6060f31ce3f..bcef6fabea0 100644 --- a/src/harness/harness.ts +++ b/src/harness/harness.ts @@ -18,7 +18,7 @@ /// /// /// -/// +/// // this will work in the browser via browserify var _chai: typeof chai = require('chai'); @@ -568,6 +568,9 @@ module Harness { private lastErrors: MinimalDiagnostic[]; + // save this away so we can reset the newline value after any tests that change it + private originalNewline = sys.newLine; + public reset() { this.inputFiles = []; this.settings = []; @@ -598,7 +601,7 @@ module Harness { this.inputFiles.push(file); } - public compile(options?: ts.CompilerOptions) { + public setCompilerOptions(options?: ts.CompilerOptions) { this.compileOptions = options || { noResolve: false }; } @@ -624,6 +627,10 @@ module Harness { settingsCallback(null); } + // always use \r\n for newlines unless the test specifies otherwise + // this ensures baseline consistency across Windows and *nix but still lets us test both \n and \r\n + sys.newLine = '\r\n'; + this.settings.forEach(setting => { switch (setting.flag.toLowerCase()) { // "filename", "comments", "declaration", "module", "nolib", "sourcemap", "target", "out", "outDir", "noimplicitany", "noresolve" @@ -692,6 +699,10 @@ module Harness { case 'declaration': options.declaration = !!setting.value; break; + case 'newline': + case 'newlines': + sys.newLine = setting.value; + break; case 'mapsourcefiles': case 'maproot': @@ -740,6 +751,7 @@ module Harness { var sourceMapData: ts.SourceMapData[]; if (!hadParseErrors) { sourceMapData = checker.emitFiles().sourceMaps; + sys.newLine = this.originalNewline; } var errors: MinimalDiagnostic[] = []; @@ -753,6 +765,8 @@ module Harness { // Covert the source Map data into the baseline result.updateSourceMapRecord(program, sourceMapData); onComplete(result); + + sys.newLine = this.originalNewline; return options; } } @@ -851,7 +865,7 @@ module Harness { }); this.errors = errors; - this.sourceMapRecord = sourceMapRecordLines.join('\r\n'); + this.sourceMapRecord = sourceMapRecordLines.join('\n'); } public updateSourceMapRecord(program: ts.Program, sourceMapData: ts.SourceMapData[]) { @@ -891,7 +905,7 @@ module Harness { var optionRegex = /^[\/]{2}\s*@(\w+)\s*:\s*(\S*)/gm; // multiple matches on multiple lines // List of allowed metadata names - var fileMetadataNames = ["filename", "comments", "declaration", "module", "nolib", "sourcemap", "target", "out", "outDir", "noimplicitany", "noresolve"]; + var fileMetadataNames = ["filename", "comments", "declaration", "module", "nolib", "sourcemap", "target", "out", "outDir", "noimplicitany", "noresolve", "newline", "newlines"]; function extractCompilerSettings(content: string): CompilerSetting[] { diff --git a/src/harness/rwcRunner.ts b/src/harness/rwcRunner.ts index 30b9f9a80cf..e4038eb76e6 100644 --- a/src/harness/rwcRunner.ts +++ b/src/harness/rwcRunner.ts @@ -143,7 +143,7 @@ module RWC { harnessCompiler.addInputFile({ unitName: resolvedPath, content: content }); }); - harnessCompiler.compile(); + harnessCompiler.setCompilerOptions(); // Emit the results harnessCompiler.emitAll(emitterIOHost); diff --git a/src/harness/unittestrunner.ts b/src/harness/unittestrunner.ts index 451c868a828..e08b835ac62 100644 --- a/src/harness/unittestrunner.ts +++ b/src/harness/unittestrunner.ts @@ -37,7 +37,7 @@ class UnitTestRunner extends RunnerBase { return { unitName: test, content: Harness.IO.readFile(test) } }); harnessCompiler.addInputFiles(toBeAdded); - harnessCompiler.compile({ noResolve: true }); + harnessCompiler.setCompilerOptions({ noResolve: true }); var stdout = new Harness.Compiler.EmitterIOHost(); var emitDiagnostics = harnessCompiler.emitAll(stdout); diff --git a/tests/cases/compiler/contextualTyping.ts b/tests/cases/compiler/contextualTyping.ts index 408e878f8a4..5a202e507b5 100644 --- a/tests/cases/compiler/contextualTyping.ts +++ b/tests/cases/compiler/contextualTyping.ts @@ -1,4 +1,5 @@ // @sourcemap: true +// @newline: \n // DEFAULT INTERFACES interface IFoo { n: number;