|
1 | 1 | import assert from 'node:assert/strict';
|
| 2 | +import os from 'node:os'; |
2 | 3 | import path from 'node:path';
|
3 |
| -import temp from 'temp'; |
| 4 | +import type temp from 'temp'; |
4 | 5 | import { __tests__ } from '../../debug';
|
5 | 6 | import { exec } from '../../exec';
|
6 | 7 | import { TestEnv } from '../testEnv';
|
@@ -35,7 +36,7 @@ describe('debug (slow)', () => {
|
35 | 36 | sketchPath,
|
36 | 37 | programmer,
|
37 | 38 | });
|
38 |
| - assert.deepStrictEqual(actual, { |
| 39 | + const expected = { |
39 | 40 | name: `Arduino (${fqbn}:programmer=${programmer})`,
|
40 | 41 | configId: `${fqbn}:programmer=${programmer}`,
|
41 | 42 | cwd: '${workspaceRoot}',
|
@@ -70,7 +71,21 @@ describe('debug (slow)', () => {
|
70 | 71 | 'hardware/arduino-git/samd/variants/nano_33_iot/openocd_scripts/openocd.cfg'
|
71 | 72 | ),
|
72 | 73 | ],
|
73 |
| - }); |
| 74 | + }; |
| 75 | + if (os.platform() === 'win32') { |
| 76 | + // The CLI builds the paths in a strange way and mixes the \\ separators with / |
| 77 | + // Expected: "c:\\Users\\kittaakos\\dev\\vscode-arduino-tools\\.tests\\data\\packages\\arduino\\tools\\openocd\\0.10.0-arduino7\\bin\\openocd" |
| 78 | + // Got: "C:\\Users\\kittaakos\\dev\\vscode-arduino-tools\\.tests\\data\\packages\\arduino\\tools\\openocd\\0.10.0-arduino7/bin/openocd" |
| 79 | + // This logic adjusts the expectations on Windows |
| 80 | + actual.serverpath = normalizePath(actual.serverpath); |
| 81 | + actual.svdFile = normalizePath(actual.svdFile); |
| 82 | + if (actual.configFiles) { |
| 83 | + actual.configFiles[1] = <string>normalizePath(actual.configFiles[1]); |
| 84 | + } |
| 85 | + actual.armToolchainPath = normalizePath(actual.armToolchainPath); |
| 86 | + actual.executable = <string>normalizePath(actual.executable, false); // |
| 87 | + } |
| 88 | + assert.deepStrictEqual(actual, expected); |
74 | 89 | });
|
75 | 90 | });
|
76 | 91 |
|
@@ -145,4 +160,20 @@ describe('debug (slow)', () => {
|
145 | 160 | function fromBuildPath(...paths: string[]): string {
|
146 | 161 | return path.join(buildPath, ...paths);
|
147 | 162 | }
|
| 163 | + |
| 164 | + function normalizePath( |
| 165 | + p: string | undefined, |
| 166 | + driveLetterToLowerCase = true // This is a hack. Sometimes the CLI gives paths with capital case drive, sometimes it's lower-case. |
| 167 | + ): string | undefined { |
| 168 | + if (!p || os.platform() !== 'win32') { |
| 169 | + return p; |
| 170 | + } |
| 171 | + let normalized = p.split('/').join('\\'); // cannot use path.resolve as the CLI sometimes gives the trailing separator on Windows, sometimes it does not |
| 172 | + if (driveLetterToLowerCase && /^[a-z]:\\/i.test(normalized)) { |
| 173 | + normalized = |
| 174 | + normalized.substring(0, 1).toLowerCase() + |
| 175 | + normalized.substring(1, normalized.length); |
| 176 | + } |
| 177 | + return normalized; |
| 178 | + } |
148 | 179 | });
|
0 commit comments