@@ -163,6 +163,40 @@ suite('Terminal - Code Execution', () => {
163
163
. returns ( ( ) => terminalService . object ) ;
164
164
} ) ;
165
165
166
+ async function ensureWeSetCurrentDriveBeforeChangingDirectory ( _isWindows : boolean ) : Promise < void > {
167
+ const file = Uri . file ( path . join ( 'd:' , 'path' , 'to' , 'file' , 'one.py' ) ) ;
168
+ terminalSettings . setup ( ( t ) => t . executeInFileDir ) . returns ( ( ) => true ) ;
169
+ workspace . setup ( ( w ) => w . rootPath ) . returns ( ( ) => path . join ( 'c:' , 'path' , 'to' ) ) ;
170
+ workspaceFolder . setup ( ( w ) => w . uri ) . returns ( ( ) => Uri . file ( path . join ( 'c:' , 'path' , 'to' ) ) ) ;
171
+ platform . setup ( ( p ) => p . isWindows ) . returns ( ( ) => true ) ;
172
+ settings . setup ( ( s ) => s . pythonPath ) . returns ( ( ) => PYTHON_PATH ) ;
173
+ terminalSettings . setup ( ( t ) => t . launchArgs ) . returns ( ( ) => [ ] ) ;
174
+
175
+ await executor . executeFile ( file ) ;
176
+ terminalService . verify ( async ( t ) => t . sendText ( TypeMoq . It . isValue ( 'd:' ) ) , TypeMoq . Times . once ( ) ) ;
177
+ }
178
+ test ( 'Ensure we set current drive before changing directory on windows' , async ( ) => {
179
+ await ensureWeSetCurrentDriveBeforeChangingDirectory ( true ) ;
180
+ } ) ;
181
+
182
+ async function ensureWeDoNotChangeDriveIfDriveLetterSameAsFileDriveLetter (
183
+ _isWindows : boolean ,
184
+ ) : Promise < void > {
185
+ const file = Uri . file ( path . join ( 'c:' , 'path' , 'to' , 'file' , 'one.py' ) ) ;
186
+ terminalSettings . setup ( ( t ) => t . executeInFileDir ) . returns ( ( ) => true ) ;
187
+ workspace . setup ( ( w ) => w . rootPath ) . returns ( ( ) => path . join ( 'c:' , 'path' , 'to' ) ) ;
188
+ workspaceFolder . setup ( ( w ) => w . uri ) . returns ( ( ) => Uri . file ( path . join ( 'c:' , 'path' , 'to' ) ) ) ;
189
+ platform . setup ( ( p ) => p . isWindows ) . returns ( ( ) => true ) ;
190
+ settings . setup ( ( s ) => s . pythonPath ) . returns ( ( ) => PYTHON_PATH ) ;
191
+ terminalSettings . setup ( ( t ) => t . launchArgs ) . returns ( ( ) => [ ] ) ;
192
+
193
+ await executor . executeFile ( file ) ;
194
+ terminalService . verify ( async ( t ) => t . sendText ( TypeMoq . It . isValue ( 'c:' ) ) , TypeMoq . Times . never ( ) ) ;
195
+ }
196
+ test ( 'Ensure we do not change drive if current drive letter is same as the file drive letter on windows' , async ( ) => {
197
+ await ensureWeDoNotChangeDriveIfDriveLetterSameAsFileDriveLetter ( true ) ;
198
+ } ) ;
199
+
166
200
async function ensureWeSetCurrentDirectoryBeforeExecutingAFile ( _isWindows : boolean ) : Promise < void > {
167
201
const file = Uri . file ( path . join ( 'c' , 'path' , 'to' , 'file' , 'one.py' ) ) ;
168
202
terminalSettings . setup ( ( t ) => t . executeInFileDir ) . returns ( ( ) => true ) ;
0 commit comments