Skip to content

Commit fe0a1c9

Browse files
committed
Fix logic for testing tasks that depend on the current location
1 parent 62e35d7 commit fe0a1c9

File tree

3 files changed

+58
-37
lines changed

3 files changed

+58
-37
lines changed

integration/vscode/ada/src/taskProviders.ts

Lines changed: 27 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -823,19 +823,37 @@ abstract class SequentialExecution extends vscode.CustomExecution {
823823
}
824824

825825
/**
826-
* Task names contributed by the extension don't have the task type prefix
827-
* while tasks coming from the workspace typically do since VS Code includes
828-
* the type prefix when converting an automatic extension task into a
829-
* configurable workspace task. getConventionalTaskLabel() takes care of
830-
* that fact.
826+
* Finds and returns the task of the given name.
827+
*
828+
* Task names contributed by the extension don't have the task type prefix in
829+
* the name while tasks coming from the workspace typically do since VS Code
830+
* includes the type prefix when converting an automatic extension task into a
831+
* configurable workspace task. This function accounts for that fact by search
832+
* for the task with and without the type prefix.
833+
*
834+
* If an array of tasks is given, the search will applied to this array and the
835+
* API will not be queried for tasks. This can be used to achieve a performance
836+
* boost.
831837
*
832838
* @returns the task that has the given name, or the given name with the
833-
* prefix `ada: `.
839+
* prefix `ada: ` or `spark: `.
834840
* @throws an Error if the task is not found.
835841
*/
836-
export function findTaskByName(tasks: vscode.Task[], taskName: string): vscode.Task {
842+
export async function findTaskByName(
843+
taskName: string,
844+
tasks?: vscode.Task[]
845+
): Promise<vscode.Task> {
846+
if (!tasks) {
847+
tasks = (
848+
await Promise.all([
849+
vscode.tasks.fetchTasks({ type: 'ada' }),
850+
vscode.tasks.fetchTasks({ type: 'spark' }),
851+
])
852+
).flat();
853+
}
854+
837855
if (tasks.length == 0) {
838-
throw Error('The given task list is empty.' + ` Cannot find task '${taskName}'`);
856+
throw Error('The task list is empty.' + ` Cannot find task '${taskName}'`);
839857
}
840858

841859
const task = tasks.find((v) => {
@@ -862,7 +880,7 @@ class SequentialExecutionByName extends SequentialExecution {
862880

863881
protected async getTasksToRun(): Promise<vscode.Task[]> {
864882
const adaTasks = await vscode.tasks.fetchTasks({ type: TASK_TYPE_ADA });
865-
return this.taskNames.map((name) => findTaskByName(adaTasks, name));
883+
return Promise.all(this.taskNames.map((name) => findTaskByName(name, adaTasks)));
866884
}
867885
}
868886

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

Lines changed: 27 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ ada: Clean current project - gprclean -P ${projectPath}
5555
ada: Build current project - gprbuild -P ${projectPath} -cargs:ada -gnatef
5656
ada: Check current file - gprbuild -q -f -c -u -gnatc -P ${projectPath} \${fileBasename} -cargs:ada -gnatef
5757
ada: Analyze the project with GNAT SAS - gnatsas analyze -P ${projectPath}
58-
ada: Analyze the current file with GNAT SAS - gnatsas analyze -P ${projectPath} \${fileBasename}
58+
ada: Analyze the current file with GNAT SAS - gnatsas analyze -P ${projectPath} --file=\${fileBasename}
5959
ada: Create a report after a GNAT SAS analysis - gnatsas report sarif -P ${projectPath}
6060
ada: Generate documentation from the project - gnatdoc -P ${projectPath}
6161
ada: Create/update test skeletons for the project - gnattest -P ${projectPath}
@@ -212,21 +212,21 @@ suite('Task Execution', function () {
212212
allProvidedTasks.push(...(await createAdaTaskProvider().provideTasks()));
213213
});
214214

215-
declTaskTest('ada: Build current project', testedTaskLabels);
216-
declTaskTest('ada: Run main - src/main1.adb', testedTaskLabels);
217-
declTaskTest('ada: Run main - src/test.adb', testedTaskLabels);
218-
declTaskTest('ada: Check current file', testedTaskLabels, openSrcFile);
219-
declTaskTest('ada: Clean current project', testedTaskLabels);
220-
declTaskTest('ada: Build main - src/main1.adb', testedTaskLabels);
221-
declTaskTest('ada: Build main - src/test.adb', testedTaskLabels);
222-
declTaskTest('ada: Build and run main - src/main1.adb', testedTaskLabels);
223-
declTaskTest('ada: Build and run main - src/test.adb', testedTaskLabels);
224-
declTaskTest('ada: Analyze the project with GNAT SAS', testedTaskLabels);
225-
declTaskTest('ada: Create a report after a GNAT SAS analysis', testedTaskLabels);
226-
declTaskTest('ada: Analyze the project with GNAT SAS and produce a report', testedTaskLabels);
227-
declTaskTest('ada: Analyze the current file with GNAT SAS', testedTaskLabels, openSrcFile);
228-
declTaskTest('ada: Generate documentation from the project', testedTaskLabels);
229-
declTaskTest('ada: Create/update test skeletons for the project', testedTaskLabels);
215+
declTaskTest('ada: Build current project');
216+
declTaskTest('ada: Run main - src/main1.adb');
217+
declTaskTest('ada: Run main - src/test.adb');
218+
declTaskTest('ada: Check current file', openSrcFile);
219+
declTaskTest('ada: Clean current project');
220+
declTaskTest('ada: Build main - src/main1.adb');
221+
declTaskTest('ada: Build main - src/test.adb');
222+
declTaskTest('ada: Build and run main - src/main1.adb');
223+
declTaskTest('ada: Build and run main - src/test.adb');
224+
declTaskTest('ada: Analyze the project with GNAT SAS');
225+
declTaskTest('ada: Create a report after a GNAT SAS analysis');
226+
declTaskTest('ada: Analyze the project with GNAT SAS and produce a report');
227+
declTaskTest('ada: Analyze the current file with GNAT SAS', openSrcFile);
228+
declTaskTest('ada: Generate documentation from the project');
229+
declTaskTest('ada: Create/update test skeletons for the project');
230230

231231
/**
232232
* Check that the 'buildAndRunMain' task works fine with projects that
@@ -249,8 +249,8 @@ suite('Task Execution', function () {
249249
await new Promise((resolve) => setTimeout(resolve, 1000));
250250
await testTask(
251251
'Build and run main - src/main1.adb',
252-
allProvidedTasks,
253-
testedTaskLabels
252+
testedTaskLabels,
253+
allProvidedTasks
254254
);
255255
} finally {
256256
// Reset the 'ada.projectFile' setting. If the previous value was
@@ -314,20 +314,23 @@ suite('Task Execution', function () {
314314
* has to be defined in the same module as the testsuite in order for the
315315
* testing GUI to detect the tests in VS Code.
316316
*/
317-
function declTaskTest(
318-
taskName: string,
319-
testedTasks: Set<string>,
320-
prolog?: () => void | Promise<void>
321-
): Mocha.Test {
317+
function declTaskTest(taskName: string, prolog?: () => void | Promise<void>): Mocha.Test {
322318
return test(taskName, async function () {
323319
if (prolog) {
324320
await prolog();
325321
}
326322

327-
await testTask(taskName, allProvidedTasks, testedTasks);
323+
/**
324+
* If there was a prolog, don't use the static task list computed at
325+
* the beginning. Tasks are sensitive to the current cursor location
326+
* so we recompute available tasks instead of using the static task
327+
* list.
328+
*/
329+
await testTask(taskName, testedTaskLabels, prolog ? undefined : allProvidedTasks);
328330
});
329331
}
330332
});
333+
331334
async function openSrcFile() {
332335
assert(vscode.workspace.workspaceFolders);
333336
const testAdbUri = vscode.Uri.joinPath(

integration/vscode/ada/test/suite/utils.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@ import assert from 'assert';
22
import { spawnSync } from 'child_process';
33
import { existsSync, readFileSync, writeFileSync } from 'fs';
44
import * as vscode from 'vscode';
5+
import { setTerminalEnvironment } from '../../src/helpers';
56
import {
67
SimpleTaskProvider,
78
findTaskByName,
89
getConventionalTaskLabel,
910
} from '../../src/taskProviders';
10-
import { setTerminalEnvironment } from '../../src/helpers';
1111

1212
/**
1313
* This function compares some actual output to an expected referenced stored in
@@ -142,12 +142,12 @@ export function getCmdLine(exec: vscode.ShellExecution) {
142142

143143
export async function testTask(
144144
taskName: string,
145-
allProvidedTasks: vscode.Task[],
146-
testedTasks: Set<string>
145+
testedTasks: Set<string>,
146+
allProvidedTasks?: vscode.Task[]
147147
) {
148148
assert(vscode.workspace.workspaceFolders);
149149

150-
const task = findTaskByName(allProvidedTasks, taskName);
150+
const task = await findTaskByName(taskName, allProvidedTasks);
151151
assert(task);
152152
testedTasks.add(getConventionalTaskLabel(task));
153153

0 commit comments

Comments
 (0)