Skip to content

Commit 45ca82f

Browse files
committed
Fix output analyzer
1 parent d0c7ac8 commit 45ca82f

File tree

1 file changed

+19
-9
lines changed

1 file changed

+19
-9
lines changed

editors/code/src/test_explorer/RustcOutputAnalyzer.ts

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ const targetPatternNamedCaptureGroup = {
2020

2121
// when target is lib/bin, there is "unittests ", when target is integration test, there is not
2222
const sepInRegexString = sep === '\\' ? '\\\\' : sep;
23-
const targetPattern = new RegExp(`Running (?:unittests )?(?<${targetPatternNamedCaptureGroup.relativePath}>.*?) \\(.*${sepInRegexString}(?<${targetPatternNamedCaptureGroup.normalizedPackageName}>.*?)-\\)`);
23+
const targetPattern = new RegExp(`Running (?:unittests )?(?<${targetPatternNamedCaptureGroup.relativePath}>.*?) \(.*${sepInRegexString}(?<${targetPatternNamedCaptureGroup.normalizedPackageName}>.*?)-.*?\)`);
2424

2525
const caseResultPattern = /^test (.*?) ... (\w*)$/;
2626
const stacktraceTestCasePattern = /^---- (.*?) stdout ----$/;
@@ -40,11 +40,21 @@ export class RustcOutputAnalyzer {
4040
}
4141

4242
public onStdErr(data: any) {
43-
// TODO: maybe testRun.error() might be helpful?
43+
// This is so weird, some messages will be logged as stderr
44+
// like "Finished test [unoptimized + debuginfo] target(s) in 0.07s"
45+
// and "Running unittests src\lib.rs (target\debug\deps\hashbrown-3547e1bc587fc63a.exe)"
46+
47+
// And this make ir hard to use breakpoint to debug, because the buffer will be flushed in unexpected order.
4448
const normalizedData = normalizeOutputData(data);
45-
normalizedData.split('\r\n');
4649

50+
this.testRun.appendOutput(normalizedData);
4751
console.log(`StdErr:${data}`);
52+
53+
const lines = normalizedData.split("\r\n");
54+
55+
lines.forEach(line => {
56+
this.analyticsCurrentTestTarget(line);
57+
});
4858
}
4959

5060
public onClose() {
@@ -60,12 +70,8 @@ export class RustcOutputAnalyzer {
6070
console.log(`Stdout:${data}`);
6171

6272
const lines = normalizedData.split("\r\n");
63-
// At the end of the output, when the tests are all finished
64-
// stack trace(if any failed) will be output together in a big `data`
65-
// set this flag to analytics all the output
6673

6774
lines.forEach(line => {
68-
this.analyticsCurrentTestTarget(line);
6975
this.analyticsTestCaseResult(line);
7076
this.analyticsStackTrace(line);
7177
});
@@ -75,7 +81,7 @@ export class RustcOutputAnalyzer {
7581
private _currentTargetRelativePath: string | undefined = undefined;
7682

7783
private analyticsCurrentTestTarget(line: string) {
78-
const match = targetPattern.exec(line);
84+
const match = targetPattern.exec(line); // Running unittests src\\lib.rs (target\\debug\\deps\\hashbrown-3547e1bc587fc63a.exe)
7985
if (match) {
8086
this._currentNormalizedPackageName = match?.groups?.[targetPatternNamedCaptureGroup.normalizedPackageName];
8187
this._currentTargetRelativePath = match?.groups?.[targetPatternNamedCaptureGroup.relativePath];
@@ -112,6 +118,10 @@ export class RustcOutputAnalyzer {
112118
}
113119
}
114120

121+
122+
// At the end of the output, when the tests are all finished
123+
// stack trace(if any failed) will be output together in a big `data`
124+
// set this flag to analytics all the output
115125
private _failureContextAnalyticsFlag = false;
116126
private _currentFailedRustcOutputTest: vscode.TestItem | undefined = undefined;
117127
private _currentFailedCaseOutputWithStackTrace: string[] = [];
@@ -152,7 +162,7 @@ export class RustcOutputAnalyzer {
152162

153163
// why replace: refer https://code.visualstudio.com/api/extension-guides/testing#test-output
154164
function normalizeOutputData(data: any): string {
155-
return data.toString().replace(/\n/g, '\r\n');
165+
return data.toString().replace(/\r\n/g, '\n').replace(/\n/g, '\r\n');
156166
}
157167

158168
enum RustcTestResult {

0 commit comments

Comments
 (0)