|
1 | 1 | import*ascpfrom"child_process"; |
2 | 2 | import*asfsfrom"fs"; |
3 | 3 | importpathfrom"path"; |
| 4 | +import*asreadlinefrom"readline"; |
4 | 5 | importwhichfrom"which"; |
5 | 6 |
|
6 | 7 | constfailingTestsPath=path.join(import.meta.dirname,"failingTests.txt"); |
7 | 8 | constcrashingTestsPath=path.join(import.meta.dirname,"crashingTests.txt"); |
8 | 9 |
|
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(){ |
10 | 20 | constgo=which.sync("go"); |
11 | | -lettestOutput:string; |
| 21 | + |
| 22 | +lettestProcess:cp.ChildProcess; |
12 | 23 | try{ |
13 | 24 | // 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"], |
16 | 27 | env:{ ...process.env,TSGO_FOURSLASH_IGNORE_FAILING:"1"}, |
17 | 28 | }); |
18 | 29 | } |
19 | 30 | catch(error){ |
20 | | -testOutput=(erroras{stdout:string;}).stdoutasstring; |
| 31 | +thrownewError("Failed to spawn test process: "+error); |
21 | 32 | } |
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"); |
25 | 36 | } |
26 | | -constfailRegex=/---FAIL:([\S]+)/gm; |
| 37 | + |
27 | 38 | constfailingTests:string[]=[]; |
28 | | -constcrashingRegex=/^===(?:NAME|CONT)([\S]+)\n.*InternalError.*$/gm; |
29 | 39 | constcrashingTests:string[]=[]; |
30 | | -letmatch; |
| 40 | +consttestOutputs=newMap<string,string[]>(); |
| 41 | +constallOutputs:string[]=[]; |
| 42 | +lethadPanic=false; |
31 | 43 |
|
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)||[]; |
38 | 72 |
|
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 | +}); |
41 | 132 | } |
42 | 133 |
|
43 | | -main(); |
| 134 | +main().catch(error=>{ |
| 135 | +console.error("Error:",error); |
| 136 | +process.exit(1); |
| 137 | +}); |