Skip to content

Commit 3057a3b

Browse files
authored
chore: Improve external parser tests (#14911)
* improve runner * update allowlist * review
1 parent 4b3f619 commit 3057a3b

5 files changed

Lines changed: 80 additions & 23 deletions

File tree

Makefile

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,8 @@ test-ci-coverage:
150150
bootstrap-flow:
151151
rm -rf build/flow
152152
mkdir -p build
153-
git clone --single-branch --shallow-since=2021-05-01 https://github.com/facebook/flow.git build/flow
153+
git clone --filter=blob:none --sparse --single-branch --shallow-since=2021-05-01 https://github.com/facebook/flow.git build/flow
154+
cd build/flow && git sparse-checkout set "src/parser/test/flow"
154155
cd build/flow && git checkout -q $(FLOW_COMMIT)
155156

156157
test-flow:
@@ -162,7 +163,8 @@ test-flow-update-allowlist:
162163
bootstrap-typescript:
163164
rm -rf ./build/typescript
164165
mkdir -p ./build
165-
git clone --single-branch --shallow-since=2022-04-01 https://github.com/microsoft/TypeScript.git ./build/typescript
166+
git clone --filter=blob:none --sparse --single-branch --shallow-since=2022-04-01 https://github.com/microsoft/TypeScript.git ./build/typescript
167+
cd build/typescript && git sparse-checkout set "tests"
166168
cd build/typescript && git checkout -q $(TYPESCRIPT_COMMIT)
167169

168170
test-typescript:
@@ -174,7 +176,8 @@ test-typescript-update-allowlist:
174176
bootstrap-test262:
175177
rm -rf build/test262
176178
mkdir -p build
177-
git clone --single-branch --shallow-since=2021-05-01 https://github.com/tc39/test262.git build/test262
179+
git clone --filter=blob:none --sparse --single-branch --shallow-since=2021-05-01 https://github.com/tc39/test262.git build/test262
180+
cd build/test262 && git sparse-checkout set "test"
178181
cd build/test262 && git checkout -q $(TEST262_COMMIT)
179182

180183
test-test262:
Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
1-
language/expressions/class/decorator/syntax/class-valid/decorator-member-expr-private-identifier.js(default)
2-
language/expressions/class/decorator/syntax/class-valid/decorator-member-expr-private-identifier.js(strict mode)
1+
# 2 invalid programs did not produce a parsing error
2+
33
language/import/json-invalid.js(default)
44
language/import/json-invalid.js(strict mode)
5+
6+
7+
# 4 valid programs produced a parsing error
8+
9+
language/expressions/class/decorator/syntax/class-valid/decorator-member-expr-private-identifier.js(default)
10+
language/expressions/class/decorator/syntax/class-valid/decorator-member-expr-private-identifier.js(strict mode)
511
language/statements/class/decorator/syntax/class-valid/decorator-member-expr-private-identifier.js(default)
612
language/statements/class/decorator/syntax/class-valid/decorator-member-expr-private-identifier.js(strict mode)

scripts/parser-tests/test262/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ function* getPlugins(features) {
167167
}
168168

169169
const runner = new TestRunner({
170-
testDir: path.join(dirname, "../../../build/test262"),
170+
testDir: path.join(dirname, "../../../build/test262").replace(/\\/g, "/"),
171171
allowlist: path.join(dirname, "allowlist.txt"),
172172
logInterval: 500,
173173
shouldUpdate: process.argv.includes("--update-allowlist"),
@@ -179,7 +179,7 @@ const runner = new TestRunner({
179179

180180
for await (const test of stream) {
181181
// strip test/
182-
const fileName = test.file.slice(5);
182+
const fileName = test.file.slice(5).replace(/\\/g, "/");
183183

184184
if (ignoredTests.some(start => fileName.startsWith(start))) continue;
185185

scripts/parser-tests/typescript/allowlist.txt

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,18 @@
1+
# 9 invalid programs did not produce a parsing error
2+
3+
bigintIndex.ts
4+
classExpressionWithDecorator1.ts
5+
collisionArgumentsArrowFunctions.ts # TypeScript doesn't allow a parameter to be named arguments even in non-strict mode, which we don't catch.
6+
collisionArgumentsFunction.ts # TypeScript doesn't allow a parameter to be named arguments even in non-strict mode, which we don't catch.
7+
collisionArgumentsFunctionExpressions.ts # TypeScript doesn't allow a parameter to be named arguments even in non-strict mode, which we don't catch.
8+
dynamicImportTrailingComma.ts
9+
es3-oldStyleOctalLiteralInEnums.ts # We don't support ES3-style octal literal errors.
10+
exportDeclarationsInAmbientNamespaces2.ts
11+
multipleExports.ts
12+
13+
14+
# 143 valid programs produced a parsing error
15+
116
ArrowFunctionExpression1.ts
217
MemberAccessorDeclaration15.ts
318
ParameterList13.ts
@@ -17,15 +32,10 @@ augmentedTypesEnum2.ts
1732
augmentedTypesFunction.ts
1833
augmentedTypesInterface.ts
1934
augmentedTypesVar.ts
20-
bigintIndex.ts
2135
classCannotExtendVar.ts
22-
classExpressionWithDecorator1.ts
2336
classExtendsMultipleBaseClasses.ts
2437
classOverloadForFunction.ts
2538
classWithEmptyTypeParameter.ts
26-
collisionArgumentsArrowFunctions.ts # TypeScript doesn't allow a parameter to be named arguments even in non-strict mode, which we don't catch.
27-
collisionArgumentsFunction.ts # TypeScript doesn't allow a parameter to be named arguments even in non-strict mode, which we don't catch.
28-
collisionArgumentsFunctionExpressions.ts # TypeScript doesn't allow a parameter to be named arguments even in non-strict mode, which we don't catch.
2939
constDeclarations-invalidContexts.ts
3040
constDeclarations-scopes.ts
3141
constDeclarations-validContexts.ts
@@ -49,12 +59,10 @@ duplicateLabel2.ts
4959
duplicatePackage_withErrors.ts
5060
duplicateVarAndImport.ts
5161
duplicateVarAndImport2.ts
52-
dynamicImportTrailingComma.ts
5362
emptyGenericParamList.ts
5463
emptyTypeArgumentList.ts
5564
emptyTypeArgumentListWithNew.ts
5665
enumGenericTypeClash.ts
57-
es3-oldStyleOctalLiteralInEnums.ts # We don't support ES3-style octal literal errors.
5866
es3-oldStyleOctalLiteralTypes.ts
5967
es6ImportDefaultBindingFollowedWithNamedImport1InEs5.ts
6068
es6ImportDefaultBindingMergeErrors.ts
@@ -67,7 +75,6 @@ exportAssignmentWithDeclareModifier.ts
6775
exportAssignmentWithExportModifier.ts
6876
exportClassWithoutName.ts
6977
exportDeclarationsInAmbientNamespaces.ts
70-
exportDeclarationsInAmbientNamespaces2.ts
7178
exportDefaultAsyncFunction2.ts
7279
exportEqualsOfModule.ts
7380
exportInterfaceClassAndValue.ts
@@ -124,7 +131,6 @@ moduleDuplicateIdentifiers.ts
124131
moduleSharesNameWithImportDeclarationInsideIt3.ts
125132
moduleSharesNameWithImportDeclarationInsideIt5.ts
126133
multipleClassPropertyModifiersErrors.ts
127-
multipleExports.ts
128134
multipleInheritance.ts
129135
nameCollisions.ts
130136
noImplicitAnyDestructuringVarDeclaration.ts

scripts/parser-tests/utils/parser-test-runner.js

Lines changed: 49 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ class TestRunner {
5050
test.actualError = false;
5151
} catch (err) {
5252
test.actualError = true;
53+
test.actualErrorObject = err;
5354
}
5455

5556
test.result = test.expectedError !== test.actualError ? "fail" : "pass";
@@ -85,20 +86,61 @@ class TestRunner {
8586
.map(test => test.id)
8687
.concat(summary.unrecognized);
8788

88-
const updated = summary.disallowed.falsePositive
89-
.concat(summary.disallowed.falseNegative)
90-
.map(test => test.id);
89+
const allowedFalsePositiveIds = summary.allowed.falsePositive.map(
90+
test => test.id
91+
);
92+
93+
let invalidWithoutError = [];
94+
let validWithError = [];
9195

9296
for (const line of contents.split("\n")) {
9397
const testId = line.replace(/#.*$/, "").trim();
94-
if (!toRemove.includes(testId) && line) {
95-
updated.push(line);
98+
if (testId && !toRemove.includes(testId)) {
99+
if (allowedFalsePositiveIds.includes(testId)) {
100+
invalidWithoutError.push(line);
101+
} else {
102+
validWithError.push(line);
103+
}
96104
}
97105
}
98106

99-
updated.sort();
107+
invalidWithoutError = invalidWithoutError.concat(
108+
summary.disallowed.falsePositive.map(test => test.id)
109+
);
110+
validWithError = validWithError.concat(
111+
summary.disallowed.falseNegative.map(test => test.id)
112+
);
113+
114+
invalidWithoutError.sort();
115+
validWithError.sort();
116+
117+
const errorsMap = new Map();
118+
summary.allowed.falseNegative
119+
.concat(summary.disallowed.falseNegative)
120+
.forEach(test => {
121+
errorsMap.set(test.id, test.actualErrorObject);
122+
});
123+
124+
const updated = [
125+
`# ${invalidWithoutError.length} invalid programs did not produce a parsing error\n`,
126+
"\n",
127+
invalidWithoutError.join("\n"),
128+
"\n",
129+
"\n",
130+
"\n",
131+
`# ${validWithError.length} valid programs produced a parsing error\n`,
132+
"\n",
133+
...validWithError
134+
// .map(
135+
// v =>
136+
// `${v}\n# ${JSON.stringify(errorsMap.get(v), null, 2)
137+
// .trimEnd()
138+
// .replace(/\n/g, "\n#")}\n`
139+
// )
140+
.join("\n"),
141+
];
100142

101-
await fs.writeFile(this.allowlist, updated.join("\n") + "\n", "utf8");
143+
await fs.writeFile(this.allowlist, updated.join("") + "\n", "utf8");
102144
}
103145

104146
interpret(results, allowlist) {

0 commit comments

Comments
 (0)