Skip to content

Commit de76a0f

Browse files
author
Akos Kitta
committed
fix: tests on Windows
do some magic with the paths
1 parent 4be5f07 commit de76a0f

File tree

1 file changed

+34
-3
lines changed

1 file changed

+34
-3
lines changed

src/test/suite/debug.slow-test.ts

Lines changed: 34 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import assert from 'node:assert/strict';
2+
import os from 'node:os';
23
import path from 'node:path';
3-
import temp from 'temp';
4+
import type temp from 'temp';
45
import { __tests__ } from '../../debug';
56
import { exec } from '../../exec';
67
import { TestEnv } from '../testEnv';
@@ -35,7 +36,7 @@ describe('debug (slow)', () => {
3536
sketchPath,
3637
programmer,
3738
});
38-
assert.deepStrictEqual(actual, {
39+
const expected = {
3940
name: `Arduino (${fqbn}:programmer=${programmer})`,
4041
configId: `${fqbn}:programmer=${programmer}`,
4142
cwd: '${workspaceRoot}',
@@ -70,7 +71,21 @@ describe('debug (slow)', () => {
7071
'hardware/arduino-git/samd/variants/nano_33_iot/openocd_scripts/openocd.cfg'
7172
),
7273
],
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);
7489
});
7590
});
7691

@@ -145,4 +160,20 @@ describe('debug (slow)', () => {
145160
function fromBuildPath(...paths: string[]): string {
146161
return path.join(buildPath, ...paths);
147162
}
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+
}
148179
});

0 commit comments

Comments
 (0)