Skip to content

Commit 0bc2b65

Browse files
authored
Retire $ExpectError awareness from DefinitelyTypedRunner (#49756)
1 parent 641ab8e commit 0bc2b65

1 file changed

Lines changed: 6 additions & 34 deletions

File tree

src/testRunner/externalCompileRunner.ts

Lines changed: 6 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ namespace Harness {
1818

1919
abstract class ExternalCompileRunnerBase extends RunnerBase {
2020
abstract testDir: string;
21-
abstract report(result: ExecResult, cwd: string): string | null;
21+
abstract report(result: ExecResult): string | null;
2222
enumerateTestFiles() {
2323
return IO.getDirectories(this.testDir);
2424
}
@@ -91,7 +91,7 @@ namespace Harness {
9191
}
9292
}
9393
args.push("--noEmit");
94-
Baseline.runBaseline(`${cls.kind()}/${directoryName}.log`, cls.report(cp.spawnSync(`node`, args, { cwd, timeout, shell: true }), cwd));
94+
Baseline.runBaseline(`${cls.kind()}/${directoryName}.log`, cls.report(cp.spawnSync(`node`, args, { cwd, timeout, shell: true })));
9595

9696
function exec(command: string, args: string[], options: { cwd: string, timeout?: number, stdio?: import("child_process").StdioOptions }): string | undefined {
9797
const res = cp.spawnSync(isWorker ? `${command} 2>&1` : command, args, { shell: true, stdio, ...options });
@@ -281,46 +281,18 @@ ${sanitizeDockerfileOutput(result.stderr.toString())}`;
281281
kind(): TestRunnerKind {
282282
return "dt";
283283
}
284-
report(result: ExecResult, cwd: string) {
285-
const stdout = removeExpectedErrors(result.stdout.toString(), cwd);
286-
const stderr = result.stderr.toString();
287-
284+
report(result: ExecResult) {
288285
// eslint-disable-next-line no-null/no-null
289-
return !stdout.length && !stderr.length ? null : `Exit Code: ${result.status}
286+
return !result.stdout.length && !result.stderr.length ? null : `Exit Code: ${result.status}
290287
Standard output:
291-
${stdout.replace(/\r\n/g, "\n")}
288+
${result.stdout.toString().replace(/\r\n/g, "\n")}
292289
293290
294291
Standard error:
295-
${stderr.replace(/\r\n/g, "\n")}`;
292+
${result.stderr.toString().replace(/\r\n/g, "\n")}`;
296293
}
297294
}
298295

299-
function removeExpectedErrors(errors: string, cwd: string): string {
300-
return ts.flatten(splitBy(errors.split("\n"), s => /^\S+/.test(s)).filter(isUnexpectedError(cwd))).join("\n");
301-
}
302-
/**
303-
* Returns true if the line that caused the error contains '$ExpectError',
304-
* or if the line before that one contains '$ExpectError'.
305-
* '$ExpectError' is a marker used in Definitely Typed tests,
306-
* meaning that the error should not contribute toward our error baslines.
307-
*/
308-
function isUnexpectedError(cwd: string) {
309-
return (error: string[]) => {
310-
ts.Debug.assertGreaterThanOrEqual(error.length, 1);
311-
const match = error[0].match(/(.+\.tsx?)\((\d+),\d+\): error TS/);
312-
if (!match) {
313-
return true;
314-
}
315-
const [, errorFile, lineNumberString] = match;
316-
const lines = fs.readFileSync(path.join(cwd, errorFile), { encoding: "utf8" }).split("\n");
317-
const lineNumber = parseInt(lineNumberString) - 1;
318-
ts.Debug.assertGreaterThanOrEqual(lineNumber, 0);
319-
ts.Debug.assertLessThan(lineNumber, lines.length);
320-
const previousLine = lineNumber - 1 > 0 ? lines[lineNumber - 1] : "";
321-
return !ts.stringContains(lines[lineNumber], "$ExpectError") && !ts.stringContains(previousLine, "$ExpectError");
322-
};
323-
}
324296
/**
325297
* Split an array into multiple arrays whenever `isStart` returns true.
326298
* @example

0 commit comments

Comments
 (0)