Skip to content

Commit 5d5062b

Browse files
Merge pull request #140 from h-joo/delete-empty-diff-files
Update baselines + Logic change in reference checking
2 parents f4e5b79 + 35da7eb commit 5d5062b

10 files changed

Lines changed: 71 additions & 72 deletions

src/harness/harnessIO.ts

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1063,7 +1063,12 @@ export namespace Compiler {
10631063
tsSources: readonly TestFile[],
10641064
prettyErrors: boolean | undefined,
10651065
reason: string | undefined,
1066+
expectNull?: boolean,
10661067
) {
1068+
if (expectNull) {
1069+
// eslint-disable-next-line no-null/no-null
1070+
return Baseline.runBaseline(type + "/" + baselinePath.replace(/\.tsx?/, `.d.ts.diff`), /*actual*/ null);
1071+
}
10671072
const Diff = require("diff");
10681073
const dteContent = declarationContent(dteDeclarationFiles, tsSources, dteDiagnostics, prettyErrors);
10691074
const tscContent = declarationContent(tscDeclarationFiles, tsSources, tscDiagnostics, prettyErrors);
@@ -1122,17 +1127,21 @@ export namespace Compiler {
11221127
errors: readonly ts.Diagnostic[],
11231128
tsSources: readonly TestFile[],
11241129
prettyErrors?: boolean,
1130+
expectNull?: boolean,
11251131
) {
1126-
let code = "";
1127-
code += "//// [" + header + "] ////\r\n\r\n";
1132+
if (expectNull) {
1133+
// eslint-disable-next-line no-null/no-null
1134+
return Baseline.runBaseline(type + "/" + baselinePath.replace(/\.tsx?/, `.d.ts`), /*actual*/ null);
1135+
}
1136+
1137+
let code = "//// [" + header + "] ////\r\n\r\n";
11281138

11291139
code += sourceContent(tsSources);
11301140

11311141
code += "\r\n\r\n/// [Declarations] ////\r\n\r\n";
11321142
code += declarationContent(declarationFiles, tsSources, errors, prettyErrors);
11331143

1134-
// eslint-disable-next-line no-null/no-null
1135-
Baseline.runBaseline(type + "/" + baselinePath.replace(/\.tsx?/, `.d.ts`), code.length > 0 ? code : null);
1144+
Baseline.runBaseline(type + "/" + baselinePath.replace(/\.tsx?/, `.d.ts`), code);
11361145
}
11371146

11381147
export function doDeclarationMapBaseline(
@@ -1143,8 +1152,7 @@ export namespace Compiler {
11431152
declarationMapFiles: readonly TestFile[],
11441153
tsSources: readonly TestFile[],
11451154
) {
1146-
let code = "";
1147-
code += "//// [" + header + "] ////\r\n\r\n";
1155+
let code = "//// [" + header + "] ////\r\n\r\n";
11481156

11491157
code += sourceContent(tsSources);
11501158

@@ -1153,8 +1161,7 @@ export namespace Compiler {
11531161
code += "\r\n\r\n/// [Declarations Maps] ////\r\n\r\n";
11541162
code += declarationSourceMapContent(declarationFiles, declarationMapFiles, tsSources);
11551163

1156-
// eslint-disable-next-line no-null/no-null
1157-
Baseline.runBaseline(type + "/" + baselinePath.replace(/\.tsx?/, `.d.ts.map`), code.length > 0 ? code : null);
1164+
Baseline.runBaseline(type + "/" + baselinePath.replace(/\.tsx?/, `.d.ts.map`), code);
11581165
}
11591166

11601167
export function doJsEmitBaseline(baselinePath: string, header: string, options: ts.CompilerOptions, result: compiler.CompilationResult, tsConfigFiles: readonly TestFile[], toBeCompiled: readonly TestFile[], otherFiles: readonly TestFile[], harnessSettings: TestCaseParser.CompilerSettings) {

src/testRunner/compilerRunner.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -615,7 +615,6 @@ class IsolatedDeclarationTest extends CompilerTestBase {
615615
return this.harnessSettings.isolatedDeclarationDiffReason;
616616
}
617617
verifyDteOutput() {
618-
if (this.isOutputEquivalent && this.isDiagnosticEquivalent) return;
619618
Compiler.doDeclarationBaseline(
620619
this.configuredName,
621620
this.baselinePath + "/dte",
@@ -624,10 +623,10 @@ class IsolatedDeclarationTest extends CompilerTestBase {
624623
ts.concatenate(this.dteDiagnostics, this.tscNonIsolatedDeclarationsErrors),
625624
this.allFiles,
626625
this.options.pretty,
626+
this.isOutputEquivalent && this.isDiagnosticEquivalent,
627627
);
628628
}
629629
verifyTscOutput() {
630-
if (this.isOutputEquivalent && this.isDiagnosticEquivalent) return;
631630
Compiler.doDeclarationBaseline(
632631
this.configuredName,
633632
this.baselinePath + "/tsc",
@@ -636,6 +635,7 @@ class IsolatedDeclarationTest extends CompilerTestBase {
636635
ts.concatenate(this.tscIsolatedDeclarationsErrors, this.tscNonIsolatedDeclarationsErrors),
637636
this.allFiles,
638637
this.options.pretty,
638+
this.isOutputEquivalent && this.isDiagnosticEquivalent,
639639
);
640640
}
641641
verifyDteMapOutput() {
@@ -672,9 +672,6 @@ class IsolatedDeclarationTest extends CompilerTestBase {
672672
}
673673
}
674674
verifyDiff() {
675-
if (this.isOutputEquivalent && this.isDiagnosticEquivalent) {
676-
return;
677-
}
678675
Compiler.doDeclarationDiffBaseline(
679676
this.configuredName,
680677
this.baselinePath + "/diff",
@@ -686,6 +683,7 @@ class IsolatedDeclarationTest extends CompilerTestBase {
686683
this.allFiles,
687684
this.options.pretty,
688685
this.diffReason,
686+
this.isOutputEquivalent && this.isDiagnosticEquivalent
689687
);
690688
}
691689

tests/baselines/reference/declFileTypeofFunction.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,6 @@ declare function b1(): typeof b1;
7070
declare function foo(): typeof foo;
7171
declare var foo1: typeof foo;
7272
declare var foo2: typeof foo;
73-
declare var foo3: () => any;
74-
declare var x: () => any;
73+
declare var foo3: () => () => any;
74+
declare var x: () => () => any;
7575
declare function foo5(x: number): (x: number) => number;

tests/baselines/reference/functionExpressionReturningItself.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,4 @@ var x = function somefn() { return somefn; };
88

99

1010
//// [functionExpressionReturningItself.d.ts]
11-
declare var x: () => any;
11+
declare var x: () => () => any;

tests/baselines/reference/parseImportAttributesError.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,5 +47,5 @@ ImportInterface;
4747

4848
//// [index.d.ts]
4949
export type LocalInterface = import("pkg", { with: {} });
50-
export declare const a: any;
51-
export declare const b: any;
50+
export declare const a: import("pkg", { with: {} });
51+
export declare const b: import("pkg", { with: {} });

tests/baselines/reference/tsc/incremental/change-to-modifier-of-class-expression-field-with-declaration-emit-enabled.js

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -188,10 +188,10 @@ Output::
188188
3 console.log( person.message );
189189
   ~~~~~~~
190190

191-
[96msrc/project/MessageablePerson.ts[0m:[93m6[0m:[93m7[0m - [91merror[0m[90m TS4094: [0mProperty 'message' of exported class expression may not be private or protected.
191+
[96msrc/project/MessageablePerson.ts[0m:[93m6[0m:[93m17[0m - [91merror[0m[90m TS4094: [0mProperty 'message' of exported class expression may not be private or protected.
192192

193193
6 const wrapper = () => Messageable();
194-
[7m [0m [91m ~~~~~~~[0m
194+
[7m [0m [91m ~~~~~~~~~~~~~~~~~~~[0m
195195

196196

197197
Found 2 errors in 2 files.
@@ -206,7 +206,7 @@ exitCode:: ExitStatus.DiagnosticsPresent_OutputsSkipped
206206
//// [/src/project/main.js] file written with same contents
207207
//// [/src/project/MessageablePerson.js] file written with same contents
208208
//// [/src/project/tsconfig.tsbuildinfo]
209-
{"program":{"fileNames":["../../lib/lib.d.ts","./messageableperson.ts","./main.ts"],"fileInfos":[{"version":"5700251342-/// <reference no-default-lib=\"true\"/>\ninterface Boolean {}\ninterface Function {}\ninterface CallableFunction {}\ninterface NewableFunction {}\ninterface IArguments {}\ninterface Number { toExponential: any; }\ninterface Object {}\ninterface RegExp {}\ninterface String { charAt: any; }\ninterface Array<T> { length: number; [n: number]: T; }\ninterface ReadonlyArray<T> {}\ndeclare const console: { log(msg: any): void; };type ReturnType<T extends (...args: any) => any> = T extends (...args: any) => infer R ? R : any;\ntype InstanceType<T extends abstract new (...args: any) => any> = T extends abstract new (...args: any) => infer R ? R : any;","affectsGlobalScope":true},{"version":"3462418372-const Messageable = () => {\n return class MessageableClass {\n protected message = 'hello';\n }\n};\nconst wrapper = () => Messageable();\ntype MessageablePerson = InstanceType<ReturnType<typeof wrapper>>;\nexport default MessageablePerson;","signature":"-21450256696-declare const wrapper: () => {\n new (): {\n message: string;\n };\n};\ntype MessageablePerson = InstanceType<ReturnType<typeof wrapper>>;\nexport default MessageablePerson;\n(116,7)Error4094: Property 'message' of exported class expression may not be private or protected."},{"version":"4191603667-import MessageablePerson from './MessageablePerson.js';\nfunction logMessage( person: MessageablePerson ) {\n console.log( person.message );\n}","signature":"-3531856636-export {};\n"}],"root":[2,3],"options":{"declaration":true},"fileIdsList":[[2]],"referencedMap":[[3,1]],"exportedModulesMap":[],"semanticDiagnosticsPerFile":[1,[3,[{"file":"./main.ts","start":131,"length":7,"messageText":"Property 'message' is protected and only accessible within class 'MessageableClass' and its subclasses.","category":1,"code":2445}]],2],"emitDiagnosticsPerFile":[[2,[{"file":"./messageableperson.ts","start":116,"length":7,"messageText":"Property 'message' of exported class expression may not be private or protected.","category":1,"code":4094}]]]},"version":"FakeTSVersion"}
209+
{"program":{"fileNames":["../../lib/lib.d.ts","./messageableperson.ts","./main.ts"],"fileInfos":[{"version":"5700251342-/// <reference no-default-lib=\"true\"/>\ninterface Boolean {}\ninterface Function {}\ninterface CallableFunction {}\ninterface NewableFunction {}\ninterface IArguments {}\ninterface Number { toExponential: any; }\ninterface Object {}\ninterface RegExp {}\ninterface String { charAt: any; }\ninterface Array<T> { length: number; [n: number]: T; }\ninterface ReadonlyArray<T> {}\ndeclare const console: { log(msg: any): void; };type ReturnType<T extends (...args: any) => any> = T extends (...args: any) => infer R ? R : any;\ntype InstanceType<T extends abstract new (...args: any) => any> = T extends abstract new (...args: any) => infer R ? R : any;","affectsGlobalScope":true},{"version":"3462418372-const Messageable = () => {\n return class MessageableClass {\n protected message = 'hello';\n }\n};\nconst wrapper = () => Messageable();\ntype MessageablePerson = InstanceType<ReturnType<typeof wrapper>>;\nexport default MessageablePerson;","signature":"-36832008228-declare const wrapper: () => {\n new (): {\n message: string;\n };\n};\ntype MessageablePerson = InstanceType<ReturnType<typeof wrapper>>;\nexport default MessageablePerson;\n(126,19)Error4094: Property 'message' of exported class expression may not be private or protected."},{"version":"4191603667-import MessageablePerson from './MessageablePerson.js';\nfunction logMessage( person: MessageablePerson ) {\n console.log( person.message );\n}","signature":"-3531856636-export {};\n"}],"root":[2,3],"options":{"declaration":true},"fileIdsList":[[2]],"referencedMap":[[3,1]],"exportedModulesMap":[],"semanticDiagnosticsPerFile":[1,[3,[{"file":"./main.ts","start":131,"length":7,"messageText":"Property 'message' is protected and only accessible within class 'MessageableClass' and its subclasses.","category":1,"code":2445}]],2],"emitDiagnosticsPerFile":[[2,[{"file":"./messageableperson.ts","start":126,"length":19,"messageText":"Property 'message' of exported class expression may not be private or protected.","category":1,"code":4094}]]]},"version":"FakeTSVersion"}
210210

211211
//// [/src/project/tsconfig.tsbuildinfo.readable.baseline.txt]
212212
{
@@ -234,10 +234,10 @@ exitCode:: ExitStatus.DiagnosticsPresent_OutputsSkipped
234234
"./messageableperson.ts": {
235235
"original": {
236236
"version": "3462418372-const Messageable = () => {\n return class MessageableClass {\n protected message = 'hello';\n }\n};\nconst wrapper = () => Messageable();\ntype MessageablePerson = InstanceType<ReturnType<typeof wrapper>>;\nexport default MessageablePerson;",
237-
"signature": "-21450256696-declare const wrapper: () => {\n new (): {\n message: string;\n };\n};\ntype MessageablePerson = InstanceType<ReturnType<typeof wrapper>>;\nexport default MessageablePerson;\n(116,7)Error4094: Property 'message' of exported class expression may not be private or protected."
237+
"signature": "-36832008228-declare const wrapper: () => {\n new (): {\n message: string;\n };\n};\ntype MessageablePerson = InstanceType<ReturnType<typeof wrapper>>;\nexport default MessageablePerson;\n(126,19)Error4094: Property 'message' of exported class expression may not be private or protected."
238238
},
239239
"version": "3462418372-const Messageable = () => {\n return class MessageableClass {\n protected message = 'hello';\n }\n};\nconst wrapper = () => Messageable();\ntype MessageablePerson = InstanceType<ReturnType<typeof wrapper>>;\nexport default MessageablePerson;",
240-
"signature": "-21450256696-declare const wrapper: () => {\n new (): {\n message: string;\n };\n};\ntype MessageablePerson = InstanceType<ReturnType<typeof wrapper>>;\nexport default MessageablePerson;\n(116,7)Error4094: Property 'message' of exported class expression may not be private or protected."
240+
"signature": "-36832008228-declare const wrapper: () => {\n new (): {\n message: string;\n };\n};\ntype MessageablePerson = InstanceType<ReturnType<typeof wrapper>>;\nexport default MessageablePerson;\n(126,19)Error4094: Property 'message' of exported class expression may not be private or protected."
241241
},
242242
"./main.ts": {
243243
"original": {
@@ -290,8 +290,8 @@ exitCode:: ExitStatus.DiagnosticsPresent_OutputsSkipped
290290
[
291291
{
292292
"file": "./messageableperson.ts",
293-
"start": 116,
294-
"length": 7,
293+
"start": 126,
294+
"length": 19,
295295
"messageText": "Property 'message' of exported class expression may not be private or protected.",
296296
"category": 1,
297297
"code": 4094
@@ -301,7 +301,7 @@ exitCode:: ExitStatus.DiagnosticsPresent_OutputsSkipped
301301
]
302302
},
303303
"version": "FakeTSVersion",
304-
"size": 2187
304+
"size": 2189
305305
}
306306

307307

@@ -317,10 +317,10 @@ Output::
317317
3 console.log( person.message );
318318
   ~~~~~~~
319319

320-
[96msrc/project/MessageablePerson.ts[0m:[93m6[0m:[93m7[0m - [91merror[0m[90m TS4094: [0mProperty 'message' of exported class expression may not be private or protected.
320+
[96msrc/project/MessageablePerson.ts[0m:[93m6[0m:[93m17[0m - [91merror[0m[90m TS4094: [0mProperty 'message' of exported class expression may not be private or protected.
321321

322322
6 const wrapper = () => Messageable();
323-
[7m [0m [91m ~~~~~~~[0m
323+
[7m [0m [91m ~~~~~~~~~~~~~~~~~~~[0m
324324

325325

326326
Found 2 errors in 2 files.

0 commit comments

Comments
 (0)