Skip to content

Commit 27dd425

Browse files
committed
Update tests related to vscode tasks
1 parent 0a75d7c commit 27dd425

File tree

4 files changed

+124
-52
lines changed

4 files changed

+124
-52
lines changed
Lines changed: 122 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1,67 +1,140 @@
1-
import * as vscode from 'vscode';
2-
import * as assert from 'assert';
3-
import * as path from 'path';
1+
import assert from 'assert';
42
import { suite, test } from 'mocha';
3+
import * as vscode from 'vscode';
54
import { contextClients } from '../../../src/extension';
5+
import {
6+
CustomTaskDefinition,
7+
PROJECT_FROM_CONFIG,
8+
createAdaTaskProvider,
9+
createSparkTaskProvider,
10+
} from '../../../src/taskProviders';
611
import { activate } from '../utils';
7-
import GprTaskProvider, { fullCommand } from '../../../src/gprTaskProvider';
812

913
suite('GPR Tasks Provider', function () {
1014
this.beforeAll(async () => {
1115
await activate();
1216
});
1317

14-
const expectedTasksNames: string[] = [
15-
'Build Main: gnatpp.adb',
16-
'Build Main: test.adb',
17-
'Build And Run Main: gnatpp.adb',
18-
'Build And Run Main: test.adb',
19-
];
18+
test('Ada tasks list', async () => {
19+
const prov = createAdaTaskProvider();
20+
const tasks = await prov.provideTasks();
21+
assert.notStrictEqual(tasks, undefined);
22+
23+
const expectedTasksNames: string[] = [
24+
'ada: Build current project',
25+
'ada: Check current file',
26+
'ada: Clean current project',
27+
'ada: Build main - main1.adb',
28+
'ada: Build and run main - main1.adb',
29+
'ada: Build main - test.adb',
30+
'ada: Build and run main - test.adb',
31+
];
32+
33+
assert.strictEqual(
34+
tasks.map((t) => `${t.source}: ${t.name}`).join('\n'),
35+
expectedTasksNames.join('\n')
36+
);
37+
});
2038

21-
test('Fetching tasks', async () => {
39+
test('Spark tasks list', async () => {
2240
await contextClients.adaClient.onReady();
23-
const prov = new GprTaskProvider(contextClients.adaClient);
41+
const prov = createSparkTaskProvider();
2442
const tasks = await prov.provideTasks();
2543
assert.notStrictEqual(tasks, undefined);
26-
if (tasks != undefined) {
27-
for (let i = 0; i < tasks.length; i++) {
28-
assert.strictEqual(tasks[i].name, expectedTasksNames[i]);
29-
}
30-
}
31-
});
32-
test('Command Generation', () => {
33-
const expectedCmd = 'gprbuild -c -u -P default.gpr "folder/src folder/file.adb" ';
34-
const args = [
35-
'-c',
36-
' -u ',
37-
' -P',
38-
'default.gpr ',
39-
' "folder/src folder/file.adb" ',
44+
const expectedTasksNames: string[] = [
45+
'spark: Clean project for proof',
46+
'spark: Examine project',
47+
'spark: Examine file',
48+
'spark: Examine subprogram',
49+
'spark: Prove project',
50+
'spark: Prove file',
51+
'spark: Prove subprogram',
52+
'spark: Prove selected region',
53+
'spark: Prove line',
4054
];
41-
const cmd = fullCommand('gprbuild', args);
42-
assert.strictEqual(cmd, expectedCmd);
43-
});
44-
test('Tasks resolving', async () => {
45-
const prov = new GprTaskProvider(contextClients.adaClient);
46-
const task = new vscode.Task(
47-
{ type: 'gpr', main: path.join('src', 'program.adb') },
48-
'build main',
49-
'tasks'
55+
assert.strictEqual(
56+
tasks.map((t) => `${t.source}: ${t.name}`).join('\n'),
57+
expectedTasksNames.join('\n')
5058
);
51-
const workspace = vscode.workspace.workspaceFolders?.at(0)?.uri.fsPath;
52-
if (workspace == undefined) {
53-
throw new Error('No workspace found');
54-
}
55-
const expectedCmd =
56-
'gprbuild -d -P ' +
57-
path.join(workspace, 'default.gpr') +
58-
' ' +
59-
path.join('src', 'program.adb ');
59+
});
60+
61+
test('Resolving task', async () => {
62+
const prov = createAdaTaskProvider();
63+
64+
const def: CustomTaskDefinition = {
65+
type: 'ada',
66+
configuration: {
67+
kind: 'buildProject',
68+
projectFile: PROJECT_FROM_CONFIG,
69+
},
70+
};
71+
const task = new vscode.Task(def, vscode.TaskScope.Workspace, 'My Task', 'ada');
72+
const resolved = await prov.resolveTask(task);
73+
74+
assert(resolved);
75+
assert(resolved.execution);
76+
77+
const exec = resolved.execution as vscode.ShellExecution;
78+
const actualCmd = [exec.command].concat(exec.args).join(' ');
79+
80+
const expectedCmd = `gprbuild -P ${def.configuration.projectFile} -cargs -gnatef`;
81+
82+
assert.strictEqual(actualCmd, expectedCmd);
83+
});
84+
85+
test('Resolving task with main', async () => {
86+
const prov = createAdaTaskProvider();
87+
88+
const def: CustomTaskDefinition = {
89+
type: 'ada',
90+
configuration: {
91+
kind: 'buildMain',
92+
projectFile: PROJECT_FROM_CONFIG,
93+
main: 'src/program.adb',
94+
},
95+
};
96+
const task = new vscode.Task(def, vscode.TaskScope.Workspace, 'My Task', 'ada');
6097
const resolved = await prov.resolveTask(task);
61-
assert.notStrictEqual(resolved, undefined);
62-
if (resolved != undefined && resolved.execution) {
63-
const exec = resolved.execution as vscode.ShellExecution;
64-
assert.strictEqual(exec.commandLine, expectedCmd);
65-
}
98+
99+
assert(resolved);
100+
assert(resolved.execution);
101+
102+
const exec = resolved.execution as vscode.ShellExecution;
103+
const actualCmd = [exec.command].concat(exec.args).join(' ');
104+
105+
const expectedCmd = `gprbuild -P ${def.configuration.projectFile} ${
106+
def.configuration.main ?? ''
107+
} -cargs -gnatef`;
108+
109+
assert.strictEqual(actualCmd, expectedCmd);
110+
});
111+
112+
test('Resolving task with run main', async () => {
113+
const prov = createAdaTaskProvider();
114+
115+
const def: CustomTaskDefinition = {
116+
type: 'ada',
117+
configuration: {
118+
kind: 'buildAndRunMain',
119+
projectFile: PROJECT_FROM_CONFIG,
120+
main: 'src/main1.adb',
121+
},
122+
};
123+
const task = new vscode.Task(def, vscode.TaskScope.Workspace, 'My Task', 'ada');
124+
const resolved = await prov.resolveTask(task);
125+
126+
assert(resolved);
127+
assert(resolved.execution);
128+
129+
const exec = resolved.execution as vscode.ShellExecution;
130+
const actualCmd = [exec.command].concat(exec.args).join(' ');
131+
132+
// Note that the executable is named differently than the source file
133+
// via project attributes
134+
const expectedCmd = `gprbuild -P ${def.configuration.projectFile} ${
135+
def.configuration.main ?? ''
136+
} -cargs -gnatef && obj/main1exec`;
137+
138+
assert.strictEqual(actualCmd, expectedCmd);
66139
});
67140
});

integration/vscode/ada/test/workspaces/general/default.gpr

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,15 @@
11
project Default is
22

33
Tools_Mains :=
4-
("gnatpp.adb",
4+
("main1.adb",
55
"test.adb");
66

77
for Source_Dirs use ("src/**");
88
for Object_Dir use "obj";
99
for Main use Tools_Mains;
1010

1111
package Builder is
12-
for Executable ("gnatpp.adb") use "gnatpp";
13-
for Executable ("test.adb") use "test";
12+
for Executable ("main1.adb") use "main1exec";
1413
end Builder;
1514

1615
package Compiler is

0 commit comments

Comments
 (0)