Skip to content

Commit 2fe47a5

Browse files
authored
Add script to update list of failing generated fourslash tests (#1361)
1 parent 76d4e43 commit 2fe47a5

File tree

5 files changed

+64
-45
lines changed

5 files changed

+64
-45
lines changed

internal/fourslash/_scripts/convertFourslash.mts

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,26 @@ import * as cp from "child_process";
22
import * as fs from "fs";
33
import * as path from "path";
44
import * as ts from "typescript";
5+
import * as url from "url";
56
import which from "which";
67

78
const stradaFourslashPath = path.resolve(import.meta.dirname, "../", "../", "../", "_submodules", "TypeScript", "tests", "cases", "fourslash");
89

910
let inputFileSet: Set<string> | undefined;
1011

1112
const failingTestsPath = path.join(import.meta.dirname, "failingTests.txt");
12-
const failingTestsList = fs.readFileSync(failingTestsPath, "utf-8").split("\n").map(line => line.trim().substring(4)).filter(line => line.length > 0);
13-
const failingTests = new Set(failingTestsList);
1413
const helperFilePath = path.join(import.meta.dirname, "../", "tests", "util_test.go");
1514

1615
const outputDir = path.join(import.meta.dirname, "../", "tests", "gen");
1716

1817
const unparsedFiles: string[] = [];
1918

20-
function main() {
19+
function getFailingTests(): Set<string> {
20+
const failingTestsList = fs.readFileSync(failingTestsPath, "utf-8").split("\n").map(line => line.trim().substring(4)).filter(line => line.length > 0);
21+
return new Set(failingTestsList);
22+
}
23+
24+
export function main() {
2125
const args = process.argv.slice(2);
2226
const inputFilesPath = args[0];
2327
if (inputFilesPath) {
@@ -28,18 +32,17 @@ function main() {
2832
inputFileSet = new Set(inputFiles);
2933
}
3034

31-
if (!fs.existsSync(outputDir)) {
32-
fs.mkdirSync(outputDir, { recursive: true });
33-
}
35+
fs.rmSync(outputDir, { recursive: true, force: true });
36+
fs.mkdirSync(outputDir, { recursive: true });
3437

3538
generateHelperFile();
36-
parseTypeScriptFiles(stradaFourslashPath);
39+
parseTypeScriptFiles(getFailingTests(), stradaFourslashPath);
3740
console.log(unparsedFiles.join("\n"));
3841
const gofmt = which.sync("go");
3942
cp.execFileSync(gofmt, ["tool", "mvdan.cc/gofumpt", "-lang=go1.24", "-w", outputDir]);
4043
}
4144

42-
function parseTypeScriptFiles(folder: string): void {
45+
function parseTypeScriptFiles(failingTests: Set<string>, folder: string): void {
4346
const files = fs.readdirSync(folder);
4447

4548
files.forEach(file => {
@@ -50,13 +53,13 @@ function parseTypeScriptFiles(folder: string): void {
5053
}
5154

5255
if (stat.isDirectory()) {
53-
parseTypeScriptFiles(filePath);
56+
parseTypeScriptFiles(failingTests, filePath);
5457
}
5558
else if (file.endsWith(".ts")) {
5659
const content = fs.readFileSync(filePath, "utf-8");
5760
const test = parseFileContent(file, content);
5861
if (test) {
59-
const testContent = generateGoTest(test);
62+
const testContent = generateGoTest(failingTests, test);
6063
const testPath = path.join(outputDir, `${test.name}_test.go`);
6164
fs.writeFileSync(testPath, testContent, "utf-8");
6265
}
@@ -791,7 +794,7 @@ interface GoTest {
791794
commands: Cmd[];
792795
}
793796

794-
function generateGoTest(test: GoTest): string {
797+
function generateGoTest(failingTests: Set<string>, test: GoTest): string {
795798
const testName = test.name[0].toUpperCase() + test.name.substring(1);
796799
const content = test.content;
797800
const commands = test.commands.map(cmd => generateCmd(cmd)).join("\n");
@@ -827,4 +830,6 @@ function generateHelperFile() {
827830
fs.copyFileSync(helperFilePath, path.join(outputDir, "util_test.go"));
828831
}
829832

830-
main();
833+
if (url.fileURLToPath(import.meta.url) == process.argv[1]) {
834+
main();
835+
}

internal/fourslash/_scripts/failingTests.txt

Lines changed: 11 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,6 @@ TestCompletionEntryForClassMembers_StaticWhenBaseTypeIsNotResolved
99
TestCompletionExportFrom
1010
TestCompletionForComputedStringProperties
1111
TestCompletionForStringLiteral
12-
TestCompletionForStringLiteral_quotePreference
13-
TestCompletionForStringLiteral_quotePreference1
14-
TestCompletionForStringLiteral_quotePreference2
15-
TestCompletionForStringLiteral_quotePreference3
16-
TestCompletionForStringLiteral_quotePreference4
17-
TestCompletionForStringLiteral_quotePreference5
18-
TestCompletionForStringLiteral_quotePreference6
1912
TestCompletionForStringLiteral12
2013
TestCompletionForStringLiteral15
2114
TestCompletionForStringLiteral2
@@ -60,9 +53,9 @@ TestCompletionImportModuleSpecifierEndingTs
6053
TestCompletionImportModuleSpecifierEndingTsxPreserve
6154
TestCompletionImportModuleSpecifierEndingTsxReact
6255
TestCompletionImportModuleSpecifierEndingUnsupportedExtension
63-
TestCompletionInfoWithExplicitTypeArguments
6456
TestCompletionInFunctionLikeBody_includesPrimitiveTypes
6557
TestCompletionInJsDoc
58+
TestCompletionInfoWithExplicitTypeArguments
6659
TestCompletionListAndMemberListOnCommentedDot
6760
TestCompletionListAndMemberListOnCommentedLine
6861
TestCompletionListAndMemberListOnCommentedWhiteSpace
@@ -95,23 +88,24 @@ TestCompletionListInUnclosedTaggedTemplate01
9588
TestCompletionListInUnclosedTaggedTemplate02
9689
TestCompletionListInUnclosedTemplate01
9790
TestCompletionListInUnclosedTemplate02
98-
TestCompletionListInvalidMemberNames_withExistingIdentifier
9991
TestCompletionListInvalidMemberNames2
92+
TestCompletionListInvalidMemberNames_withExistingIdentifier
10093
TestCompletionListOnAliases2
10194
TestCompletionListPrivateNames
10295
TestCompletionListPrivateNamesAccessors
10396
TestCompletionListPrivateNamesMethods
104-
TestCompletionListsStringLiteralTypeAsIndexedAccessTypeObject
10597
TestCompletionListStaticMembers
10698
TestCompletionListStaticProtectedMembers
10799
TestCompletionListStaticProtectedMembers2
108100
TestCompletionListStaticProtectedMembers3
109101
TestCompletionListStringParenthesizedExpression
110102
TestCompletionListStringParenthesizedType
111103
TestCompletionListWithoutVariableinitializer
104+
TestCompletionListsStringLiteralTypeAsIndexedAccessTypeObject
112105
TestCompletionNoAutoInsertQuestionDotWithUserPreferencesOff
113106
TestCompletionOfAwaitPromise6
114107
TestCompletionPreferredSuggestions1
108+
TestCompletionWithConditionalOperatorMissingColon
115109
TestCompletionsAfterJSDoc
116110
TestCompletionsBeforeRestArg1
117111
TestCompletionsECMAPrivateMemberTriggerCharacter
@@ -123,9 +117,9 @@ TestCompletionsJSDocImportTagAttributesErrorModuleSpecifier1
123117
TestCompletionsJSDocImportTagEmptyModuleSpecifier1
124118
TestCompletionsJSDocNoCrash1
125119
TestCompletionsJSDocNoCrash2
120+
TestCompletionsJsPropertyAssignment
126121
TestCompletionsJsdocParamTypeBeforeName
127122
TestCompletionsJsdocTypeTagCast
128-
TestCompletionsJsPropertyAssignment
129123
TestCompletionsJsxAttribute2
130124
TestCompletionsKeyof
131125
TestCompletionsLiteralFromInferenceWithinInferredType3
@@ -143,13 +137,13 @@ TestCompletionsOverridingMethod4
143137
TestCompletionsOverridingMethod9
144138
TestCompletionsOverridingMethodCrash1
145139
TestCompletionsOverridingProperties1
140+
TestCompletionsPathsJsonModule
141+
TestCompletionsPathsRelativeJsonModule
146142
TestCompletionsPaths_importType
147143
TestCompletionsPaths_kinds
148144
TestCompletionsPaths_pathMapping
149145
TestCompletionsPaths_pathMapping_nonTrailingWildcard1
150146
TestCompletionsPaths_pathMapping_parentDirectory
151-
TestCompletionsPathsJsonModule
152-
TestCompletionsPathsRelativeJsonModule
153147
TestCompletionsPropertiesPriorities
154148
TestCompletionsRecommended_union
155149
TestCompletionsRedeclareModuleAsGlobal
@@ -159,7 +153,6 @@ TestCompletionsSymbolMembers
159153
TestCompletionsTriggerCharacter
160154
TestCompletionsUniqueSymbol1
161155
TestCompletionsWithStringReplacementMode1
162-
TestCompletionWithConditionalOperatorMissingColon
163156
TestExportEqualCallableInterface
164157
TestGetJavaScriptCompletions1
165158
TestGetJavaScriptCompletions10
@@ -200,22 +193,9 @@ TestImportCompletions_importsMap2
200193
TestImportCompletions_importsMap3
201194
TestImportCompletions_importsMap4
202195
TestImportCompletions_importsMap5
203-
TestImportCompletionsPackageJsonExportsSpecifierEndsInTs
204-
TestImportCompletionsPackageJsonExportsTrailingSlash1
205-
TestImportCompletionsPackageJsonImports_ts
206-
TestImportCompletionsPackageJsonImportsConditions1
207-
TestImportCompletionsPackageJsonImportsLength1
208-
TestImportCompletionsPackageJsonImportsLength2
209-
TestImportCompletionsPackageJsonImportsPattern
210-
TestImportCompletionsPackageJsonImportsPattern_capsInPath1
211-
TestImportCompletionsPackageJsonImportsPattern_capsInPath2
212-
TestImportCompletionsPackageJsonImportsPattern_js_ts
213-
TestImportCompletionsPackageJsonImportsPattern_ts
214-
TestImportCompletionsPackageJsonImportsPattern_ts_ts
215-
TestImportCompletionsPackageJsonImportsPattern2
196+
TestImportStatementCompletions4
216197
TestImportStatementCompletions_noPatternAmbient
217198
TestImportStatementCompletions_pnpmTransitive
218-
TestImportStatementCompletions4
219199
TestImportTypeMemberCompletions
220200
TestJavaScriptClass4
221201
TestJavaScriptModules12
@@ -225,15 +205,15 @@ TestJavaScriptModules19
225205
TestJavascriptModules20
226206
TestJavascriptModules21
227207
TestJavascriptModulesTypeImport
228-
TestJsdocExtendsTagCompletion
229208
TestJsDocFunctionSignatures3
230209
TestJsDocGenerics1
210+
TestJsdocExtendsTagCompletion
231211
TestJsdocImplementsTagCompletion
232212
TestJsdocOverloadTagCompletion
233-
TestJsdocParameterNameCompletion
234213
TestJsdocParamTagSpecialKeywords
235-
TestJsdocPropertyTagCompletion
214+
TestJsdocParameterNameCompletion
236215
TestJsdocPropTagCompletion
216+
TestJsdocPropertyTagCompletion
237217
TestJsdocSatisfiesTagCompletion1
238218
TestJsdocTemplatePrototypeCompletions
239219
TestJsdocTemplateTagCompletion

internal/fourslash/_scripts/tsconfig.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
"compilerOptions": {
33
"strict": true,
44
"noEmit": true,
5-
"module": "nodenext"
5+
"module": "nodenext",
6+
"allowImportingTsExtensions": true
67
}
78
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import * as cp from "child_process";
2+
import * as fs from "fs";
3+
import path from "path";
4+
import which from "which";
5+
import { main as convertFourslash } from "./convertFourslash.mts";
6+
7+
const failingTestsPath = path.join(import.meta.dirname, "failingTests.txt");
8+
9+
function main() {
10+
fs.writeFileSync(failingTestsPath, "", "utf-8");
11+
convertFourslash();
12+
const go = which.sync("go");
13+
let testOutput: string;
14+
try {
15+
testOutput = cp.execFileSync(go, ["test", "./internal/fourslash/tests/gen"], { encoding: "utf-8" });
16+
}
17+
catch (error) {
18+
testOutput = (error as { stdout: string; }).stdout as string;
19+
}
20+
const regex = /--- FAIL: ([\S]+)/gm;
21+
const failingTests: string[] = [];
22+
let match;
23+
24+
while ((match = regex.exec(testOutput)) !== null) {
25+
failingTests.push(match[1]);
26+
}
27+
28+
fs.writeFileSync(failingTestsPath, failingTests.sort().join("\n") + "\n", "utf-8");
29+
convertFourslash();
30+
}
31+
32+
main();

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@
2828
"extension:build": "npm run -w _extension build",
2929
"extension:watch": "npm run -w _extension watch",
3030
"node": "node --no-warnings --conditions @typescript/source",
31-
"convertfourslash": "node --experimental-strip-types --no-warnings internal/fourslash/_scripts/convertFourslash.mts"
31+
"convertfourslash": "node --experimental-strip-types --no-warnings internal/fourslash/_scripts/convertFourslash.mts",
32+
"updatefailing": "node --experimental-strip-types --no-warnings internal/fourslash/_scripts/updateFailing.mts"
3233
},
3334
"workspaces": [
3435
"./_extension",

0 commit comments

Comments
 (0)