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' ;
@@ -43,13 +45,7 @@ suite('Attach Debugger - Experimental', () => {
43
45
} catch { }
44
46
}
45
47
} ) ;
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
-
48
+ async function testAttachingToRemoteProcess ( localRoot : string , remoteRoot : string , pathSeparator : string ) {
53
49
const port = await getFreePort ( { host : 'localhost' , port : 3000 } ) ;
54
50
const customEnv = { ...process . env } ;
55
51
@@ -58,6 +54,8 @@ suite('Attach Debugger - Experimental', () => {
58
54
customEnv [ 'PYTHONPATH' ] = PTVSD_PATH ;
59
55
const pythonArgs = [ '-m' , 'ptvsd' , '--server' , '--port' , `${ port } ` , '--file' , fileToDebug . fileToCommandArgument ( ) ] ;
60
56
procToKill = spawn ( 'python' , pythonArgs , { env : customEnv , cwd : path . dirname ( fileToDebug ) } ) ;
57
+ // wait for remote socket to start
58
+ await sleep ( 1000 ) ;
61
59
62
60
// Send initialize, attach
63
61
const initializePromise = debugClient . initializeRequest ( {
@@ -69,15 +67,23 @@ suite('Attach Debugger - Experimental', () => {
69
67
supportsVariableType : true ,
70
68
supportsVariablePaging : true
71
69
} ) ;
72
- const attachPromise = debugClient . attachRequest ( {
73
- localRoot : path . dirname ( fileToDebug ) ,
74
- remoteRoot : path . dirname ( fileToDebug ) ,
70
+ const options : AttachRequestArguments & DebugConfiguration = {
71
+ name : 'attach' ,
72
+ request : 'attach' ,
73
+ localRoot,
74
+ remoteRoot,
75
75
type : 'pythonExperimental' ,
76
76
port : port ,
77
77
host : 'localhost' ,
78
- logToFile : false ,
78
+ logToFile : true ,
79
79
debugOptions : [ DebugOptions . RedirectOutput ]
80
- } ) ;
80
+ } ;
81
+ const serviceContainer = TypeMoq . Mock . ofType < IServiceContainer > ( ) ;
82
+ serviceContainer . setup ( c => c . get ( IPlatformService , TypeMoq . It . isAny ( ) ) ) . returns ( ( ) => new PlatformService ( ) ) ;
83
+ const configProvider = new PythonV2DebugConfigurationProvider ( serviceContainer . object ) ;
84
+
85
+ const launchArgs = await configProvider . resolveDebugConfiguration ( { index : 0 , name : 'root' , uri : Uri . file ( localRoot ) } , options ) ;
86
+ const attachPromise = debugClient . attachRequest ( launchArgs ) ;
81
87
82
88
await Promise . all ( [
83
89
initializePromise ,
@@ -90,7 +96,9 @@ suite('Attach Debugger - Experimental', () => {
90
96
const stdOutPromise = debugClient . assertOutput ( 'stdout' , 'this is stdout' ) ;
91
97
const stdErrPromise = debugClient . assertOutput ( 'stderr' , 'this is stderr' ) ;
92
98
93
- const breakpointLocation = { path : fileToDebug , column : 1 , line : 12 } ;
99
+ // Don't use path utils, as we're building the paths manually (mimic windows paths on unix test servers and vice versa).
100
+ const localFileName = `${ localRoot } ${ pathSeparator } ${ path . basename ( fileToDebug ) } ` ;
101
+ const breakpointLocation = { path : localFileName , column : 1 , line : 12 } ;
94
102
const breakpointPromise = debugClient . setBreakpointsRequest ( {
95
103
lines : [ breakpointLocation . line ] ,
96
104
breakpoints : [ { line : breakpointLocation . line , column : breakpointLocation . column } ] ,
@@ -111,5 +119,25 @@ suite('Attach Debugger - Experimental', () => {
111
119
debugClient . waitForEvent ( 'exited' ) ,
112
120
debugClient . waitForEvent ( 'terminated' )
113
121
] ) ;
122
+ }
123
+ test ( 'Confirm we are able to attach to a running program' , async function ( ) {
124
+ this . timeout ( 20000 ) ;
125
+ // Lets skip this test on AppVeyor (very flaky on AppVeyor).
126
+ if ( IS_APPVEYOR ) {
127
+ return ;
128
+ }
129
+
130
+ await testAttachingToRemoteProcess ( path . dirname ( fileToDebug ) , path . dirname ( fileToDebug ) , path . sep ) ;
131
+ } ) ;
132
+ test ( 'Confirm localpath translations are done correctly' , async function ( ) {
133
+ this . timeout ( 20000 ) ;
134
+ // Lets skip this test on AppVeyor (very flaky on AppVeyor).
135
+ if ( IS_APPVEYOR ) {
136
+ return ;
137
+ }
138
+
139
+ const localWorkspace = IS_WINDOWS ? '/home/user/Desktop/project/src' : 'C:\\Project\\src' ;
140
+ const pathSeparator = IS_WINDOWS ? '\\' : '/' ;
141
+ await testAttachingToRemoteProcess ( localWorkspace , path . dirname ( fileToDebug ) , pathSeparator ) ;
114
142
} ) ;
115
143
} ) ;
0 commit comments