|
1 | 1 | import * as assert from 'assert'; |
2 | 2 | import { |
3 | 3 | extractProfilePath, |
| 4 | + getShellCommandAsString, |
4 | 5 | PROFILE_TAG_END, |
5 | 6 | PROFILE_TAG_START, |
6 | 7 | } from '../../../../../features/terminal/shells/common/shellUtils'; |
| 8 | +import { ShellConstants } from '../../../../../features/common/shellConstants'; |
7 | 9 |
|
8 | 10 | suite('Shell Utils', () => { |
9 | 11 | suite('extractProfilePath', () => { |
@@ -77,4 +79,41 @@ suite('Shell Utils', () => { |
77 | 79 | assert.strictEqual(result, expectedPath); |
78 | 80 | }); |
79 | 81 | }); |
| 82 | + |
| 83 | + suite('getShellCommandAsString PowerShell Conda Activation', () => { |
| 84 | + test('should format PowerShell conda activation with dot-sourcing correctly', () => { |
| 85 | + const command = [ |
| 86 | + { executable: '.', args: ['/path/to/conda-hook.ps1'] }, |
| 87 | + { executable: 'conda', args: ['activate', 'myenv'] } |
| 88 | + ]; |
| 89 | + const result = getShellCommandAsString(ShellConstants.PWSH, command); |
| 90 | + assert.strictEqual(result, '(. /path/to/conda-hook.ps1) ; (conda activate myenv)'); |
| 91 | + }); |
| 92 | + |
| 93 | + test('should format PowerShell conda activation with spaces in path correctly', () => { |
| 94 | + const command = [ |
| 95 | + { executable: '.', args: ['/path with spaces/conda-hook.ps1'] }, |
| 96 | + { executable: 'conda', args: ['activate', 'my env'] } |
| 97 | + ]; |
| 98 | + const result = getShellCommandAsString(ShellConstants.PWSH, command); |
| 99 | + assert.strictEqual(result, '(. "/path with spaces/conda-hook.ps1") ; (conda activate "my env")'); |
| 100 | + }); |
| 101 | + |
| 102 | + test('should format PowerShell conda activation fallback correctly', () => { |
| 103 | + const command = [ |
| 104 | + { executable: '/path/to/activate.bat' }, |
| 105 | + { executable: 'conda', args: ['activate', 'myenv'] } |
| 106 | + ]; |
| 107 | + const result = getShellCommandAsString(ShellConstants.PWSH, command); |
| 108 | + assert.strictEqual(result, '(/path/to/activate.bat) ; (conda activate myenv)'); |
| 109 | + }); |
| 110 | + |
| 111 | + test('should format single PowerShell command without parentheses', () => { |
| 112 | + const command = [ |
| 113 | + { executable: 'conda', args: ['activate', 'myenv'] } |
| 114 | + ]; |
| 115 | + const result = getShellCommandAsString(ShellConstants.PWSH, command); |
| 116 | + assert.strictEqual(result, 'conda activate myenv'); |
| 117 | + }); |
| 118 | + }); |
80 | 119 | }); |
0 commit comments