Skip to content

Commit 22ec0e3

Browse files
committed
Add testing of tasks based on current location
1 parent 53859ce commit 22ec0e3

File tree

3 files changed

+91
-1
lines changed

3 files changed

+91
-1
lines changed

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

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ import {
88
PROJECT_FROM_CONFIG,
99
createAdaTaskProvider,
1010
createSparkTaskProvider,
11+
getEnclosingSymbol,
12+
getSelectedRegion,
1113
} from '../../../src/taskProviders';
1214
import { activate } from '../utils';
1315

@@ -277,6 +279,79 @@ ada: Build and run main - src/test.adb - kind: buildAndRunMain`.trim();
277279
assert(resolved);
278280
assert.equal(await runTaskAndGetResult(resolved), 2);
279281
});
282+
283+
test('current regions and subprograms', async () => {
284+
assert(vscode.workspace.workspaceFolders);
285+
const testAdbUri = vscode.Uri.joinPath(
286+
vscode.workspace.workspaceFolders[0].uri,
287+
'src',
288+
'test.adb'
289+
);
290+
291+
/**
292+
* Position the cursor within the nested P3 subprogram
293+
*/
294+
await vscode.window.showTextDocument(testAdbUri, {
295+
selection: new vscode.Range(17, 13, 17, 13),
296+
});
297+
assert.deepEqual(
298+
(await getEnclosingSymbol(vscode.window.activeTextEditor, [vscode.SymbolKind.Function]))
299+
?.range,
300+
// The expected range is that of the inner-most subprogram P3
301+
new vscode.Range(13, 9, 18, 16)
302+
);
303+
assert.equal(getSelectedRegion(vscode.window.activeTextEditor), '18:18');
304+
305+
/**
306+
* Select a multi-line range
307+
*/
308+
await vscode.window.showTextDocument(testAdbUri, {
309+
selection: new vscode.Range(15, 13, 17, 13),
310+
});
311+
assert.equal(getSelectedRegion(vscode.window.activeTextEditor), '16:18');
312+
});
313+
314+
test('spark tasks on current location', async () => {
315+
assert(vscode.workspace.workspaceFolders);
316+
const testAdbUri = vscode.Uri.joinPath(
317+
vscode.workspace.workspaceFolders[0].uri,
318+
'src',
319+
'test.adb'
320+
);
321+
322+
{
323+
await vscode.window.showTextDocument(testAdbUri, {
324+
selection: new vscode.Range(17, 13, 17, 13),
325+
});
326+
const tasks = await vscode.tasks.fetchTasks({ type: 'spark' });
327+
const subPTask = tasks.find((t) => t.name == 'Prove subprogram');
328+
assert(subPTask);
329+
assert(subPTask.execution);
330+
assert.equal(
331+
getCmdLine(subPTask.execution as vscode.ShellExecution),
332+
`gnatprove -j0 -P ${await getProjectFile()} ` +
333+
`--limit-subp=\${fileBasename}:14 -cargs:ada -gnatef`
334+
);
335+
}
336+
337+
{
338+
await vscode.window.showTextDocument(testAdbUri, {
339+
selection: new vscode.Range(20, 0, 23, 0),
340+
});
341+
/**
342+
* Compute the tasks again after the change of selection
343+
*/
344+
const tasks = await vscode.tasks.fetchTasks({ type: 'spark' });
345+
const regionTask = tasks.find((t) => t.name == 'Prove selected region');
346+
assert(regionTask);
347+
assert(regionTask.execution);
348+
assert.equal(
349+
getCmdLine(regionTask.execution as vscode.ShellExecution),
350+
`gnatprove -j0 -u \${fileBasename} -P ${await getProjectFile()} ` +
351+
`--limit-region=\${fileBasename}:21:24 -cargs:ada -gnatef`
352+
);
353+
}
354+
});
280355
});
281356

282357
async function runTaskAndGetResult(task: vscode.Task): Promise<number | undefined> {
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
package Bar is
2-
end Bar;
2+
end Bar;

integration/vscode/ada/test/workspaces/general/src/test.adb

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,21 @@ with Foo;
99

1010
procedure Test is
1111

12+
procedure P1 is
13+
procedure P2 is
14+
procedure P3 is
15+
begin
16+
null;
17+
null;
18+
null;
19+
end P3;
20+
begin
21+
null;
22+
end P2;
23+
begin
24+
null;
25+
end P1;
26+
1227
begin
1328

1429
null;

0 commit comments

Comments
 (0)