Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit ce964e3

Browse filesBrowse files
Akos Kittakittaakos
Akos Kitta
authored andcommitted
fix: programmer is optional for debug -I check
Ref: arduino/arduino-ide#2371 Signed-off-by: Akos Kitta <a.kitta@arduino.cc>
1 parent 666dd48 commit ce964e3
Copy full SHA for ce964e3

File tree

5 files changed

+57
-25
lines changed
Filter options

5 files changed

+57
-25
lines changed

‎package.json

Copy file name to clipboardExpand all lines: package.json
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
"compile-tests": "tsc -p . --outDir lib",
2626
"format": "prettier --write . && prettier-package-json --write ./package.json",
2727
"generate": "node ./scripts/generate.js 1.5.1",
28-
"postinstall": "node ./scripts/cli 0.35.2",
28+
"postinstall": "node ./scripts/cli 0.35.3",
2929
"lint": "eslint src --ext ts",
3030
"prepackage": "yarn clean && yarn compile && yarn lint && yarn webpack",
3131
"package": "mkdirp build-artifacts && vsce package --out ./build-artifacts",

‎src/debug.ts

Copy file name to clipboardExpand all lines: src/debug.ts
+20-14Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -142,9 +142,6 @@ async function createLaunchConfig(
142142
params: StartDebugParams
143143
): Promise<ArduinoDebugLaunchConfig> {
144144
const { programmer, board } = params;
145-
if (!programmer) {
146-
throw new Error('Missing programmer');
147-
}
148145
const { file, args } = buildDebugInfoArgs(params);
149146
const [stdout, customConfigs] = await Promise.all([
150147
withProgress(
@@ -206,8 +203,14 @@ async function parseRawDebugInfo(
206203
return config;
207204
}
208205

209-
function createConfigId(board: BoardIdentifier, programmer: string): string {
206+
function createConfigId(
207+
board: BoardIdentifier,
208+
programmer: string | undefined
209+
): string {
210210
const fqbn = new FQBN(board.fqbn);
211+
if (!programmer) {
212+
return fqbn.toString();
213+
}
211214
if (hasConfigOptions(fqbn)) {
212215
// if already has config options, append the programmer as an ordinary custom board config option
213216
return `${fqbn.toString()},programmer=${programmer}`;
@@ -294,7 +297,7 @@ function resolveCliConfigPath(
294297

295298
async function mergeLaunchConfig(
296299
board: BoardIdentifier,
297-
programmer: string,
300+
programmer: string | undefined,
298301
debugInfo: DebugInfo & Executable,
299302
customConfigs: CustomDebugConfigs
300303
): Promise<ArduinoDebugLaunchConfig> {
@@ -326,7 +329,10 @@ async function mergeLaunchConfig(
326329
return launchConfig;
327330
}
328331

329-
function createName(board: BoardIdentifier, programmer: string): string {
332+
function createName(
333+
board: BoardIdentifier,
334+
programmer: string | undefined
335+
): string {
330336
if (!board.name) {
331337
const configId = createConfigId(board, programmer);
332338
return `Arduino (${configId})`;
@@ -336,9 +342,9 @@ function createName(board: BoardIdentifier, programmer: string): string {
336342
const options = Object.entries(fqbn.options)
337343
.map(([key, value]) => `${key}=${value}`)
338344
.join(',');
339-
return `${board.name} (${options},${programmer})`;
345+
return `${board.name} (${options}${programmer ? `,${programmer}` : ''})`;
340346
}
341-
return `${board.name} (${programmer})`;
347+
return `${board.name}${programmer ? ` (${programmer})` : ''}`;
342348
}
343349

344350
function replaceValue(
@@ -494,12 +500,12 @@ export class CliError extends Error {
494500
}
495501
}
496502

497-
// https://github.com/arduino/arduino-cli/blob/b41f4044cac6ab7f7d853e368bc31e5d626d63d4/internal/cli/feedback/errorcodes.go#L57-L58
498-
const missingProgrammerCode = 11 as const;
499-
function isMissingProgrammerError(
503+
// https://github.com/arduino/arduino-cli/blob/b41f4044cac6ab7f7d853e368bc31e5d626d63d4/internal/cli/feedback/errorcodes.go#L43-L44
504+
const badArgumentCode = 7 as const;
505+
function isBadArgumentError(
500506
arg: unknown
501-
): arg is CliError & { exitCode: typeof missingProgrammerCode } {
502-
return arg instanceof CliError && arg.exitCode === missingProgrammerCode;
507+
): arg is CliError & { exitCode: typeof badArgumentCode } {
508+
return arg instanceof CliError && arg.exitCode === badArgumentCode;
503509
}
504510

505511
// Remove index signature
@@ -536,6 +542,6 @@ export const __tests__ = {
536542
mergeLaunchConfig,
537543
updateLaunchConfigs,
538544
isCommandError,
539-
isMissingProgrammerError,
545+
isBadArgumentError,
540546
cliExec,
541547
} as const;

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

Copy file name to clipboardExpand all lines: src/test/suite/debug.slow-test.ts
+6-9Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,8 @@ import { __tests__ } from '../../debug';
66
import { exec } from '../../exec';
77
import { TestEnv } from '../testEnv';
88

9-
const {
10-
CliError,
11-
buildDebugInfoArgs,
12-
createLaunchConfig,
13-
isMissingProgrammerError,
14-
} = __tests__;
9+
const { CliError, buildDebugInfoArgs, createLaunchConfig, isBadArgumentError } =
10+
__tests__;
1511

1612
describe('debug (slow)', function () {
1713
this.slow(2_000);
@@ -168,14 +164,15 @@ describe('debug (slow)', function () {
168164
});
169165

170166
['en', 'it'].map((locale) =>
171-
it(`should fail when the programmer is missing (locale: ${locale})`, async function () {
167+
// Note: this test used to test the missing programmer error, but the programmer is optional after https://github.com/arduino/arduino-cli/pull/2544 so it's testing the bad request.
168+
it(`should fail with bad argument (error code 7) if the debugging is not supported by the board (locale: ${locale})`, async function () {
172169
if (!testEnv.cliConfigPaths[locale]) {
173170
this.skip();
174171
}
175172
await assert.rejects(
176-
// Can be any arbitrary board that does not have a default programmer defined in the platform. Otherwise, the error does not occur.
173+
// Can be any arbitrary board that does not support debugging.
177174
cliExec(['debug', '-I', '-b', 'arduino:avr:uno', sketchPath], locale),
178-
(reason) => isMissingProgrammerError(reason)
175+
(reason) => isBadArgumentError(reason)
179176
);
180177
})
181178
);

‎src/test/suite/debug.test.ts

Copy file name to clipboardExpand all lines: src/test/suite/debug.test.ts
+29Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -363,10 +363,21 @@ describe('debug', () => {
363363
const actual = createConfigId({ fqbn: 'a:b:c' }, 'p');
364364
assert.strictEqual(actual, 'a:b:c:programmer=p');
365365
});
366+
367+
it('should create the configuration ID when the FQBN has no custom board options (no programmer)', () => {
368+
const actual = createConfigId({ fqbn: 'a:b:c' }, undefined);
369+
assert.strictEqual(actual, 'a:b:c');
370+
});
371+
366372
it('should create the configuration ID when the FQBN has custom board options', () => {
367373
const actual = createConfigId({ fqbn: 'a:b:c:o1=v1' }, 'p');
368374
assert.strictEqual(actual, 'a:b:c:o1=v1,programmer=p');
369375
});
376+
377+
it('should create the configuration ID when the FQBN has custom board options (no programmer)', () => {
378+
const actual = createConfigId({ fqbn: 'a:b:c:o1=v1' }, undefined);
379+
assert.strictEqual(actual, 'a:b:c:o1=v1');
380+
});
370381
});
371382
describe('createName', () => {
372383
it('should use the generated config ID if the board name is absent', () => {
@@ -386,19 +397,37 @@ describe('debug', () => {
386397
);
387398
});
388399

400+
it('should use the generated config ID with the custom board options if the board name is absent (no programmer)', () => {
401+
const board = { fqbn: 'a:b:c:UsbMode=default' };
402+
const actual = createName(board, undefined);
403+
assert.strictEqual(actual, 'Arduino (a:b:c:UsbMode=default)');
404+
});
405+
389406
it('should use the board name', () => {
390407
const board = { fqbn: 'a:b:c', name: 'board name' };
391408
const programmer = 'p1';
392409
const actual = createName(board, programmer);
393410
assert.strictEqual(actual, 'board name (p1)');
394411
});
395412

413+
it('should use the board name (no programmer)', () => {
414+
const board = { fqbn: 'a:b:c', name: 'board name' };
415+
const actual = createName(board, undefined);
416+
assert.strictEqual(actual, 'board name');
417+
});
418+
396419
it('should use the board name and all custom board options', () => {
397420
const board = { fqbn: 'a:b:c:UsbMode=default', name: 'board name' };
398421
const programmer = 'p1';
399422
const actual = createName(board, programmer);
400423
assert.strictEqual(actual, 'board name (UsbMode=default,p1)');
401424
});
425+
426+
it('should use the board name and all custom board options (no programmer)', () => {
427+
const board = { fqbn: 'a:b:c:UsbMode=default', name: 'board name' };
428+
const actual = createName(board, undefined);
429+
assert.strictEqual(actual, 'board name (UsbMode=default)');
430+
});
402431
});
403432

404433
describe('isCustomDebugConfig', () => {

‎src/test/testEnv.ts

Copy file name to clipboardExpand all lines: src/test/testEnv.ts
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ async function prepareWithCli(params: PrepareTestEnvParams): Promise<void> {
139139
log(`Installing ${toInstall}...`);
140140
const args = ['core', 'install', toInstall, '--skip-post-install'];
141141
await cliExec(args, cliConfigPath);
142-
log(`Done. Installed ${platform}`);
142+
log(`Done. Installed ${toInstall}`);
143143
}
144144
log('Done');
145145
}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.