|
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, |
| 7 | + shellsWithLeadingSpaceHistorySupport, |
6 | 8 | } from '../../../../../features/terminal/shells/common/shellUtils'; |
| 9 | +import { ShellConstants } from '../../../../../features/common/shellConstants'; |
| 10 | +import { PythonCommandRunConfiguration } from '../../../../../api'; |
7 | 11 |
|
8 | 12 | suite('Shell Utils', () => { |
9 | 13 | suite('extractProfilePath', () => { |
@@ -77,4 +81,108 @@ suite('Shell Utils', () => { |
77 | 81 | assert.strictEqual(result, expectedPath); |
78 | 82 | }); |
79 | 83 | }); |
| 84 | + |
| 85 | + suite('shellsWithLeadingSpaceHistorySupport', () => { |
| 86 | + test('should include bash, zsh, and gitbash', () => { |
| 87 | + assert.ok(shellsWithLeadingSpaceHistorySupport.includes(ShellConstants.BASH)); |
| 88 | + assert.ok(shellsWithLeadingSpaceHistorySupport.includes(ShellConstants.ZSH)); |
| 89 | + assert.ok(shellsWithLeadingSpaceHistorySupport.includes(ShellConstants.GITBASH)); |
| 90 | + }); |
| 91 | + |
| 92 | + test('should not include shells without leading space history support', () => { |
| 93 | + assert.ok(!shellsWithLeadingSpaceHistorySupport.includes(ShellConstants.PWSH)); |
| 94 | + assert.ok(!shellsWithLeadingSpaceHistorySupport.includes(ShellConstants.CMD)); |
| 95 | + assert.ok(!shellsWithLeadingSpaceHistorySupport.includes(ShellConstants.FISH)); |
| 96 | + assert.ok(!shellsWithLeadingSpaceHistorySupport.includes(ShellConstants.SH)); |
| 97 | + assert.ok(!shellsWithLeadingSpaceHistorySupport.includes(ShellConstants.NU)); |
| 98 | + }); |
| 99 | + }); |
| 100 | + |
| 101 | + suite('getShellCommandAsString', () => { |
| 102 | + const sampleCommand: PythonCommandRunConfiguration[] = [ |
| 103 | + { executable: 'source', args: ['/path/to/activate'] }, |
| 104 | + ]; |
| 105 | + |
| 106 | + suite('leading space for history ignore', () => { |
| 107 | + test('should add leading space for bash commands', () => { |
| 108 | + const result = getShellCommandAsString(ShellConstants.BASH, sampleCommand); |
| 109 | + assert.ok(result.startsWith(' '), 'Bash command should start with a leading space'); |
| 110 | + assert.ok(result.includes('source'), 'Command should contain source'); |
| 111 | + }); |
| 112 | + |
| 113 | + test('should add leading space for zsh commands', () => { |
| 114 | + const result = getShellCommandAsString(ShellConstants.ZSH, sampleCommand); |
| 115 | + assert.ok(result.startsWith(' '), 'Zsh command should start with a leading space'); |
| 116 | + assert.ok(result.includes('source'), 'Command should contain source'); |
| 117 | + }); |
| 118 | + |
| 119 | + test('should add leading space for gitbash commands', () => { |
| 120 | + const result = getShellCommandAsString(ShellConstants.GITBASH, sampleCommand); |
| 121 | + assert.ok(result.startsWith(' '), 'Git Bash command should start with a leading space'); |
| 122 | + assert.ok(result.includes('source'), 'Command should contain source'); |
| 123 | + }); |
| 124 | + |
| 125 | + test('should not add leading space for pwsh commands', () => { |
| 126 | + const result = getShellCommandAsString(ShellConstants.PWSH, sampleCommand); |
| 127 | + assert.ok(!result.startsWith(' '), 'PowerShell command should not start with a leading space'); |
| 128 | + }); |
| 129 | + |
| 130 | + test('should not add leading space for cmd commands', () => { |
| 131 | + const result = getShellCommandAsString(ShellConstants.CMD, sampleCommand); |
| 132 | + assert.ok(!result.startsWith(' '), 'CMD command should not start with a leading space'); |
| 133 | + }); |
| 134 | + |
| 135 | + test('should not add leading space for fish commands', () => { |
| 136 | + const result = getShellCommandAsString(ShellConstants.FISH, sampleCommand); |
| 137 | + assert.ok(!result.startsWith(' '), 'Fish command should not start with a leading space'); |
| 138 | + }); |
| 139 | + |
| 140 | + test('should not add leading space for sh commands', () => { |
| 141 | + const result = getShellCommandAsString(ShellConstants.SH, sampleCommand); |
| 142 | + assert.ok(!result.startsWith(' '), 'SH command should not start with a leading space'); |
| 143 | + }); |
| 144 | + |
| 145 | + test('should not add leading space for nu commands', () => { |
| 146 | + const result = getShellCommandAsString(ShellConstants.NU, sampleCommand); |
| 147 | + assert.ok(!result.startsWith(' '), 'Nu command should not start with a leading space'); |
| 148 | + }); |
| 149 | + |
| 150 | + test('should not add leading space for unknown shells', () => { |
| 151 | + const result = getShellCommandAsString('unknown', sampleCommand); |
| 152 | + assert.ok(!result.startsWith(' '), 'Unknown shell command should not start with a leading space'); |
| 153 | + }); |
| 154 | + }); |
| 155 | + |
| 156 | + suite('command formatting', () => { |
| 157 | + test('should format multiple commands with && for bash', () => { |
| 158 | + const multiCommand: PythonCommandRunConfiguration[] = [ |
| 159 | + { executable: 'source', args: ['/path/to/init'] }, |
| 160 | + { executable: 'conda', args: ['activate', 'myenv'] }, |
| 161 | + ]; |
| 162 | + const result = getShellCommandAsString(ShellConstants.BASH, multiCommand); |
| 163 | + assert.ok(result.includes('&&'), 'Bash should use && to join commands'); |
| 164 | + assert.ok(result.startsWith(' '), 'Bash command should start with a leading space'); |
| 165 | + }); |
| 166 | + |
| 167 | + test('should format multiple commands with ; for pwsh', () => { |
| 168 | + const multiCommand: PythonCommandRunConfiguration[] = [ |
| 169 | + { executable: 'source', args: ['/path/to/init'] }, |
| 170 | + { executable: 'conda', args: ['activate', 'myenv'] }, |
| 171 | + ]; |
| 172 | + const result = getShellCommandAsString(ShellConstants.PWSH, multiCommand); |
| 173 | + assert.ok(result.includes(';'), 'PowerShell should use ; to join commands'); |
| 174 | + assert.ok(!result.startsWith(' '), 'PowerShell command should not start with a leading space'); |
| 175 | + }); |
| 176 | + |
| 177 | + test('should format multiple commands with "; and" for fish', () => { |
| 178 | + const multiCommand: PythonCommandRunConfiguration[] = [ |
| 179 | + { executable: 'source', args: ['/path/to/init'] }, |
| 180 | + { executable: 'conda', args: ['activate', 'myenv'] }, |
| 181 | + ]; |
| 182 | + const result = getShellCommandAsString(ShellConstants.FISH, multiCommand); |
| 183 | + assert.ok(result.includes('; and'), 'Fish should use "; and" to join commands'); |
| 184 | + assert.ok(!result.startsWith(' '), 'Fish command should not start with a leading space'); |
| 185 | + }); |
| 186 | + }); |
| 187 | + }); |
80 | 188 | }); |
0 commit comments