added initial set of unit tests for separate compilation mode

This commit is contained in:
Vladimir Matveev 2015-03-30 23:17:45 -07:00
parent 49b3f85a17
commit 1803d730c2
35 changed files with 275 additions and 1 deletions

View file

@ -1062,6 +1062,10 @@ module Harness {
options.preserveConstEnums = setting.value === 'true';
break;
case 'separatecompilation':
options.separateCompilation = setting.value === 'true';
break;
case 'suppressimplicitanyindexerrors':
options.suppressImplicitAnyIndexErrors = setting.value === 'true';
break;
@ -1461,7 +1465,12 @@ 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", "noemitonerror", "noimplicitany", "noresolve", "newline", "newlines", "emitbom", "errortruncation", "usecasesensitivefilenames", "preserveconstenums", "includebuiltfile", "suppressimplicitanyindexerrors", "stripinternal"];
var fileMetadataNames = ["filename", "comments", "declaration", "module",
"nolib", "sourcemap", "target", "out", "outdir", "noemitonerror",
"noimplicitany", "noresolve", "newline", "newlines", "emitbom",
"errortruncation", "usecasesensitivefilenames", "preserveconstenums",
"includebuiltfile", "suppressimplicitanyindexerrors", "stripinternal",
"separatecompilation"];
function extractCompilerSettings(content: string): CompilerSetting[] {

View file

@ -0,0 +1,10 @@
tests/cases/compiler/separateCompilationAmbientConstEnum.ts(3,20): error TS1209: Ambient const enums are not allowed when the '--separateCompilation' flag is provided.
==== tests/cases/compiler/separateCompilationAmbientConstEnum.ts (1 errors) ====
declare const enum E { X = 1}
~
!!! error TS1209: Ambient const enums are not allowed when the '--separateCompilation' flag is provided.
export var y;

View file

@ -0,0 +1,8 @@
//// [separateCompilationAmbientConstEnum.ts]
declare const enum E { X = 1}
export var y;
//// [separateCompilationAmbientConstEnum.js]
export var y;

View file

@ -0,0 +1,7 @@
error TS5044: Option 'declaration' cannot be specified with option 'separateCompilation'.
!!! error TS5044: Option 'declaration' cannot be specified with option 'separateCompilation'.
==== tests/cases/compiler/separateCompilationDeclaration.ts (0 errors) ====
export var x;

View file

@ -0,0 +1,10 @@
//// [separateCompilationDeclaration.ts]
export var x;
//// [separateCompilationDeclaration.js]
export var x;
//// [separateCompilationDeclaration.d.ts]
export declare var x: any;

View file

@ -0,0 +1,5 @@
//// [separateCompilationES6.ts]
export var x;
//// [separateCompilationES6.js]
export var x;

View file

@ -0,0 +1,4 @@
=== tests/cases/compiler/separateCompilationES6.ts ===
export var x;
>x : any

View file

@ -0,0 +1,7 @@
error TS5045: Option 'noEmitOnError' cannot be specified with option 'separateCompilation'.
!!! error TS5045: Option 'noEmitOnError' cannot be specified with option 'separateCompilation'.
==== tests/cases/compiler/separateCompilationNoEmitOnError.ts (0 errors) ====
export var x;

View file

@ -0,0 +1,8 @@
tests/cases/compiler/separateCompilationNoExternalModule.ts(2,1): error TS1208: Cannot compile non-external modules when the '--separateCompilation' flag is provided.
==== tests/cases/compiler/separateCompilationNoExternalModule.ts (1 errors) ====
var x;
~~~
!!! error TS1208: Cannot compile non-external modules when the '--separateCompilation' flag is provided.

View file

@ -0,0 +1,6 @@
//// [separateCompilationNoExternalModule.ts]
var x;
//// [separateCompilationNoExternalModule.js]
var x;

View file

@ -0,0 +1,14 @@
//// [separateCompilationNonAmbientConstEnum.ts]
const enum E { X = 100 };
var e = E.X;
export var x;
//// [separateCompilationNonAmbientConstEnum.js]
var E;
(function (E) {
E[E["X"] = 100] = "X";
})(E || (E = {}));
;
var e = E.X;
export var x;

View file

@ -0,0 +1,15 @@
=== tests/cases/compiler/separateCompilationNonAmbientConstEnum.ts ===
const enum E { X = 100 };
>E : E
>X : E
var e = E.X;
>e : E
>E.X : E
>E : typeof E
>X : E
export var x;
>x : any

View file

@ -0,0 +1,12 @@
error TS5046: Option 'out' cannot be specified with option 'separateCompilation'.
tests/cases/compiler/file2.ts(1,1): error TS1208: Cannot compile non-external modules when the '--separateCompilation' flag is provided.
!!! error TS5046: Option 'out' cannot be specified with option 'separateCompilation'.
==== tests/cases/compiler/file1.ts (0 errors) ====
export var x;
==== tests/cases/compiler/file2.ts (1 errors) ====
var y;
~~~
!!! error TS1208: Cannot compile non-external modules when the '--separateCompilation' flag is provided.

View file

@ -0,0 +1,12 @@
//// [tests/cases/compiler/separateCompilationOut.ts] ////
//// [file1.ts]
export var x;
//// [file2.ts]
var y;
//// [file1.js]
export var x;
//// [all.js]
var y;

View file

@ -0,0 +1,7 @@
error TS5043: Option 'sourceMap' cannot be specified with option 'separateCompilation'.
!!! error TS5043: Option 'sourceMap' cannot be specified with option 'separateCompilation'.
==== tests/cases/compiler/separateCompilationSourceMap.ts (0 errors) ====
export var x;

View file

@ -0,0 +1,7 @@
//// [separateCompilationSourceMap.ts]
export var x;
//// [separateCompilationSourceMap.js]
export var x;
//# sourceMappingURL=separateCompilationSourceMap.js.map

View file

@ -0,0 +1,2 @@
//// [separateCompilationSourceMap.js.map]
{"version":3,"file":"separateCompilationSourceMap.js","sourceRoot":"","sources":["separateCompilationSourceMap.ts"],"names":[],"mappings":"AACA,WAAW,CAAC,CAAC"}

View file

@ -0,0 +1,27 @@
===================================================================
JsFile: separateCompilationSourceMap.js
mapUrl: separateCompilationSourceMap.js.map
sourceRoot:
sources: separateCompilationSourceMap.ts
===================================================================
-------------------------------------------------------------------
emittedFile:tests/cases/compiler/separateCompilationSourceMap.js
sourceFile:separateCompilationSourceMap.ts
-------------------------------------------------------------------
>>>export var x;
1 >
2 >^^^^^^^^^^^
3 > ^
4 > ^
5 > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^->
1 >
>
2 >export var
3 > x
4 > ;
1 >Emitted(1, 1) Source(2, 1) + SourceIndex(0)
2 >Emitted(1, 12) Source(2, 12) + SourceIndex(0)
3 >Emitted(1, 13) Source(2, 13) + SourceIndex(0)
4 >Emitted(1, 14) Source(2, 14) + SourceIndex(0)
---
>>>//# sourceMappingURL=separateCompilationSourceMap.js.map

View file

@ -0,0 +1,5 @@
//// [separateCompilationSpecifiedModule.ts]
export var x;
//// [separateCompilationSpecifiedModule.js]
exports.x;

View file

@ -0,0 +1,4 @@
=== tests/cases/compiler/separateCompilationSpecifiedModule.ts ===
export var x;
>x : any

View file

@ -0,0 +1,6 @@
error TS5047: Option 'separateCompilation' can only be used when either option'--module' is provided or option 'target' is 'ES6' or higher.
!!! error TS5047: Option 'separateCompilation' can only be used when either option'--module' is provided or option 'target' is 'ES6' or higher.
==== tests/cases/compiler/separateCompilationUnspecifiedModule.ts (0 errors) ====
export var x;

View file

@ -0,0 +1,5 @@
//// [separateCompilationUnspecifiedModule.ts]
export var x;
//// [separateCompilationUnspecifiedModule.js]
exports.x;

View file

@ -0,0 +1,11 @@
//// [tests/cases/compiler/separateCompilationWithDeclarationFile.ts] ////
//// [file1.d.ts]
declare function foo(): void;
//// [file1.ts]
export var x;
//// [file1.js]
export var x;

View file

@ -0,0 +1,9 @@
=== tests/cases/compiler/file1.d.ts ===
declare function foo(): void;
>foo : () => void
=== tests/cases/compiler/file1.ts ===
export var x;
>x : any

View file

@ -0,0 +1,7 @@
// @separateCompilation: true
// @target: es6
// @filename: file1.ts
declare const enum E { X = 1}
export var y;

View file

@ -0,0 +1,6 @@
// @separateCompilation: true
// @declaration: true
// @target: es6
// @filename: file1.ts
export var x;

View file

@ -0,0 +1,4 @@
// @separateCompilation: true
// @target: es6
// @filename: file1.ts
export var x;

View file

@ -0,0 +1,6 @@
// @separateCompilation: true
// @noEmitOnError:true
// @target: es6
// @filename: file1.ts
export var x;

View file

@ -0,0 +1,5 @@
// @separateCompilation: true
// @target: es6
// @filename: file1.ts
var x;

View file

@ -0,0 +1,7 @@
// @separateCompilation: true
// @target: es6
// @filename: file1.ts
const enum E { X = 100 };
var e = E.X;
export var x;

View file

@ -0,0 +1,8 @@
// @separateCompilation: true
// @out:all.js
// @target: es6
// @filename: file1.ts
export var x;
// @filename: file2.ts
var y;

View file

@ -0,0 +1,6 @@
// @separateCompilation: true
// @sourceMap:sourcemap.map
// @target: es6
// @filename: file1.ts
export var x;

View file

@ -0,0 +1,4 @@
// @separateCompilation: true
// @module: commonjs
// @filename: file1.ts
export var x;

View file

@ -0,0 +1,3 @@
// @separateCompilation: true
// @filename: file1.ts
export var x;

View file

@ -0,0 +1,8 @@
// @separateCompilation: true
// @target: es6
// @filename: file1.d.ts
declare function foo(): void;
// @filename: file1.ts
export var x;