8
8
import { ChildProcess , spawn } from 'child_process' ;
9
9
import * as getFreePort from 'get-port' ;
10
10
import * as path from 'path' ;
11
+ import * as TypeMoq from 'typemoq' ;
12
+ import { DebugConfiguration , Uri } from 'vscode' ;
11
13
import { DebugClient } from 'vscode-debugadapter-testsupport' ;
12
14
import { EXTENSION_ROOT_DIR } from '../../client/common/constants' ;
13
15
import '../../client/common/extensions' ;
14
- import { DebugOptions } from '../../client/debugger/Common/Contracts' ;
16
+ import { IS_WINDOWS } from '../../client/common/platform/constants' ;
17
+ import { PlatformService } from '../../client/common/platform/platformService' ;
18
+ import { IPlatformService } from '../../client/common/platform/types' ;
19
+ import { PythonV2DebugConfigurationProvider } from '../../client/debugger' ;
20
+ import { AttachRequestArguments , DebugOptions } from '../../client/debugger/Common/Contracts' ;
21
+ import { IServiceContainer } from '../../client/ioc/types' ;
15
22
import { sleep } from '../common' ;
16
23
import { initialize , IS_APPVEYOR , IS_MULTI_ROOT_TEST , TEST_DEBUGGER } from '../initialize' ;
17
24
import { continueDebugging , createDebugAdapter } from './utils' ;
@@ -43,21 +50,17 @@ suite('Attach Debugger - Experimental', () => {
43
50
} catch { }
44
51
}
45
52
} ) ;
46
- test ( 'Confirm we are able to attach to a running program' , async function ( ) {
47
- this . timeout ( 20000 ) ;
48
- // Lets skip this test on AppVeyor (very flaky on AppVeyor).
49
- if ( IS_APPVEYOR ) {
50
- return ;
51
- }
52
-
53
+ async function testAttachingToRemoteProcess ( localRoot : string , remoteRoot : string , pathSeparator : string ) {
53
54
const port = await getFreePort ( { host : 'localhost' , port : 3000 } ) ;
54
55
const customEnv = { ...process . env } ;
55
56
56
57
// Set the path for PTVSD to be picked up.
57
58
// tslint:disable-next-line:no-string-literal
58
- customEnv [ 'PYTHONPATH' ] = ptvsdPath ;
59
- const pythonArgs = [ '-m' , 'ptvsd' , '--server' , '--port' , `${ port } ` , '--file' , fileToDebug . fileToCommandArgument ( ) ] ;
59
+ customEnv [ 'PYTHONPATH' ] = '/home/don/Desktop/development/vscode/ptvsd' ;
60
+ const pythonArgs = [ '-m' , 'ptvsd' , '--server' , '--port' , `${ port } ` , '--file' , fileToDebug ] ;
60
61
procToKill = spawn ( 'python' , pythonArgs , { env : customEnv , cwd : path . dirname ( fileToDebug ) } ) ;
62
+ // wait for remote socket to start
63
+ await sleep ( 1000 ) ;
61
64
62
65
// Send initialize, attach
63
66
const initializePromise = debugClient . initializeRequest ( {
@@ -69,15 +72,23 @@ suite('Attach Debugger - Experimental', () => {
69
72
supportsVariableType : true ,
70
73
supportsVariablePaging : true
71
74
} ) ;
72
- const attachPromise = debugClient . attachRequest ( {
73
- localRoot : path . dirname ( fileToDebug ) ,
74
- remoteRoot : path . dirname ( fileToDebug ) ,
75
+ const options : AttachRequestArguments & DebugConfiguration = {
76
+ name : 'attach' ,
77
+ request : 'attach' ,
78
+ localRoot,
79
+ remoteRoot,
75
80
type : 'pythonExperimental' ,
76
81
port : port ,
77
82
host : 'localhost' ,
78
- logToFile : false ,
83
+ logToFile : true ,
79
84
debugOptions : [ DebugOptions . RedirectOutput ]
80
- } ) ;
85
+ } ;
86
+ const serviceContainer = TypeMoq . Mock . ofType < IServiceContainer > ( ) ;
87
+ serviceContainer . setup ( c => c . get ( IPlatformService , TypeMoq . It . isAny ( ) ) ) . returns ( ( ) => new PlatformService ( ) ) ;
88
+ const configProvider = new PythonV2DebugConfigurationProvider ( serviceContainer . object ) ;
89
+
90
+ const launchArgs = await configProvider . resolveDebugConfiguration ( { index : 0 , name : 'root' , uri : Uri . file ( localRoot ) } , options ) ;
91
+ const attachPromise = debugClient . attachRequest ( launchArgs ) ;
81
92
82
93
await Promise . all ( [
83
94
initializePromise ,
@@ -90,7 +101,9 @@ suite('Attach Debugger - Experimental', () => {
90
101
const stdOutPromise = debugClient . assertOutput ( 'stdout' , 'this is stdout' ) ;
91
102
const stdErrPromise = debugClient . assertOutput ( 'stderr' , 'this is stderr' ) ;
92
103
93
- const breakpointLocation = { path : fileToDebug , column : 1 , line : 12 } ;
104
+ // Don't use path utils, as we're building the paths manually (mimic windows paths on unix test servers and vice versa).
105
+ const localFileName = `${ localRoot } ${ pathSeparator } ${ path . basename ( fileToDebug ) } ` ;
106
+ const breakpointLocation = { path : localFileName , column : 1 , line : 12 } ;
94
107
const breakpointPromise = debugClient . setBreakpointsRequest ( {
95
108
lines : [ breakpointLocation . line ] ,
96
109
breakpoints : [ { line : breakpointLocation . line , column : breakpointLocation . column } ] ,
@@ -111,5 +124,25 @@ suite('Attach Debugger - Experimental', () => {
111
124
debugClient . waitForEvent ( 'exited' ) ,
112
125
debugClient . waitForEvent ( 'terminated' )
113
126
] ) ;
127
+ }
128
+ test ( 'Confirm we are able to attach to a running program' , async function ( ) {
129
+ this . timeout ( 20000 ) ;
130
+ // Lets skip this test on AppVeyor (very flaky on AppVeyor).
131
+ if ( IS_APPVEYOR ) {
132
+ return ;
133
+ }
134
+
135
+ await testAttachingToRemoteProcess ( path . dirname ( fileToDebug ) , path . dirname ( fileToDebug ) , path . sep ) ;
136
+ } ) ;
137
+ test ( 'Confirm localpath translations are done correctly' , async function ( ) {
138
+ this . timeout ( 20000 ) ;
139
+ // Lets skip this test on AppVeyor (very flaky on AppVeyor).
140
+ if ( IS_APPVEYOR ) {
141
+ return ;
142
+ }
143
+
144
+ const localWorkspace = IS_WINDOWS ? '/home/user/Desktop/project/src' : 'C:\\Project\\src' ;
145
+ const pathSeparator = IS_WINDOWS ? '\\' : '/' ;
146
+ await testAttachingToRemoteProcess ( localWorkspace , path . dirname ( fileToDebug ) , pathSeparator ) ;
114
147
} ) ;
115
148
} ) ;
0 commit comments