5
5
6
6
import { expect } from 'chai' ;
7
7
import * as TypeMoq from 'typemoq' ;
8
+ import * as sinon from 'sinon' ;
8
9
import { DebugConfiguration , DebugConfigurationProvider , TextDocument , TextEditor , Uri , WorkspaceFolder } from 'vscode' ;
9
- import { IDocumentManager , IWorkspaceService } from '../../../../../client/common/application/types' ;
10
10
import { PYTHON_LANGUAGE } from '../../../../../client/common/constants' ;
11
- import { IFileSystem , IPlatformService } from '../../../../../client/common/platform/types' ;
12
11
import { IConfigurationService } from '../../../../../client/common/types' ;
13
- import { OSType } from '../../../../../client/common/utils/platform' ;
14
12
import { AttachConfigurationResolver } from '../../../../../client/debugger/extension/configuration/resolvers/attach' ;
15
13
import { AttachRequestArguments , DebugOptions } from '../../../../../client/debugger/types' ;
16
14
import { IInterpreterService } from '../../../../../client/interpreter/contracts' ;
17
- import { IServiceContainer } from '../../../../../client/ioc/types' ;
18
- import { getOSType } from '../../../../common' ;
19
- import { getInfoPerOS , setUpOSMocks } from './common' ;
15
+ import { getInfoPerOS } from './common' ;
16
+ import * as common from '../../../../../client/debugger/extension/configuration/utils/common' ;
17
+ import * as workspaceFolder from '../../../../../client/debugger/extension/configuration/utils/workspaceFolder' ;
18
+ import * as platform from '../../../../../client/debugger/extension/configuration/utils/platform' ;
20
19
21
20
getInfoPerOS ( ) . forEach ( ( [ osName , osType , path ] ) => {
22
- if ( osType === OSType . Unknown ) {
21
+ if ( osType === platform . OSType . Unknown ) {
23
22
return ;
24
23
}
25
24
26
25
function getAvailableOptions ( ) : string [ ] {
27
26
const options = [ DebugOptions . RedirectOutput ] ;
28
- if ( osType === OSType . Windows ) {
27
+ if ( osType === platform . OSType . Windows ) {
29
28
options . push ( DebugOptions . FixFilePathCase ) ;
30
29
options . push ( DebugOptions . WindowsClient ) ;
31
30
} else {
@@ -36,36 +35,26 @@ getInfoPerOS().forEach(([osName, osType, path]) => {
36
35
}
37
36
38
37
suite ( `Debugging - Config Resolver attach, OS = ${ osName } ` , ( ) => {
39
- let serviceContainer : TypeMoq . IMock < IServiceContainer > ;
40
38
let debugProvider : DebugConfigurationProvider ;
41
- let platformService : TypeMoq . IMock < IPlatformService > ;
42
- let fileSystem : TypeMoq . IMock < IFileSystem > ;
43
- let documentManager : TypeMoq . IMock < IDocumentManager > ;
44
39
let configurationService : TypeMoq . IMock < IConfigurationService > ;
45
- let workspaceService : TypeMoq . IMock < IWorkspaceService > ;
46
40
let interpreterService : TypeMoq . IMock < IInterpreterService > ;
41
+ let getActiveTextEditorStub : sinon . SinonStub ;
42
+ let getWorkspaceFoldersStub : sinon . SinonStub ;
43
+ let getOSTypeStub : sinon . SinonStub ;
47
44
const debugOptionsAvailable = getAvailableOptions ( ) ;
48
45
49
46
setup ( ( ) => {
50
- serviceContainer = TypeMoq . Mock . ofType < IServiceContainer > ( ) ;
51
- platformService = TypeMoq . Mock . ofType < IPlatformService > ( ) ;
52
- workspaceService = TypeMoq . Mock . ofType < IWorkspaceService > ( ) ;
53
47
configurationService = TypeMoq . Mock . ofType < IConfigurationService > ( ) ;
54
48
interpreterService = TypeMoq . Mock . ofType < IInterpreterService > ( ) ;
55
- fileSystem = TypeMoq . Mock . ofType < IFileSystem > ( ) ;
56
- serviceContainer
57
- . setup ( ( c ) => c . get ( TypeMoq . It . isValue ( IPlatformService ) ) )
58
- . returns ( ( ) => platformService . object ) ;
59
- serviceContainer . setup ( ( c ) => c . get ( TypeMoq . It . isValue ( IFileSystem ) ) ) . returns ( ( ) => fileSystem . object ) ;
60
- setUpOSMocks ( osType , platformService ) ;
61
- documentManager = TypeMoq . Mock . ofType < IDocumentManager > ( ) ;
62
- debugProvider = new AttachConfigurationResolver (
63
- workspaceService . object ,
64
- documentManager . object ,
65
- platformService . object ,
66
- configurationService . object ,
67
- interpreterService . object ,
68
- ) ;
49
+ debugProvider = new AttachConfigurationResolver ( configurationService . object , interpreterService . object ) ;
50
+ getActiveTextEditorStub = sinon . stub ( common , 'getActiveTextEditor' ) ;
51
+ getOSTypeStub = sinon . stub ( platform , 'getOSType' ) ;
52
+ getWorkspaceFoldersStub = sinon . stub ( workspaceFolder , 'getWorkspaceFolders' ) ;
53
+ getOSTypeStub . returns ( osType ) ;
54
+ } ) ;
55
+
56
+ teardown ( ( ) => {
57
+ sinon . restore ( ) ;
69
58
} ) ;
70
59
71
60
function createMoqWorkspaceFolder ( folderPath : string ) {
@@ -81,21 +70,15 @@ getInfoPerOS().forEach(([osName, osType, path]) => {
81
70
document . setup ( ( d ) => d . languageId ) . returns ( ( ) => languageId ) ;
82
71
document . setup ( ( d ) => d . fileName ) . returns ( ( ) => fileName ) ;
83
72
textEditor . setup ( ( t ) => t . document ) . returns ( ( ) => document . object ) ;
84
- documentManager . setup ( ( d ) => d . activeTextEditor ) . returns ( ( ) => textEditor . object ) ;
73
+ getActiveTextEditorStub . returns ( textEditor . object ) ;
85
74
} else {
86
- documentManager . setup ( ( d ) => d . activeTextEditor ) . returns ( ( ) => undefined ) ;
75
+ getActiveTextEditorStub . returns ( undefined ) ;
87
76
}
88
- serviceContainer
89
- . setup ( ( c ) => c . get ( TypeMoq . It . isValue ( IDocumentManager ) ) )
90
- . returns ( ( ) => documentManager . object ) ;
91
77
}
92
78
93
79
function setupWorkspaces ( folders : string [ ] ) {
94
80
const workspaceFolders = folders . map ( createMoqWorkspaceFolder ) ;
95
- workspaceService . setup ( ( w ) => w . workspaceFolders ) . returns ( ( ) => workspaceFolders ) ;
96
- serviceContainer
97
- . setup ( ( c ) => c . get ( TypeMoq . It . isValue ( IWorkspaceService ) ) )
98
- . returns ( ( ) => workspaceService . object ) ;
81
+ getWorkspaceFoldersStub . returns ( workspaceFolders ) ;
99
82
}
100
83
101
84
const attach : Partial < AttachRequestArguments > = {
@@ -269,7 +252,7 @@ getInfoPerOS().forEach(([osName, osType, path]) => {
269
252
} ) ;
270
253
271
254
test ( `Ensure drive letter is lower cased for local path mappings on Windows when host is '${ host } '` , async function ( ) {
272
- if ( getOSType ( ) !== OSType . Windows || osType !== OSType . Windows ) {
255
+ if ( platform . getOSType ( ) !== platform . OSType . Windows || osType !== platform . OSType . Windows ) {
273
256
return this . skip ( ) ;
274
257
}
275
258
const activeFile = 'xyz.py' ;
@@ -292,7 +275,7 @@ getInfoPerOS().forEach(([osName, osType, path]) => {
292
275
} ) ;
293
276
294
277
test ( `Ensure drive letter is not lower cased for local path mappings on non-Windows when host is '${ host } '` , async function ( ) {
295
- if ( getOSType ( ) === OSType . Windows || osType === OSType . Windows ) {
278
+ if ( platform . getOSType ( ) === platform . OSType . Windows || osType === platform . OSType . Windows ) {
296
279
return this . skip ( ) ;
297
280
}
298
281
const activeFile = 'xyz.py' ;
@@ -315,7 +298,7 @@ getInfoPerOS().forEach(([osName, osType, path]) => {
315
298
} ) ;
316
299
317
300
test ( `Ensure drive letter is lower cased for local path mappings on Windows when host is '${ host } ' and with existing path mappings` , async function ( ) {
318
- if ( getOSType ( ) !== OSType . Windows || osType !== OSType . Windows ) {
301
+ if ( platform . getOSType ( ) !== platform . OSType . Windows || osType !== platform . OSType . Windows ) {
319
302
return this . skip ( ) ;
320
303
}
321
304
const activeFile = 'xyz.py' ;
@@ -342,7 +325,7 @@ getInfoPerOS().forEach(([osName, osType, path]) => {
342
325
} ) ;
343
326
344
327
test ( `Ensure drive letter is not lower cased for local path mappings on non-Windows when host is '${ host } ' and with existing path mappings` , async function ( ) {
345
- if ( getOSType ( ) === OSType . Windows || osType === OSType . Windows ) {
328
+ if ( platform . getOSType ( ) === platform . OSType . Windows || osType === platform . OSType . Windows ) {
346
329
return this . skip ( ) ;
347
330
}
348
331
const activeFile = 'xyz.py' ;
0 commit comments