Skip to content

Commit d96dc45

Browse files
committed
test/integration/goDebug.test.ts: fix local variable assertion
The conditional breakpoint tests were failing because the wrong scope was being checked for the variable value. In the legacy adapter there was a single scope named "Local" but dlv-dap returns two scopes: "Arguments" and "Locals". This change now looks for the scope that matches either the name "Local" or "Locals" and uses that. Change-Id: If106701d74f19f95c9079fcd33a5f3e8f1c916b2 Reviewed-on: https://go-review.googlesource.com/c/vscode-go/+/295411 Trust: Suzy Mueller <[email protected]> Run-TryBot: Suzy Mueller <[email protected]> TryBot-Result: kokoro <[email protected]> Reviewed-by: Polina Sokolova <[email protected]>
1 parent 7f1e239 commit d96dc45

File tree

1 file changed

+19
-29
lines changed

1 file changed

+19
-29
lines changed

test/integration/goDebug.test.ts

Lines changed: 19 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -426,20 +426,22 @@ const testAll = (isDlvDap: boolean) => {
426426
* 3. scopesRequest
427427
* 4. variablesRequest
428428
*/
429-
async function assertVariableValue(name: string, val: string): Promise<void> {
429+
async function assertLocalVariableValue(name: string, val: string): Promise<void> {
430430
const threadsResponse = await dc.threadsRequest();
431431
assert(threadsResponse.success);
432432
const stackTraceResponse = await dc.stackTraceRequest({ threadId: threadsResponse.body.threads[0].id });
433433
assert(stackTraceResponse.success);
434434
const scopesResponse = await dc.scopesRequest({ frameId: stackTraceResponse.body.stackFrames[0].id });
435435
assert(scopesResponse.success);
436+
const localScopeIndex = scopesResponse.body.scopes.findIndex((v) => v.name === 'Local' || v.name === 'Locals');
437+
assert(localScopeIndex >= 0, "no scope named 'Local':");
436438
const variablesResponse = await dc.variablesRequest({
437-
variablesReference: scopesResponse.body.scopes[0].variablesReference
439+
variablesReference: scopesResponse.body.scopes[localScopeIndex].variablesReference
438440
});
439441
assert(variablesResponse.success);
440442
// Locate the variable with the matching name.
441443
const i = variablesResponse.body.variables.findIndex((v) => v.name === name);
442-
assert(i >= 0);
444+
assert(i >= 0, `no variable in scope named ${name}`);
443445
// Check that the value of name is val.
444446
assert.strictEqual(variablesResponse.body.variables[i].value, val);
445447
}
@@ -698,7 +700,7 @@ const testAll = (isDlvDap: boolean) => {
698700
const debugConfig = await initializeDebugConfig(config);
699701
await dc.hitBreakpoint(debugConfig, getBreakpointLocation(FILE, BREAKPOINT_LINE));
700702

701-
await assertVariableValue('strdat', '"Hello, World!"');
703+
await assertLocalVariableValue('strdat', '"Hello, World!"');
702704
});
703705

704706
test('should debug program without cwd set', async function () {
@@ -721,7 +723,7 @@ const testAll = (isDlvDap: boolean) => {
721723
const debugConfig = await initializeDebugConfig(config);
722724
await dc.hitBreakpoint(debugConfig, getBreakpointLocation(FILE, BREAKPOINT_LINE));
723725

724-
await assertVariableValue('strdat', '"Goodbye, World."');
726+
await assertLocalVariableValue('strdat', '"Goodbye, World."');
725727
});
726728

727729
test('should debug file program with cwd set', async function () {
@@ -745,7 +747,7 @@ const testAll = (isDlvDap: boolean) => {
745747
const debugConfig = await initializeDebugConfig(config);
746748
await dc.hitBreakpoint(debugConfig, getBreakpointLocation(FILE, BREAKPOINT_LINE));
747749

748-
await assertVariableValue('strdat', '"Hello, World!"');
750+
await assertLocalVariableValue('strdat', '"Hello, World!"');
749751
});
750752

751753
test('should debug file program without cwd set', async function () {
@@ -769,7 +771,7 @@ const testAll = (isDlvDap: boolean) => {
769771

770772
await dc.hitBreakpoint(debugConfig, getBreakpointLocation(FILE, BREAKPOINT_LINE));
771773

772-
await assertVariableValue('strdat', '"Goodbye, World."');
774+
await assertLocalVariableValue('strdat', '"Goodbye, World."');
773775
});
774776

775777
test('should run program with cwd set (noDebug)', async function () {
@@ -1146,11 +1148,7 @@ const testAll = (isDlvDap: boolean) => {
11461148
});
11471149

11481150
suite('conditionalBreakpoints', () => {
1149-
test('should stop on conditional breakpoint', async function () {
1150-
if (isDlvDap && dlvDapSkipsEnabled) {
1151-
this.skip(); // not working in dlv-dap.
1152-
}
1153-
1151+
test('should stop on conditional breakpoint', async () => {
11541152
const PROGRAM = path.join(DATA_ROOT, 'condbp');
11551153
const FILE = path.join(DATA_ROOT, 'condbp', 'condbp.go');
11561154
const BREAKPOINT_LINE = 7;
@@ -1183,15 +1181,11 @@ const testAll = (isDlvDap: boolean) => {
11831181
dc.assertStoppedLocation('breakpoint', location)
11841182
]).then(() =>
11851183
// The program is stopped at the breakpoint, check to make sure 'i == 1'.
1186-
assertVariableValue('i', '2')
1184+
assertLocalVariableValue('i', '2')
11871185
);
11881186
});
11891187

1190-
test('should add breakpoint condition', async function () {
1191-
if (isDlvDap && dlvDapSkipsEnabled) {
1192-
this.skip(); // not working in dlv-dap.
1193-
}
1194-
1188+
test('should add breakpoint condition', async () => {
11951189
const PROGRAM = path.join(DATA_ROOT, 'condbp');
11961190
const FILE = path.join(DATA_ROOT, 'condbp', 'condbp.go');
11971191
const BREAKPOINT_LINE = 7;
@@ -1209,7 +1203,7 @@ const testAll = (isDlvDap: boolean) => {
12091203
.hitBreakpoint(debugConfig, location)
12101204
.then(() =>
12111205
// The program is stopped at the breakpoint, check to make sure 'i == 0'.
1212-
assertVariableValue('i', '0')
1206+
assertLocalVariableValue('i', '0')
12131207
)
12141208
.then(() =>
12151209
// Add a condition to the breakpoint, and make sure it runs until 'i == 2'.
@@ -1225,17 +1219,13 @@ const testAll = (isDlvDap: boolean) => {
12251219
dc.assertStoppedLocation('breakpoint', location)
12261220
]).then(() =>
12271221
// The program is stopped at the breakpoint, check to make sure 'i == 2'.
1228-
assertVariableValue('i', '2')
1222+
assertLocalVariableValue('i', '2')
12291223
)
12301224
)
12311225
);
12321226
});
12331227

1234-
test('should remove breakpoint condition', async function () {
1235-
if (isDlvDap && dlvDapSkipsEnabled) {
1236-
this.skip(); // not working in dlv-dap.
1237-
}
1238-
1228+
test('should remove breakpoint condition', async () => {
12391229
const PROGRAM = path.join(DATA_ROOT, 'condbp');
12401230
const FILE = path.join(DATA_ROOT, 'condbp', 'condbp.go');
12411231
const BREAKPOINT_LINE = 7;
@@ -1269,7 +1259,7 @@ const testAll = (isDlvDap: boolean) => {
12691259
])
12701260
.then(() =>
12711261
// The program is stopped at the breakpoint, check to make sure 'i == 2'.
1272-
assertVariableValue('i', '2')
1262+
assertLocalVariableValue('i', '2')
12731263
)
12741264
.then(() =>
12751265
// Remove the breakpoint condition, and make sure the program runs until 'i == 3'.
@@ -1285,7 +1275,7 @@ const testAll = (isDlvDap: boolean) => {
12851275
dc.assertStoppedLocation('breakpoint', location)
12861276
]).then(() =>
12871277
// The program is stopped at the breakpoint, check to make sure 'i == 3'.
1288-
assertVariableValue('i', '3')
1278+
assertLocalVariableValue('i', '3')
12891279
)
12901280
)
12911281
);
@@ -1608,7 +1598,7 @@ const testAll = (isDlvDap: boolean) => {
16081598
}
16091599

16101600
test('should stop on a breakpoint set in file with substituted path', async function () {
1611-
if (isDlvDap) {
1601+
if (isDlvDap && dlvDapSkipsEnabled) {
16121602
this.skip(); // not working in dlv-dap.
16131603
}
16141604

@@ -1656,7 +1646,7 @@ const testAll = (isDlvDap: boolean) => {
16561646
});
16571647

16581648
test('stopped for a breakpoint set during initialization using substitutePath (remote attach)', async function () {
1659-
if (isDlvDap) {
1649+
if (isDlvDap && dlvDapSkipsEnabled) {
16601650
this.skip(); // not working in dlv-dap.
16611651
}
16621652

0 commit comments

Comments
 (0)