|
| 1 | +/** |
| 2 | + * Copyright 2025 Arm Limited |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + * you may not use this file except in compliance with the License. |
| 6 | + * You may obtain a copy of the License at |
| 7 | + * |
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * |
| 10 | + * Unless required by applicable law or agreed to in writing, software |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + * See the License for the specific language governing permissions and |
| 14 | + * limitations under the License. |
| 15 | + */ |
| 16 | + |
| 17 | +import * as vscode from 'vscode'; |
| 18 | +import * as fs from 'fs'; |
| 19 | +import * as os from 'os'; |
| 20 | +import * as path from 'path'; |
| 21 | +import { BuiltinToolPath } from './builtin-tool-path'; |
| 22 | + |
| 23 | +const TOOL_EXTENSION = os.platform() === 'win32' ? '.exe' : ''; |
| 24 | + |
| 25 | +describe('BuiltinToolPath', () => { |
| 26 | + |
| 27 | + let testFolder: string; |
| 28 | + |
| 29 | + beforeEach(() => { |
| 30 | + testFolder = fs.mkdtempSync(path.join(os.tmpdir(), 'jest-')); |
| 31 | + (vscode.extensions.getExtension as jest.Mock).mockReturnValue({ |
| 32 | + extensionUri: vscode.Uri.file(testFolder), |
| 33 | + }); |
| 34 | + }); |
| 35 | + |
| 36 | + afterEach(() => { |
| 37 | + jest.clearAllMocks(); |
| 38 | + fs.rmSync(testFolder, { recursive: true, force: true }); |
| 39 | + }); |
| 40 | + |
| 41 | + it('should return the correct path for a given tool', () => { |
| 42 | + const builtinToolPath = new BuiltinToolPath('tools/pyocd/pyocd'); |
| 43 | + |
| 44 | + fs.mkdirSync(`${testFolder}/tools/pyocd`, { recursive: true }); |
| 45 | + fs.writeFileSync(`${testFolder}/tools/pyocd/pyocd${TOOL_EXTENSION}`, ''); |
| 46 | + |
| 47 | + const expected = vscode.Uri.file(`${testFolder}/tools/pyocd/pyocd${TOOL_EXTENSION}`); |
| 48 | + const result = builtinToolPath.getAbsolutePath(); |
| 49 | + expect(result?.fsPath).toBe(expected.fsPath); |
| 50 | + }); |
| 51 | + |
| 52 | + it('should return undefined if tool does not exist', () => { |
| 53 | + const builtinToolPath = new BuiltinToolPath('tools/pyocd/pyocd'); |
| 54 | + |
| 55 | + const result = builtinToolPath.getAbsolutePath(); |
| 56 | + expect(result).toBeUndefined(); |
| 57 | + }); |
| 58 | + |
| 59 | +}); |
| 60 | + |
0 commit comments