|
1 |
| -import * as vscode from 'vscode'; |
2 |
| -import * as assert from 'assert'; |
3 |
| -import * as path from 'path'; |
| 1 | +import assert from 'assert'; |
4 | 2 | import { suite, test } from 'mocha';
|
| 3 | +import * as vscode from 'vscode'; |
5 | 4 | import { contextClients } from '../../../src/extension';
|
| 5 | +import { |
| 6 | + CustomTaskDefinition, |
| 7 | + PROJECT_FROM_CONFIG, |
| 8 | + createAdaTaskProvider, |
| 9 | + createSparkTaskProvider, |
| 10 | +} from '../../../src/taskProviders'; |
6 | 11 | import { activate } from '../utils';
|
7 |
| -import GprTaskProvider, { fullCommand } from '../../../src/gprTaskProvider'; |
8 | 12 |
|
9 | 13 | suite('GPR Tasks Provider', function () {
|
10 | 14 | this.beforeAll(async () => {
|
11 | 15 | await activate();
|
12 | 16 | });
|
13 | 17 |
|
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 | + }); |
20 | 38 |
|
21 |
| - test('Fetching tasks', async () => { |
| 39 | + test('Spark tasks list', async () => { |
22 | 40 | await contextClients.adaClient.onReady();
|
23 |
| - const prov = new GprTaskProvider(contextClients.adaClient); |
| 41 | + const prov = createSparkTaskProvider(); |
24 | 42 | const tasks = await prov.provideTasks();
|
25 | 43 | 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', |
40 | 54 | ];
|
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') |
50 | 58 | );
|
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'); |
60 | 97 | 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); |
66 | 139 | });
|
67 | 140 | });
|
0 commit comments