Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit06abb77

Browse files
authored
Usego test -json in updateFailing, detect baseline errors (#2347)
1 parent20bf4fc commit06abb77

File tree

2 files changed

+114
-24
lines changed

2 files changed

+114
-24
lines changed

‎.github/workflows/ci.yml‎

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -264,12 +264,8 @@ jobs:
264264
-name:Regenerate fourslash tests and update failing test list
265265
run:|
266266
set -x
267-
echo "" > ./internal/fourslash/_scripts/failingTests.txt
268267
npm run convertfourslash >/dev/null 2>&1 ||true
269-
npx hereby test >/dev/null ||true
270-
npx hereby baseline-accept ||true
271268
npm run updatefailing >/dev/null 2>&1 ||true
272-
npx hereby baseline-accept ||true
273269
rm -rf testdata/baselines/reference/fourslash ||true
274270
npx hereby test >/dev/null ||true
275271
npx hereby baseline-accept ||true
Lines changed: 114 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,137 @@
11
import*ascpfrom"child_process";
22
import*asfsfrom"fs";
33
importpathfrom"path";
4+
import*asreadlinefrom"readline";
45
importwhichfrom"which";
56

67
constfailingTestsPath=path.join(import.meta.dirname,"failingTests.txt");
78
constcrashingTestsPath=path.join(import.meta.dirname,"crashingTests.txt");
89

9-
functionmain(){
10+
interfaceTestEvent{
11+
Time?:string;
12+
Action:string;
13+
Package?:string;
14+
Test?:string;
15+
Output?:string;
16+
Elapsed?:number;
17+
}
18+
19+
asyncfunctionmain(){
1020
constgo=which.sync("go");
11-
lettestOutput:string;
21+
22+
lettestProcess:cp.ChildProcess;
1223
try{
1324
// Run tests with TSGO_FOURSLASH_IGNORE_FAILING=1 to run all tests including those in failingTests.txt
14-
testOutput=cp.execFileSync(go,["test","-v","./internal/fourslash/tests/gen"],{
15-
encoding:"utf-8",
25+
testProcess=cp.spawn(go,["test","-json","./internal/fourslash/tests/gen"],{
26+
stdio:["ignore","pipe","pipe"],
1627
env:{ ...process.env,TSGO_FOURSLASH_IGNORE_FAILING:"1"},
1728
});
1829
}
1930
catch(error){
20-
testOutput=(erroras{stdout:string;}).stdoutasstring;
31+
thrownewError("Failed to spawn test process: "+error);
2132
}
22-
constpanicRegex=/^panic/m;
23-
if(panicRegex.test(testOutput)){
24-
thrownewError("Unrecovered panic detected in tests\n"+testOutput);
33+
34+
if(!testProcess.stdout||!testProcess.stderr){
35+
thrownewError("Test process stdout or stderr is null");
2536
}
26-
constfailRegex=/---FAIL:([\S]+)/gm;
37+
2738
constfailingTests:string[]=[];
28-
constcrashingRegex=/^===(?:NAME|CONT)([\S]+)\n.*InternalError.*$/gm;
2939
constcrashingTests:string[]=[];
30-
letmatch;
40+
consttestOutputs=newMap<string,string[]>();
41+
constallOutputs:string[]=[];
42+
lethadPanic=false;
3143

32-
while((match=failRegex.exec(testOutput))!==null){
33-
failingTests.push(match[1]);
34-
}
35-
while((match=crashingRegex.exec(testOutput))!==null){
36-
crashingTests.push(match[1]);
37-
}
44+
constrl=readline.createInterface({
45+
input:testProcess.stdout,
46+
crlfDelay:Infinity,
47+
});
48+
49+
rl.on("line",line=>{
50+
try{
51+
constevent:TestEvent=JSON.parse(line);
52+
53+
// Collect output for each test
54+
if(event.Action==="output"&&event.Output){
55+
allOutputs.push(event.Output);
56+
if(event.Test){
57+
if(!testOutputs.has(event.Test)){
58+
testOutputs.set(event.Test,[]);
59+
}
60+
testOutputs.get(event.Test)!.push(event.Output);
61+
}
62+
63+
// Check for panics
64+
if(/^panic/m.test(event.Output)){
65+
hadPanic=true;
66+
}
67+
}
68+
69+
// Process failed tests
70+
if(event.Action==="fail"&&event.Test){
71+
constoutputs=testOutputs.get(event.Test)||[];
3872

39-
fs.writeFileSync(failingTestsPath,failingTests.sort((a,b)=>a.localeCompare(b,"en-US")).join("\n")+"\n","utf-8");
40-
fs.writeFileSync(crashingTestsPath,crashingTests.sort((a,b)=>a.localeCompare(b,"en-US")).join("\n")+"\n","utf-8");
73+
// Check if this is a crashing test (contains InternalError)
74+
consthasCrash=outputs.some(line=>line.includes("InternalError"));
75+
if(hasCrash){
76+
crashingTests.push(event.Test);
77+
}
78+
79+
// A test is only considered a baseline-only failure if ALL error messages
80+
// are baseline-related. Any non-baseline error message means it's a real failure.
81+
constbaselineMessagePatterns=[
82+
/^\s*baseline\.go:\d+:thebaselinefile.*haschanged\./,
83+
/^\s*baseline\.go:\d+:newbaselinecreatedat/,
84+
/^\s*baseline\.go:\d+:thebaselinefile.*doesnotexistintheTypeScriptsubmodule/,
85+
/^\s*baseline\.go:\d+:thebaselinefile.*doesnotmatchthereferenceintheTypeScriptsubmodule/,
86+
];
87+
88+
// Check each output line that looks like an error message
89+
// Error messages from Go tests typically contain ".go:" with a line number
90+
consterrorLines=outputs.filter(line=>/^\s*\w+\.go:\d+:/.test(line));
91+
92+
// If there are no error lines, it's a real failure.
93+
// If all error lines match baseline patterns, it's a baseline-only failure
94+
constisBaselineOnlyFailure=errorLines.length>0&&
95+
errorLines.every(line=>baselineMessagePatterns.some(pattern=>pattern.test(line)));
96+
97+
if(!isBaselineOnlyFailure){
98+
failingTests.push(event.Test);
99+
}
100+
}
101+
}
102+
catch(e){
103+
// Not JSON, possibly stderr or other output - ignore
104+
}
105+
});
106+
107+
testProcess.stderr.on("data",data=>{
108+
// Check stderr for panics too
109+
constoutput=data.toString();
110+
allOutputs.push(output);
111+
if(/^panic/m.test(output)){
112+
hadPanic=true;
113+
}
114+
});
115+
116+
awaitnewPromise<void>((resolve,reject)=>{
117+
testProcess.on("close",code=>{
118+
if(hadPanic){
119+
reject(newError("Unrecovered panic detected in tests\n"+allOutputs.join("")));
120+
return;
121+
}
122+
123+
fs.writeFileSync(failingTestsPath,failingTests.sort((a,b)=>a.localeCompare(b,"en-US")).join("\n")+"\n","utf-8");
124+
fs.writeFileSync(crashingTestsPath,crashingTests.sort((a,b)=>a.localeCompare(b,"en-US")).join("\n")+"\n","utf-8");
125+
resolve();
126+
});
127+
128+
testProcess.on("error",error=>{
129+
reject(error);
130+
});
131+
});
41132
}
42133

43-
main();
134+
main().catch(error=>{
135+
console.error("Error:",error);
136+
process.exit(1);
137+
});

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp