Skip to content

Commit d5762a7

Browse files
authored
Fixes to detection of shell (microsoft#7384)
* Fixes to identification of shell
1 parent 40a1d04 commit d5762a7

File tree

3 files changed

+28
-1
lines changed

3 files changed

+28
-1
lines changed

news/2 Fixes/6928.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fixes to detection of shell.

src/client/common/terminal/shellDetector.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ export class ShellDetector {
5454
for (const detector of shellDetectors) {
5555
shell = detector.identify(telemetryProperties, terminal);
5656
traceVerbose(`${detector}. Shell identified as ${shell} ${terminal ? `(Terminal name is ${terminal.name})` : ''}`);
57-
if (shell) {
57+
if (shell && shell !== TerminalShellType.other) {
5858
break;
5959
}
6060
}

src/test/common/terminals/shellDetector.unit.test.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,32 @@ suite('Shell Detector', () => {
154154

155155
const shell = shellDetector.identifyTerminalShell();
156156

157+
expect(shell).to.be.equal(detectedShell);
158+
verify(detector1.identify(anything(), anything())).never();
159+
verify(detector2.identify(anything(), undefined)).once();
160+
verify(detector3.identify(anything(), anything())).once();
161+
verify(detector4.identify(anything(), anything())).once();
162+
});
163+
test(`Fall back to detectors that can identify a shell ${testSuffix} (even if detected shell is other)`, () => {
164+
when(platformService.osType).thenReturn(os.value);
165+
const detector1 = mock(UserEnvironmentShellDetector);
166+
const detector2 = mock(UserEnvironmentShellDetector);
167+
const detector3 = mock(UserEnvironmentShellDetector);
168+
const detector4 = mock(UserEnvironmentShellDetector);
169+
const detectedShell = TerminalShellType.xonsh;
170+
when(detector1.priority).thenReturn(1);
171+
when(detector2.priority).thenReturn(2);
172+
when(detector3.priority).thenReturn(3);
173+
when(detector4.priority).thenReturn(4);
174+
when(detector1.identify(anything(), anything())).thenReturn(TerminalShellType.ksh);
175+
when(detector2.identify(anything(), anything())).thenReturn(detectedShell);
176+
when(detector3.identify(anything(), anything())).thenReturn(TerminalShellType.other);
177+
when(detector4.identify(anything(), anything())).thenReturn(TerminalShellType.other);
178+
const shellDetector = new ShellDetector(instance(platformService), [instance(detector1), instance(detector2),
179+
instance(detector3), instance(detector4)]);
180+
181+
const shell = shellDetector.identifyTerminalShell();
182+
157183
expect(shell).to.be.equal(detectedShell);
158184
verify(detector1.identify(anything(), anything())).never();
159185
verify(detector2.identify(anything(), undefined)).once();

0 commit comments

Comments
 (0)