-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdebugTracker.ts
More file actions
204 lines (185 loc) · 8.17 KB
/
debugTracker.ts
File metadata and controls
204 lines (185 loc) · 8.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
import * as vscode from 'vscode';
import { allTestRuns, loadedTestController, localTestController, OurTestRun } from './extension';
import { refreshHistoryRootItem } from './historyExplorer';
import { processCoverage } from './coverage';
export class DebugTracker implements vscode.DebugAdapterTracker {
private session: vscode.DebugSession;
private serverName: string;
private namespace: string;
private testController: vscode.TestController
private run?: OurTestRun;
private testingIdBase: string;
private className?: string;
private testMethodName?: string;
private testDuration?: number;
private methodTestMap: Map<string, vscode.TestItem>;
private methodTest?: vscode.TestItem;
private failureMessages: vscode.TestMessage[] = [];
private skippedMessages: vscode.TestMessage[] = [];
constructor(session: vscode.DebugSession) {
this.session = session;
let runType: string;
[ runType, this.serverName, this.namespace ] = this.session.configuration.name.split(':');
this.testController = runType === 'LoadedTests' ? loadedTestController : localTestController;
this.run = allTestRuns[this.session.configuration.testingRunIndex];
if (this.run) {
this.run.debugSession = session;
};
this.testingIdBase = this.session.configuration.testingIdBase;
this.methodTestMap = new Map<string, vscode.TestItem>();
const addToMethodTestMap = (testItem?: vscode.TestItem) => {
if (!testItem) {
return;
}
if (testItem.children.size > 0) {
testItem.children.forEach(addToMethodTestMap);
} else {
this.methodTestMap.set(testItem.id, testItem);
}
}
if (runType === 'LoadedTests') {
// This tree is flat
addToMethodTestMap(this.testController.items.get(this.testingIdBase));
} else {
// This tree is nested
addToMethodTestMap(this.testController.items.get(this.testingIdBase + ':'));
}
}
onDidSendMessage(message: any): void {
if (message.type === 'event' && message.event === 'output' && message.body?.category === 'stdout') {
if (!this.run) {
return;
}
const line: string = (message.body.output as string).replace(/\n/, '');
this.run.appendOutput(line + '\r\n');
const coverageMatch = line.match(/^(?:http|https):\/\/.*\/TestCoverage\.UI\.AggregateResultViewer\.cls\?Index=(\d+)/);
if (coverageMatch && this.run.debugSession) {
const coverageIndex = Number(coverageMatch[1]);
this.run.debugSession.configuration.coverageIndex = coverageIndex;
//console.log(`Coverage index set to ${coverageIndex}`);
}
if (this.className === undefined) {
const classBegin = line.match(/^ ([%\dA-Za-z][\dA-Za-z0-9\.]*) begins \.\.\./);
if (classBegin) {
this.className = classBegin[1];
}
return;
}
if (line.startsWith(` ${this.className} `)) {
this.className = undefined;
return;
}
if (this.testMethodName === undefined) {
const methodBegin = line.match(/^ Test([\dA-Za-z0-9]+).* begins \.\.\./);
if (methodBegin) {
this.testMethodName = methodBegin[1];
this.methodTest = this.methodTestMap.get(`${this.testingIdBase}:${this.className}:Test${this.testMethodName}`);
this.failureMessages = [];
if (this.methodTest) {
this.run.started(this.methodTest)
}
return;
}
} else {
if (line.startsWith(` Test${this.testMethodName} `)) {
const outcome = line.split(this.testMethodName + ' ')[1];
//console.log(`Class ${this.className}, Test-method ${this.testMethodName}, outcome=${outcome}`);
if (this.methodTest) {
switch (outcome) {
case 'passed':
this.run.passed(this.methodTest, this.testDuration)
break;
case 'skipped':
// Pending https://github.com/microsoft/vscode/issues/133198 we can't do anything with this.skippedMessages
this.run.skipped(this.methodTest);
break;
case 'failed':
if (this.failureMessages.length > 0) {
this.run.failed(this.methodTest, this.failureMessages, this.testDuration);
} else {
this.run.failed(this.methodTest, { message: 'Failed with no messages' }, this.testDuration);
}
break;
default:
break;
}
}
this.testMethodName = undefined;
this.testDuration = undefined;
this.methodTest = undefined;
this.failureMessages = [];
this.skippedMessages = [];
return;
}
}
if (this.className && this.testMethodName) {
const assertPassedMatch = line.match(/^ (Assert\w+):(.*) \(passed\)$/);
if (assertPassedMatch) {
//const macroName = assertPassedMatch[1];
//const message = assertPassedMatch[2];
//console.log(`Class ${this.className}, Test-method ${this.testMethodName}, macroName ${macroName}, outcome 'passed', message=${message}`);
} else {
const assertFailedMatch = line.match(/^(Assert\w+):(.*) \(failed\)@\+(\d+)\^(.*) <<====/);
if (assertFailedMatch) {
//const macroName = assertFailedMatch[1];
const message = assertFailedMatch[2];
const offset = Number(assertFailedMatch[3]);
const location = this.methodTest?.uri && this.methodTest.range
? new vscode.Location(this.methodTest.uri, new vscode.Position(offset, 0))
: undefined;
this.failureMessages.push({ message, location });
} else {
const assertSkippedMatch = line.match(/^ (Test\w+):(.*) \(skipped\)@\+(\d+)\^(.*)$/);
if (assertSkippedMatch) {
//const macroName = assertSkippedMatch[1];
const message = assertSkippedMatch[2];
const offset = Number(assertSkippedMatch[3]);
const location = this.methodTest?.uri && this.methodTest.range
? new vscode.Location(this.methodTest.uri, new vscode.Position(offset, 0))
: undefined;
this.skippedMessages.push({ message, location });
} else {
const logMessageMatch = line.match(/^ LogMessage:(.*)$/);
if (logMessageMatch) {
const message = logMessageMatch[1];
//console.log(`Class ${this.className}, Test-method ${this.testMethodName}, macroName LogMessage, message=${message}`);
const duration = message.match(/^Duration of execution: (\d*\.\d+) sec.$/);
if (duration) {
this.testDuration = + duration[1] * 1000;
}
} else {
const logStateStatusMatch = line.match(/^LogStateStatus:(.*)$/);
if (logStateStatusMatch) {
const message = logStateStatusMatch[1];
//console.log(`Class ${this.className}, Test-method ${this.testMethodName}, macroName LogStateStatus, message=${message}`);
this.failureMessages.push({ message });
}
}
}
}
}
}
}
}
onWillStartSession(): void {
//console.log(`**Starting session ${this.session.name}, run.name = ${this.run?.name}`);
}
async onWillStopSession(): Promise<void> {
console.log(`**Stopping session ${this.session.name}`);
if (this.run) {
await processCoverage(this.serverName, this.namespace, this.run);
//console.log(`**processCoverage done`);
this.run.end();
//console.log(`**run.end() done`);
refreshHistoryRootItem(this.serverName, this.namespace);
}
// Clear run record (may not be necessary, but is harmless)
allTestRuns[this.session.configuration.testingRunIndex] = undefined;
}
onError(error: Error): void {
//console.log(`**Erroring session ${this.session.name}: error.message=${error.message}`);
}
onExit(code: number | undefined, signal: string | undefined): void {
//console.log(`**Exiting session ${this.session.name}: code=${code}, signal=${signal}`);
}
}