@@ -235,70 +235,94 @@ func TestDeterminePythonMajorMinor(t *testing.T) {
235235 }
236236}
237237
238- func TestLaunch (t * testing.T ) {
238+ func TestPrepare (t * testing.T ) {
239239 dbgRoot = t .TempDir ()
240240
241241 tests := []struct {
242242 description string
243243 pc pythonContext
244244 commands commands
245- shouldErr bool
245+ shouldFail bool
246246 expected pythonContext
247247 }{
248248 {
249249 description : "debugpy" ,
250250 pc : pythonContext {debugMode : "debugpy" , port : 2345 , wait : false , args : []string {"python" , "app.py" }, env : nil },
251251 commands : RunCmdOut ([]string {"python" , "-V" }, "Python 3.7.4\n " ).
252252 AndRunCmd ([]string {"python" , "-m" , "debugpy" , "--listen" , "2345" , "app.py" }),
253- expected : pythonContext {debugMode : "debugpy" , port : 2345 , wait : false , args : []string {"python" , "-m" , "debugpy" , "--listen" , "2345" , "app.py" }, env : env {"PYTHONPATH" : dbgRoot + "/python/lib/python3.7/site-packages" }},
253+ expected : pythonContext {debugMode : "debugpy" , port : 2345 , wait : false , major : 3 , minor : 7 , args : []string {"python" , "-m" , "debugpy" , "--listen" , "2345" , "app.py" }, env : env {"PYTHONPATH" : dbgRoot + "/python/lib/python3.7/site-packages" }},
254254 },
255255 {
256256 description : "debugpy with wait" ,
257257 pc : pythonContext {debugMode : "debugpy" , port : 2345 , wait : true , args : []string {"python" , "app.py" }, env : nil },
258258 commands : RunCmdOut ([]string {"python" , "-V" }, "Python 3.7.4\n " ).
259259 AndRunCmd ([]string {"python" , "-m" , "debugpy" , "--listen" , "2345" , "--wait-for-client" , "app.py" }),
260- expected : pythonContext {debugMode : "debugpy" , port : 2345 , wait : true , args : []string {"python" , "-m" , "debugpy" , "--listen" , "2345" , "--wait-for-client" , "app.py" }, env : env {"PYTHONPATH" : dbgRoot + "/python/lib/python3.7/site-packages" }},
260+ expected : pythonContext {debugMode : "debugpy" , port : 2345 , wait : true , major : 3 , minor : 7 , args : []string {"python" , "-m" , "debugpy" , "--listen" , "2345" , "--wait-for-client" , "app.py" }, env : env {"PYTHONPATH" : dbgRoot + "/python/lib/python3.7/site-packages" }},
261261 },
262262 {
263263 description : "ptvsd" ,
264264 pc : pythonContext {debugMode : "ptvsd" , port : 2345 , wait : false , args : []string {"python" , "app.py" }, env : nil },
265265 commands : RunCmdOut ([]string {"python" , "-V" }, "Python 3.7.4\n " ).
266266 AndRunCmd ([]string {"python" , "-m" , "ptvsd" , "--host" , "localhost" , "--port" , "2345" , "app.py" }),
267- expected : pythonContext {debugMode : "ptvsd" , port : 2345 , wait : false , args : []string {"python" , "-m" , "ptvsd" , "--host" , "localhost" , "--port" , "2345" , "app.py" }, env : env {"PYTHONPATH" : dbgRoot + "/python/lib/python3.7/site-packages" }},
267+ expected : pythonContext {debugMode : "ptvsd" , port : 2345 , wait : false , major : 3 , minor : 7 , args : []string {"python" , "-m" , "ptvsd" , "--host" , "localhost" , "--port" , "2345" , "app.py" }, env : env {"PYTHONPATH" : dbgRoot + "/python/lib/python3.7/site-packages" }},
268268 },
269269 {
270270 description : "ptvsd with wait" ,
271271 pc : pythonContext {debugMode : "ptvsd" , port : 2345 , wait : true , args : []string {"python" , "app.py" }, env : nil },
272272 commands : RunCmdOut ([]string {"python" , "-V" }, "Python 3.7.4\n " ).
273273 AndRunCmd ([]string {"python" , "-m" , "ptvsd" , "--host" , "localhost" , "--port" , "2345" , "--wait" , "app.py" }),
274- expected : pythonContext {debugMode : "ptvsd" , port : 2345 , wait : true , args : []string {"python" , "-m" , "ptvsd" , "--host" , "localhost" , "--port" , "2345" , "--wait" , "app.py" }, env : env {"PYTHONPATH" : dbgRoot + "/python/lib/python3.7/site-packages" }},
274+ expected : pythonContext {debugMode : "ptvsd" , port : 2345 , wait : true , major : 3 , minor : 7 , args : []string {"python" , "-m" , "ptvsd" , "--host" , "localhost" , "--port" , "2345" , "--wait" , "app.py" }, env : env {"PYTHONPATH" : dbgRoot + "/python/lib/python3.7/site-packages" }},
275275 },
276276 {
277277 description : "pydevd" ,
278278 pc : pythonContext {debugMode : "pydevd" , port : 2345 , wait : false , args : []string {"python" , "app.py" }, env : nil },
279279 commands : RunCmdOut ([]string {"python" , "-V" }, "Python 3.7.4\n " ).
280280 AndRunCmd ([]string {"python" , "-m" , "pydevd" , "--server" , "--port" , "2345" , "--continue" , "--file" , "app.py" }),
281- expected : pythonContext {debugMode : "pydevd" , port : 2345 , wait : false , args : []string {"python" , "-m" , "pydevd" , "--server" , "--port" , "2345" , "--continue" , "--file" , "app.py" }, env : env {"PYTHONPATH" : dbgRoot + "/python/pydevd/python3.7/lib/python3.7/site-packages" }},
281+ expected : pythonContext {debugMode : "pydevd" , port : 2345 , wait : false , major : 3 , minor : 7 , args : []string {"python" , "-m" , "pydevd" , "--server" , "--port" , "2345" , "--continue" , "--file" , "app.py" }, env : env {"PYTHONPATH" : dbgRoot + "/python/pydevd/python3.7/lib/python3.7/site-packages" }},
282282 },
283283 {
284284 description : "pydevd with wait" ,
285285 pc : pythonContext {debugMode : "pydevd" , port : 2345 , wait : true , args : []string {"python" , "app.py" }, env : nil },
286286 commands : RunCmdOut ([]string {"python" , "-V" }, "Python 3.7.4\n " ).
287287 AndRunCmd ([]string {"python" , "-m" , "pydevd" , "--server" , "--port" , "2345" , "--file" , "app.py" }),
288- expected : pythonContext {debugMode : "pydevd" , port : 2345 , wait : true , args : []string {"python" , "-m" , "pydevd" , "--server" , "--port" , "2345" , "--file" , "app.py" }, env : env {"PYTHONPATH" : dbgRoot + "/python/pydevd/python3.7/lib/python3.7/site-packages" }},
288+ expected : pythonContext {debugMode : "pydevd" , port : 2345 , wait : true , major : 3 , minor : 7 , args : []string {"python" , "-m" , "pydevd" , "--server" , "--port" , "2345" , "--file" , "app.py" }, env : env {"PYTHONPATH" : dbgRoot + "/python/pydevd/python3.7/lib/python3.7/site-packages" }},
289+ },
290+ {
291+ description : "WRAPPER_ENABLED=false" ,
292+ pc : pythonContext {debugMode : "pydevd" , port : 2345 , wait : true , args : []string {"python" , "app.py" }, env : map [string ]string {"WRAPPER_ENABLED" : "false" }},
293+ shouldFail : true ,
294+ expected : pythonContext {debugMode : "pydevd" , port : 2345 , wait : true , args : []string {"python" , "app.py" }, env : map [string ]string {"WRAPPER_ENABLED" : "false" }},
295+ },
296+ {
297+ description : "already configured with debugpy" ,
298+ pc : pythonContext {debugMode : "debugpy" , port : 2345 , wait : false , args : []string {"python" , "-m" , "debugpy" , "--listen" , "2345" , "app.py" }},
299+ shouldFail : true ,
300+ expected : pythonContext {debugMode : "debugpy" , port : 2345 , wait : false , args : []string {"python" , "-m" , "debugpy" , "--listen" , "2345" , "app.py" }},
301+ },
302+ {
303+ description : "already configured with ptvsd" ,
304+ pc : pythonContext {debugMode : "ptvsd" , port : 2345 , wait : true , args : []string {"python" , "-m" , "ptvsd" , "--host" , "localhost" , "--port" , "2345" , "--wait" , "app.py" }},
305+ shouldFail : true ,
306+ expected : pythonContext {debugMode : "ptvsd" , port : 2345 , wait : true , args : []string {"python" , "-m" , "ptvsd" , "--host" , "localhost" , "--port" , "2345" , "--wait" , "app.py" }},
307+ },
308+ {
309+ description : "already configured with pydevd" ,
310+ pc : pythonContext {debugMode : "pydevd" , port : 2345 , wait : true , args : []string {"python" , "-m" , "pydevd" , "--server" , "--port" , "2345" , "--file" , "app.py" }},
311+ shouldFail : true ,
312+ expected : pythonContext {debugMode : "pydevd" , port : 2345 , wait : true , args : []string {"python" , "-m" , "pydevd" , "--server" , "--port" , "2345" , "--file" , "app.py" }},
289313 },
290314 }
291315
292316 for _ , test := range tests {
293317 t .Run (test .description , func (t * testing.T ) {
294318 test .commands .Setup (t )
295319 pc := test .pc
296- err := pc .launch (context .TODO ())
320+ result := pc .prepare (context .TODO ())
297321
298- if test .shouldErr && err == nil {
299- t .Error ("expected error " )
300- } else if ! test .shouldErr && err != nil {
301- t .Error ("unexpected error:" , err )
322+ if test .shouldFail && result == true {
323+ t .Error ("prepare() should have failed " )
324+ } else if ! test .shouldFail && ! result {
325+ t .Error ("prepare() should have succeeded" )
302326 } else if diff := cmp .Diff (test .expected , pc , cmp .AllowUnexported (test .expected )); diff != "" {
303327 _t .Errorf ("%T differ (-got, +want): %s" , pc , diff )
304328 }
0 commit comments