Skip to content

Commit 6a2a004

Browse files
committed
test: fix breakpoint tests on windows
The filepaths returned from delve (and thus the debug adapter) do not use the native filepath separator on windows. Delve recognizes filepaths with either separator. We can pass paths with '/' to the hitBreakpoint function, in order to get a match. This is a workaround to use the hitbreakpoint function as is. It may be preferable to reimplement the function and then match the paths ignoring the separator. Change-Id: I8a08454ac955e5e8e3e00a657c45acc8c2bd4484 Reviewed-on: https://go-review.googlesource.com/c/vscode-go/+/260729 Trust: Suzy Mueller <suzmue@golang.org> Run-TryBot: Suzy Mueller <suzmue@golang.org> TryBot-Result: kokoro <noreply+kokoro@google.com> Reviewed-by: Hyang-Ah Hana Kim <hyangah@gmail.com>
1 parent 7d5f58a commit 6a2a004

File tree

1 file changed

+17
-9
lines changed

1 file changed

+17
-9
lines changed

test/integration/goDebug.test.ts

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import * as fs from 'fs';
33
import * as path from 'path';
44
import * as sinon from 'sinon';
55
import {DebugClient} from 'vscode-debugadapter-testsupport';
6+
import { ILocation } from 'vscode-debugadapter-testsupport/lib/debugClient';
67
import {DebugProtocol} from 'vscode-debugprotocol';
78
import {
89
Delve,
@@ -277,18 +278,17 @@ suite('Go Debug Adapter', function () {
277278
this.timeout(10000);
278279

279280
const debugConfigProvider = new GoDebugConfigurationProvider();
281+
const DEBUG_ADAPTER = path.join('.', 'dist', 'debugAdapter.js');
280282

281-
const DEBUG_ADAPTER = './dist/debugAdapter.js';
282-
283-
const PROJECT_ROOT = path.join(__dirname, '..', '..', '..');
283+
const PROJECT_ROOT = path.normalize(path.join(__dirname, '..', '..', '..'));
284284
const DATA_ROOT = path.join(PROJECT_ROOT, 'test', 'fixtures');
285285

286286
let dc: DebugClient;
287287

288288
setup( () => {
289289
dc = new DebugClient('node', path.join(PROJECT_ROOT, DEBUG_ADAPTER), 'go');
290290
// To connect to a running debug server for debugging the tests, specify PORT.
291-
return dc.start(/* PORT */);
291+
return dc.start();
292292
});
293293

294294
teardown( () => dc.stop() );
@@ -382,7 +382,8 @@ suite('Go Debug Adapter', function () {
382382
type: 'go',
383383
request: 'launch',
384384
mode: 'auto',
385-
program: PROGRAM
385+
program: PROGRAM,
386+
trace: 'verbose'
386387
};
387388

388389
const debugConfig = debugConfigProvider.resolveDebugConfiguration(undefined, config);
@@ -437,13 +438,20 @@ suite('Go Debug Adapter', function () {
437438
});
438439
});
439440

441+
// The file paths returned from delve use '/' not the native path
442+
// separator, so we can replace any instances of '\' with '/', which
443+
// allows the hitBreakpoint check to match.
444+
const getBreakpointLocation = (FILE: string, LINE: number) => {
445+
return {path: FILE.replace(/\\/g, '/'), line: LINE };
446+
};
447+
440448
suite('setBreakpoints', () => {
441449

442450
test('should stop on a breakpoint', () => {
443451

444452
const PROGRAM = path.join(DATA_ROOT, 'baseTest');
445-
const FILE = path.join(DATA_ROOT, 'baseTest', 'test.go');
446453

454+
const FILE = path.join(DATA_ROOT, 'baseTest', 'test.go');
447455
const BREAKPOINT_LINE = 11;
448456

449457
const config = {
@@ -455,14 +463,14 @@ suite('Go Debug Adapter', function () {
455463
};
456464
const debugConfig = debugConfigProvider.resolveDebugConfiguration(undefined, config);
457465

458-
return dc.hitBreakpoint(debugConfig, { path: FILE, line: BREAKPOINT_LINE } );
466+
return dc.hitBreakpoint(debugConfig, getBreakpointLocation(FILE, BREAKPOINT_LINE) );
459467
});
460468

461469
test('should stop on a breakpoint in test file', () => {
462470

463471
const PROGRAM = path.join(DATA_ROOT, 'baseTest');
464-
const FILE = path.join(DATA_ROOT, 'baseTest', 'sample_test.go');
465472

473+
const FILE = path.join(DATA_ROOT, 'baseTest', 'sample_test.go');
466474
const BREAKPOINT_LINE = 15;
467475

468476
const config = {
@@ -474,7 +482,7 @@ suite('Go Debug Adapter', function () {
474482
};
475483
const debugConfig = debugConfigProvider.resolveDebugConfiguration(undefined, config);
476484

477-
return dc.hitBreakpoint(debugConfig, { path: FILE, line: BREAKPOINT_LINE } );
485+
return dc.hitBreakpoint(debugConfig, getBreakpointLocation(FILE, BREAKPOINT_LINE) );
478486
});
479487

480488
});

0 commit comments

Comments
 (0)