|
14 | 14 | * limitations under the License. |
15 | 15 | */ |
16 | 16 |
|
17 | | -import { GDBTargetConfigurationProvider } from './gdbtarget-configuration-provider'; |
| 17 | +import { GDBTargetConfiguration, GDBTargetConfigurationProvider } from '.'; // use index.ts to cover it in one test |
18 | 18 | import { extensionContextFactory } from '../__test__/vscode.factory'; |
19 | 19 |
|
20 | 20 | import * as vscode from 'vscode'; |
| 21 | +import { URI } from 'vscode-uri'; |
21 | 22 | import { debugConfigurationFactory } from './debug-configuration.factory'; |
| 23 | +import { BuiltinToolPath } from '../desktop/builtin-tool-path'; |
| 24 | +import { isWindows } from '../utils'; |
| 25 | + |
| 26 | +jest.mock('../desktop/builtin-tool-path'); |
| 27 | +const BuiltinToolPathMock = BuiltinToolPath as jest.MockedClass<typeof BuiltinToolPath>; |
22 | 28 |
|
23 | 29 | describe('GDBTargetConfigurationProvider', () => { |
24 | 30 |
|
@@ -49,4 +55,46 @@ describe('GDBTargetConfigurationProvider', () => { |
49 | 55 |
|
50 | 56 | expect(resolvedDebugConfig).toBeDefined(); |
51 | 57 | }); |
| 58 | + |
| 59 | + it('resolves debug configuration and keeps gdb path if other than \'arm-none-eabi-gdb\'', async () => { |
| 60 | + const absoluteGdbPath = '/absolute/path/to/gdb/arm-none-eabi-gdb'; |
| 61 | + const debugConfig = debugConfigurationFactory({ |
| 62 | + gdb: absoluteGdbPath |
| 63 | + }); |
| 64 | + |
| 65 | + const getAbsolutePathSpy = jest.spyOn(BuiltinToolPath.prototype, 'getAbsolutePath'); |
| 66 | + |
| 67 | + const configProvider = new GDBTargetConfigurationProvider([]); |
| 68 | + const resolvedDebugConfig = await configProvider.resolveDebugConfigurationWithSubstitutedVariables( |
| 69 | + undefined, |
| 70 | + debugConfig, |
| 71 | + undefined) as GDBTargetConfiguration; |
| 72 | + |
| 73 | + expect(resolvedDebugConfig).toBeDefined(); |
| 74 | + expect(resolvedDebugConfig.gdb).toEqual(absoluteGdbPath); |
| 75 | + expect(getAbsolutePathSpy).not.toHaveBeenCalled(); |
| 76 | + }); |
| 77 | + |
| 78 | + it('resolves debug configuration and replaces \'arm-none-eabi-gdb\' with built-in tool path', async () => { |
| 79 | + const absoluteGdbPath = '/absolute/path/to/gdb/arm-none-eabi-gdb'; |
| 80 | + const expectedGdbPath = isWindows ? absoluteGdbPath.replaceAll('/', '\\') : absoluteGdbPath; |
| 81 | + const gdbUri = URI.parse(absoluteGdbPath); |
| 82 | + const debugConfig = debugConfigurationFactory({ |
| 83 | + gdb: 'arm-none-eabi-gdb' |
| 84 | + }); |
| 85 | + |
| 86 | + const builtinToolMockInstance = { |
| 87 | + getAbsolutePath: jest.fn().mockReturnValue(gdbUri), |
| 88 | + } as unknown as BuiltinToolPath; |
| 89 | + BuiltinToolPathMock.mockImplementation(() => builtinToolMockInstance); |
| 90 | + |
| 91 | + const configProvider = new GDBTargetConfigurationProvider([]); |
| 92 | + const resolvedDebugConfig = await configProvider.resolveDebugConfigurationWithSubstitutedVariables( |
| 93 | + undefined, |
| 94 | + debugConfig, |
| 95 | + undefined) as GDBTargetConfiguration; |
| 96 | + |
| 97 | + expect(resolvedDebugConfig).toBeDefined(); |
| 98 | + expect(resolvedDebugConfig.gdb).toEqual(expectedGdbPath); |
| 99 | + }); |
52 | 100 | }); |
0 commit comments