Skip to content

Commit

Permalink
Sanitize version string for syntactically invalid buildinfo baselines (
Browse files Browse the repository at this point in the history
  • Loading branch information
weswigham authored Sep 10, 2024
1 parent 48f0b3c commit 0d7763e
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 5 deletions.
10 changes: 8 additions & 2 deletions src/testRunner/unittests/tsbuild/sample.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import { Baseline } from "../../_namespaces/Harness.js";
import * as ts from "../../_namespaces/ts.js";
import { jsonToReadableText } from "../helpers.js";
import { patchHostForBuildInfoReadWrite } from "../helpers/baseline.js";
import {
fakeTsVersion,
patchHostForBuildInfoReadWrite,
} from "../helpers/baseline.js";
import { getTypeScriptLibTestLocation } from "../helpers/contents.js";
import {
getSysForSampleProjectReferences,
Expand Down Expand Up @@ -198,7 +201,10 @@ describe("unittests:: tsbuild:: on 'sample1' project", () => {
commandLineArgs: ["--b", "-i", "-v"],
edits: [{
caption: "tsbuildinfo written has error",
edit: sys => sys.prependFile("/home/src/workspaces/project/tsconfig.tsbuildinfo", "Some random string"),
edit: sys => {
sys.prependFile("/home/src/workspaces/project/tsconfig.tsbuildinfo", "Some random string");
sys.replaceFileText("/home/src/workspaces/project/tsconfig.tsbuildinfo", `"version":"${ts.version}"`, `"version":"${fakeTsVersion}"`); // build info won't parse, need to manually sterilize for baseline
},
}],
});

Expand Down
6 changes: 5 additions & 1 deletion src/testRunner/unittests/tsc/incremental.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import * as ts from "../../_namespaces/ts.js";
import { dedent } from "../../_namespaces/Utils.js";
import { jsonToReadableText } from "../helpers.js";
import { fakeTsVersion } from "../helpers/baseline.js";
import { compilerOptionsToConfigJson } from "../helpers/contents.js";
import {
noChangeOnlyRuns,
Expand Down Expand Up @@ -100,7 +101,10 @@ describe("unittests:: tsc:: incremental::", () => {
commandLineArgs: ["-i"],
edits: [{
caption: "tsbuildinfo written has error",
edit: sys => sys.prependFile("/home/src/workspaces/project/tsconfig.tsbuildinfo", "Some random string"),
edit: sys => {
sys.prependFile("/home/src/workspaces/project/tsconfig.tsbuildinfo", "Some random string");
sys.replaceFileText("/home/src/workspaces/project/tsconfig.tsbuildinfo", `"version":"${ts.version}"`, `"version":"${fakeTsVersion}"`); // build info won't parse, need to manually sterilize for baseline
},
}],
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ Change:: tsbuildinfo written has error

Input::
//// [/home/src/workspaces/project/tsconfig.tsbuildinfo]
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"}
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"}


/home/src/tslibs/TS/Lib/tsc.js --b -i -v
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ Change:: tsbuildinfo written has error

Input::
//// [/home/src/workspaces/project/tsconfig.tsbuildinfo]
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"}
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"}


/home/src/tslibs/TS/Lib/tsc.js -i
Expand Down

0 comments on commit 0d7763e

Please sign in to comment.