Skip to content

Commit 0d7763e

Browse files
authored
Sanitize version string for syntactically invalid buildinfo baselines (#59932)
1 parent 48f0b3c commit 0d7763e

File tree

4 files changed

+15
-5
lines changed

4 files changed

+15
-5
lines changed

src/testRunner/unittests/tsbuild/sample.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
import { Baseline } from "../../_namespaces/Harness.js";
22
import * as ts from "../../_namespaces/ts.js";
33
import { jsonToReadableText } from "../helpers.js";
4-
import { patchHostForBuildInfoReadWrite } from "../helpers/baseline.js";
4+
import {
5+
fakeTsVersion,
6+
patchHostForBuildInfoReadWrite,
7+
} from "../helpers/baseline.js";
58
import { getTypeScriptLibTestLocation } from "../helpers/contents.js";
69
import {
710
getSysForSampleProjectReferences,
@@ -198,7 +201,10 @@ describe("unittests:: tsbuild:: on 'sample1' project", () => {
198201
commandLineArgs: ["--b", "-i", "-v"],
199202
edits: [{
200203
caption: "tsbuildinfo written has error",
201-
edit: sys => sys.prependFile("/home/src/workspaces/project/tsconfig.tsbuildinfo", "Some random string"),
204+
edit: sys => {
205+
sys.prependFile("/home/src/workspaces/project/tsconfig.tsbuildinfo", "Some random string");
206+
sys.replaceFileText("/home/src/workspaces/project/tsconfig.tsbuildinfo", `"version":"${ts.version}"`, `"version":"${fakeTsVersion}"`); // build info won't parse, need to manually sterilize for baseline
207+
},
202208
}],
203209
});
204210

src/testRunner/unittests/tsc/incremental.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import * as ts from "../../_namespaces/ts.js";
22
import { dedent } from "../../_namespaces/Utils.js";
33
import { jsonToReadableText } from "../helpers.js";
4+
import { fakeTsVersion } from "../helpers/baseline.js";
45
import { compilerOptionsToConfigJson } from "../helpers/contents.js";
56
import {
67
noChangeOnlyRuns,
@@ -100,7 +101,10 @@ describe("unittests:: tsc:: incremental::", () => {
100101
commandLineArgs: ["-i"],
101102
edits: [{
102103
caption: "tsbuildinfo written has error",
103-
edit: sys => sys.prependFile("/home/src/workspaces/project/tsconfig.tsbuildinfo", "Some random string"),
104+
edit: sys => {
105+
sys.prependFile("/home/src/workspaces/project/tsconfig.tsbuildinfo", "Some random string");
106+
sys.replaceFileText("/home/src/workspaces/project/tsconfig.tsbuildinfo", `"version":"${ts.version}"`, `"version":"${fakeTsVersion}"`); // build info won't parse, need to manually sterilize for baseline
107+
},
104108
}],
105109
});
106110

tests/baselines/reference/tsbuild/sample1/tsbuildinfo-has-error.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ Change:: tsbuildinfo written has error
8484

8585
Input::
8686
//// [/home/src/workspaces/project/tsconfig.tsbuildinfo]
87-
Some random string{"fileNames":["../../tslibs/ts/lib/lib.d.ts","./main.ts"],"fileInfos":[{"version":"3858781397-/// <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; };","affectsGlobalScope":true},"-10726455937-export const x = 10;"],"root":[2],"version":"5.7.0-dev"}
87+
Some random string{"fileNames":["../../tslibs/ts/lib/lib.d.ts","./main.ts"],"fileInfos":[{"version":"3858781397-/// <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; };","affectsGlobalScope":true},"-10726455937-export const x = 10;"],"root":[2],"version":"FakeTSVersion"}
8888

8989

9090
/home/src/tslibs/TS/Lib/tsc.js --b -i -v

tests/baselines/reference/tsc/incremental/tsbuildinfo-has-error.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ Change:: tsbuildinfo written has error
7777

7878
Input::
7979
//// [/home/src/workspaces/project/tsconfig.tsbuildinfo]
80-
Some random string{"fileNames":["../../tslibs/ts/lib/lib.d.ts","./main.ts"],"fileInfos":[{"version":"3858781397-/// <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; };","affectsGlobalScope":true},"-10726455937-export const x = 10;"],"root":[2],"version":"5.7.0-dev"}
80+
Some random string{"fileNames":["../../tslibs/ts/lib/lib.d.ts","./main.ts"],"fileInfos":[{"version":"3858781397-/// <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; };","affectsGlobalScope":true},"-10726455937-export const x = 10;"],"root":[2],"version":"FakeTSVersion"}
8181

8282

8383
/home/src/tslibs/TS/Lib/tsc.js -i

0 commit comments

Comments
 (0)