Skip to content

Commit 4710ba4

Browse files
committed
Add tests for the debug configuration provider
1 parent 728c6a5 commit 4710ba4

File tree

2 files changed

+123
-6
lines changed

2 files changed

+123
-6
lines changed

integration/vscode/ada/test/suite/general/debug.test.ts

Lines changed: 123 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,93 @@
11
import assert from 'assert';
22
import { suite, test } from 'mocha';
3-
import { AdaConfig, adaDynamicDebugConfigProvider } from '../../../src/debugConfigProvider';
3+
import {
4+
AdaConfig,
5+
adaDynamicDebugConfigProvider,
6+
createQuickPicksInitialLaunch,
7+
getOrFindGdb,
8+
} from '../../../src/debugConfigProvider';
9+
import { exe } from '../../../src/helpers';
410
import { activate } from '../utils';
11+
import { adaExtState } from '../../../src/extension';
512

613
suite('Debug Configurations', function () {
14+
let expectedConfigs: string;
15+
716
this.beforeAll(async () => {
817
await activate();
18+
expectedConfigs = `
19+
[
20+
{
21+
"type": "cppdbg",
22+
"name": "Ada: Debug main - src/main1.adb",
23+
"request": "launch",
24+
"targetArchitecture": "x64",
25+
"cwd": "\${workspaceFolder}",
26+
"program": "\${workspaceFolder}/obj/main1exec${exe}",
27+
"stopAtEntry": false,
28+
"externalConsole": false,
29+
"args": [],
30+
"MIMode": "gdb",
31+
"preLaunchTask": "ada: Build main - src/main1.adb",
32+
"setupCommands": [
33+
{
34+
"description": "Catch all Ada exceptions",
35+
"text": "catch exception",
36+
"ignoreFailures": true
37+
},
38+
{
39+
"description": "Enable pretty-printing for gdb",
40+
"text": "-enable-pretty-printing",
41+
"ignoreFailures": true
42+
}
43+
],
44+
"miDebuggerPath": "${getOrFindGdb() ?? '<undefined>'}"
45+
},
46+
{
47+
"name": "Ada: Attach debugger to running process - src/main1.adb",
48+
"type": "cppdbg",
49+
"request": "attach",
50+
"program": "\${workspaceFolder}/obj/main1exec${exe}",
51+
"processId": "\${command:pickProcess}",
52+
"MIMode": "gdb",
53+
"miDebuggerPath": "${getOrFindGdb() ?? '<undefined>'}"
54+
},
55+
{
56+
"type": "cppdbg",
57+
"name": "Ada: Debug main - src/test.adb",
58+
"request": "launch",
59+
"targetArchitecture": "x64",
60+
"cwd": "\${workspaceFolder}",
61+
"program": "\${workspaceFolder}/obj/test${exe}",
62+
"stopAtEntry": false,
63+
"externalConsole": false,
64+
"args": [],
65+
"MIMode": "gdb",
66+
"preLaunchTask": "ada: Build main - src/test.adb",
67+
"setupCommands": [
68+
{
69+
"description": "Catch all Ada exceptions",
70+
"text": "catch exception",
71+
"ignoreFailures": true
72+
},
73+
{
74+
"description": "Enable pretty-printing for gdb",
75+
"text": "-enable-pretty-printing",
76+
"ignoreFailures": true
77+
}
78+
],
79+
"miDebuggerPath": "${getOrFindGdb() ?? '<undefined>'}"
80+
},
81+
{
82+
"name": "Ada: Attach debugger to running process - src/test.adb",
83+
"type": "cppdbg",
84+
"request": "attach",
85+
"program": "\${workspaceFolder}/obj/test${exe}",
86+
"processId": "\${command:pickProcess}",
87+
"MIMode": "gdb",
88+
"miDebuggerPath": "${getOrFindGdb() ?? '<undefined>'}"
89+
}
90+
]`;
991
});
1092

1193
test('GDB path is explicitely set in offered debug config', async () => {
@@ -17,8 +99,7 @@ suite('Debug Configurations', function () {
1799
});
18100

19101
test('GDB path is the same for all configs', async () => {
20-
const configs =
21-
(await adaDynamicDebugConfigProvider.provideDebugConfigurations()) as AdaConfig[];
102+
const configs = await adaDynamicDebugConfigProvider.provideDebugConfigurations();
22103

23104
assert(configs.length > 1);
24105
const miDebuggerPath = configs.at(0)?.miDebuggerPath;
@@ -30,13 +111,50 @@ suite('Debug Configurations', function () {
30111
});
31112

32113
test('Two debug configs per main are proposed', async () => {
33-
const configs =
34-
(await adaDynamicDebugConfigProvider.provideDebugConfigurations()) as AdaConfig[];
114+
const configs = await adaDynamicDebugConfigProvider.provideDebugConfigurations();
35115
const expected = `
36116
Ada: Debug main - src/main1.adb
37117
Ada: Attach debugger to running process - src/main1.adb
38118
Ada: Debug main - src/test.adb
39119
Ada: Attach debugger to running process - src/test.adb`.trim();
40120
assert.equal(configs.map((v) => `${v.name}`).join('\n'), expected);
41121
});
122+
123+
test('Initial', async () => {
124+
const { quickpick } = await createQuickPicksInitialLaunch();
125+
126+
const expected = `
127+
Ada: Debug main - src/main1.adb
128+
Ada: Attach debugger to running process - src/main1.adb
129+
Ada: Debug main - src/test.adb
130+
Ada: Attach debugger to running process - src/test.adb
131+
132+
All of the above - Create all of the above configurations in the launch.json file`;
133+
assert.equal(
134+
quickpick
135+
.map((e) => `${e.label}${e.description ? ' - ' + e.description : ''}`)
136+
.join('\n'),
137+
expected.trim()
138+
);
139+
140+
assert.equal(
141+
JSON.stringify(
142+
quickpick
143+
.filter((e) => 'conf' in e)
144+
.map((e) => {
145+
assert('conf' in e);
146+
return e.conf;
147+
}),
148+
null,
149+
2
150+
).trim(),
151+
expectedConfigs.trim()
152+
);
153+
});
154+
155+
test('Dynamic', async () => {
156+
const configs = await adaExtState.dynamicDebugConfigProvider.provideDebugConfigurations();
157+
158+
assert.equal(JSON.stringify(configs, undefined, 2).trim(), expectedConfigs.trim());
159+
});
42160
});

integration/vscode/ada/test/suite/general/tasks.test.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import assert from 'assert';
22
import { existsSync } from 'fs';
33
import { suite, test } from 'mocha';
44
import * as vscode from 'vscode';
5-
import { adaExtState } from '../../../src/extension';
65
import { exe, getProjectFile } from '../../../src/helpers';
76
import {
87
CustomTaskDefinition,

0 commit comments

Comments
 (0)