Skip to content

Commit 1d46671

Browse files
committed
Merge branch 'topic/testsUpdate' into 'master'
Reorganize VSCode Tests Closes #1169 See merge request eng/ide/ada_language_server!1278
2 parents 9a70149 + 82eb34b commit 1d46671

File tree

89 files changed

+588
-465
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

89 files changed

+588
-465
lines changed

.vscode/launch.json

Lines changed: 23 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,14 @@
1111
"cwd": "${workspaceRoot}",
1212
"valuesFormatting": "parseText"
1313
},
14+
{
15+
"type": "gdb",
16+
"request": "launch",
17+
"name": "Launch Program",
18+
"target": ".obj/server/ada_language_server",
19+
"cwd": "${workspaceRoot}",
20+
"valuesFormatting": "parseText"
21+
},
1422
{
1523
"name": "Launch Extension",
1624
"type": "extensionHost",
@@ -47,40 +55,15 @@
4755
}
4856
},
4957
{
50-
"name": "Extension Tests",
51-
"type": "extensionHost",
58+
"name": "Launch Extension Testsuite",
59+
"type": "node",
5260
"request": "launch",
53-
"runtimeExecutable": "${execPath}",
54-
"outFiles": [
55-
"${workspaceFolder}/integration/vscode/ada/out/**/*.js",
56-
"!**/node_modules/**"
57-
],
58-
"args": [
59-
"--extensionDevelopmentPath=${workspaceFolder}/integration/vscode/ada",
60-
"--extensionTestsPath=${workspaceFolder}/integration/vscode/ada/out/test/suite/index",
61-
"${workspaceFolder}/integration/vscode/ada/test/TestWorkspace"
62-
],
63-
// Below we make the executables of node modules visible to the tests.
64-
// In particular, vscode-tmgrammar-snap is used for syntax highlighting
65-
// tests.
66-
"env": {
67-
// This is necessary to make the "child" vscode inherit the PATH
68-
// variable set in the workspace settings. Without it in some setups
69-
// (e.g. vscode remote) the child vscode does not get visibility
70-
// over the Ada toolchain available in the parent vscode
71-
// environment.
72-
"PATH": "${env:PATH}",
73-
// This is custom env var that we use in
74-
// integration/vscode/ada/test/suite/index.ts to prevent timeouts in
75-
// tests when debugging
76-
"MOCHA_TIMEOUT": "0"
77-
},
78-
"preLaunchTask": "npm: pretest",
79-
// Switch to Debug Console to see test results
80-
"internalConsoleOptions": "openOnSessionStart"
61+
"cwd": "${workspaceFolder}/integration/vscode/ada/",
62+
"runtimeExecutable": "npm",
63+
"runtimeArgs": ["run-script", "test"]
8164
},
8265
{
83-
"name": "Extension Tests (Update Test Refs)",
66+
"name": "General Testsuite",
8467
"type": "extensionHost",
8568
"request": "launch",
8669
"runtimeExecutable": "${execPath}",
@@ -90,13 +73,14 @@
9073
],
9174
"args": [
9275
"--extensionDevelopmentPath=${workspaceFolder}/integration/vscode/ada",
93-
"--extensionTestsPath=${workspaceFolder}/integration/vscode/ada/out/test/suite/index",
94-
"${workspaceFolder}/integration/vscode/ada/test/TestWorkspace"
76+
"--extensionTestsPath=${workspaceFolder}/integration/vscode/ada/out/test/suite/general/index",
77+
"${workspaceFolder}/integration/vscode/ada/test/workspaces/general"
9578
],
9679
// Below we make the executables of node modules visible to the tests.
9780
// In particular, vscode-tmgrammar-snap is used for syntax highlighting
9881
// tests.
9982
"env": {
83+
"MOCHA_GREP": "${input:testPattern}",
10084
// This is necessary to make the "child" vscode inherit the PATH
10185
// variable set in the workspace settings. Without it in some setups
10286
// (e.g. vscode remote) the child vscode does not get visibility
@@ -107,26 +91,13 @@
10791
// integration/vscode/ada/test/suite/index.ts to prevent timeouts in
10892
// tests when debugging
10993
"MOCHA_TIMEOUT": "0",
110-
// Setting this environment variable causes the tests to overwrite
111-
// previous test references when they are stored in files. See
112-
// assertEqualToFileContent in
113-
// integration/vscode/ada/test/suite/highlighting.test.ts
114-
"MOCHA_ALS_UPDATE": "1"
94+
"MOCHA_ALS_UPDATE": "${input:updateTestRefs}"
11595
},
11696
"preLaunchTask": "npm: pretest",
117-
// Switch to Debug Console to see test results
11897
"internalConsoleOptions": "openOnSessionStart"
11998
},
12099
{
121-
"type": "gdb",
122-
"request": "launch",
123-
"name": "Launch Program",
124-
"target": ".obj/server/ada_language_server",
125-
"cwd": "${workspaceRoot}",
126-
"valuesFormatting": "parseText"
127-
},
128-
{
129-
"name": "Extension Tests (Test Name Regexp)",
100+
"name": "GNATtest Integration Testsuite",
130101
"type": "extensionHost",
131102
"request": "launch",
132103
"runtimeExecutable": "${execPath}",
@@ -136,8 +107,8 @@
136107
],
137108
"args": [
138109
"--extensionDevelopmentPath=${workspaceFolder}/integration/vscode/ada",
139-
"--extensionTestsPath=${workspaceFolder}/integration/vscode/ada/out/test/suite/index",
140-
"${workspaceFolder}/integration/vscode/ada/test/TestWorkspace"
110+
"--extensionTestsPath=${workspaceFolder}/integration/vscode/ada/out/test/suite/gnattest/index",
111+
"${workspaceFolder}/integration/vscode/ada/test/workspaces/gnattest"
141112
],
142113
// Below we make the executables of node modules visible to the tests.
143114
// In particular, vscode-tmgrammar-snap is used for syntax highlighting
@@ -164,14 +135,13 @@
164135
"inputs": [
165136
{
166137
"id": "testPattern",
167-
"description": "A regexp of tests to run",
138+
"description": "A regexp of tests to run. Keep empty for not filtering any",
168139
"type": "promptString"
169140
},
170141
{
171142
"id": "updateTestRefs",
172143
"description": "Update test references? Keep empty for no update",
173-
"type": "promptString",
174-
"default": ""
144+
"type": "promptString"
175145
},
176146
{
177147
"id": "pid",
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# GNATtest for VSCODE
2+
3+
## How to use it:
4+
- First go to the Test View in you editor.
5+
- Then you can generate tests using GNATtest by clicking on `Configure Tests`
6+
- A pop-up must appear, so then you can select `GNATtest`.
7+
- You can then click on the refreash button to discover the tests in your project.
8+
- If your folder already have GNATtest generated tests then you should have the tests already visible to you in the View.
9+
10+
** **
11+
12+
## Support
13+
#### Running Tests
14+
15+
You can either run tests, by unit or by test case or run them all at once.
16+
17+
#### Revealing the test results
18+
19+
The messages shown in the UI about the fail of a test are limited, if you want the full summary you can check the file in: `<object_dir>/gnattest/result.txt`
20+
21+
** **
22+
23+
### Limitations
24+
25+
- Inheritence tests are ignored.
26+
-

integration/vscode/ada/src/gnattest.ts

Lines changed: 25 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,13 @@ import { ContextClients } from './clients';
66
import { getProjectFile, getObjectDir } from './helpers';
77
import { integer } from 'vscode-languageclient';
88

9+
export let controller: vscode.TestController;
10+
export let testRunProfile: vscode.TestRunProfile;
11+
912
/*
1013
Types definition for the Gnattest XML file structure
1114
*/
12-
type Root = {
15+
export type Root = {
1316
tests_mapping: TestMapping;
1417
};
1518

@@ -33,7 +36,6 @@ type Tested = {
3336
'@_line': string;
3437
'@_name': string;
3538
test_case: TestCase | [TestCase];
36-
test: Test;
3739
};
3840

3941
type TestCase = {
@@ -55,7 +57,7 @@ export async function initializeTestView(
5557
clients: ContextClients
5658
) {
5759
if (vscode.workspace.workspaceFolders !== undefined) {
58-
const controller = vscode.tests.createTestController(
60+
controller = vscode.tests.createTestController(
5961
'gnattest-test-controller',
6062
'GNATtest Test Controller'
6163
);
@@ -65,8 +67,7 @@ export async function initializeTestView(
6567
// Getting Paths Information from the server
6668
const projectFile = await getProjectFile(clients.adaClient);
6769
const objectDir: string = await getObjectDir(clients.adaClient);
68-
let gnattestPath = vscode.workspace.asRelativePath(objectDir);
69-
gnattestPath = path.join(gnattestPath, 'gnattest');
70+
const gnattestPath = path.join(objectDir, 'gnattest');
7071

7172
startTestRun(controller, projectFile, gnattestPath);
7273
await discoverTests(controller, gnattestPath);
@@ -124,7 +125,7 @@ function startTestRun(
124125
}
125126
};
126127

127-
const testRunProfile = controller.createRunProfile(
128+
testRunProfile = controller.createRunProfile(
128129
'GNATtest',
129130
vscode.TestRunProfileKind.Run,
130131
runHandler,
@@ -149,7 +150,7 @@ function startTestRun(
149150
/*
150151
Run all tests handler
151152
*/
152-
function handleRunAll(
153+
export function handleRunAll(
153154
tests: vscode.TestItem[],
154155
run: vscode.TestRun,
155156
terminalName: string,
@@ -208,7 +209,7 @@ function handleUnitRun(
208209
/*
209210
Resolves Tests to run for a selected test item in the Explorer
210211
*/
211-
function gatherChildTestItems(
212+
export function gatherChildTestItems(
212213
collection: vscode.TestItemCollection | readonly vscode.TestItem[]
213214
): vscode.TestItem[] {
214215
let items: vscode.TestItem[] = [];
@@ -226,7 +227,7 @@ function gatherChildTestItems(
226227
Gets the Source file name for a test item
227228
Needed for the --routines switch
228229
*/
229-
function getParentTestSourceName(item: vscode.TestItem) {
230+
export function getParentTestSourceName(item: vscode.TestItem) {
230231
let parent: vscode.TestItem = item;
231232
if (item.parent != undefined) {
232233
parent = getParentTestSourceName(item.parent);
@@ -237,12 +238,10 @@ function getParentTestSourceName(item: vscode.TestItem) {
237238
/*
238239
Return the test_runner output stored in the result.txt file
239240
*/
240-
async function readResultFile(resultPath: string) {
241+
export async function readResultFile(resultPath: string) {
241242
if (vscode.workspace.workspaceFolders !== undefined) {
242-
const main_path = vscode.workspace.workspaceFolders[0].uri.path;
243-
const full_result_path = path.join(main_path, resultPath);
244-
if (pathExists(full_result_path)) {
245-
const file = await vscode.workspace.fs.readFile(vscode.Uri.file(full_result_path));
243+
if (pathExists(resultPath)) {
244+
const file = await vscode.workspace.fs.readFile(vscode.Uri.file(resultPath));
246245
return file.toString();
247246
}
248247
}
@@ -257,7 +256,11 @@ enum Test_State {
257256
/*
258257
Parses the result of the file 'result.txt'
259258
*/
260-
function parseResults(tests: vscode.TestItem[], run: vscode.TestRun, file: string) {
259+
export function parseResults(
260+
tests: vscode.TestItem[],
261+
run: vscode.TestRun | undefined,
262+
file: string
263+
): boolean {
261264
const matchs = file.match(
262265
/(^|\n)((\w|-)+).ad[b|s]:\d+:\d+: (info|error): corresponding test (\w+)/g
263266
);
@@ -271,7 +274,7 @@ function parseResults(tests: vscode.TestItem[], run: vscode.TestRun, file: strin
271274
const test_line: integer = p ? p + 1 : 0;
272275
const check_line = matchs[i].match(test_src.label + ':' + test_line.toString());
273276
// update the state of the test
274-
if (check_line != null) {
277+
if (check_line != null && run != undefined) {
275278
run.appendOutput(`Completed ${e.id}\r\n`);
276279
const mm: string = matchs[i].substring(matchs[i].length - 6, matchs[i].length);
277280
if (mm == Test_State.PASSED) {
@@ -282,13 +285,15 @@ function parseResults(tests: vscode.TestItem[], run: vscode.TestRun, file: strin
282285
}
283286
}
284287
}
288+
return true;
285289
}
290+
return false;
286291
}
287292

288293
/*
289294
Return the tests structure stored in gnattest.xml file
290295
*/
291-
async function readXMLfile(harnessPath: string): Promise<string | undefined> {
296+
export async function readXMLfile(harnessPath: string): Promise<string | undefined> {
292297
if (vscode.workspace.workspaceFolders !== undefined) {
293298
const mainPath = vscode.workspace.workspaceFolders[0].uri.path;
294299
const fullHarnessPath = path.join(mainPath, harnessPath);
@@ -306,7 +311,7 @@ async function readXMLfile(harnessPath: string): Promise<string | undefined> {
306311
/*
307312
Discover tests by parsing the xml input
308313
*/
309-
async function discoverTests(controller: vscode.TestController, gnattestPath: string) {
314+
export async function discoverTests(controller: vscode.TestController, gnattestPath: string) {
310315
if (vscode.workspace.workspaceFolders !== undefined) {
311316
const mainPath = vscode.workspace.workspaceFolders[0].uri.path;
312317
const file = await readXMLfile(path.join(gnattestPath, 'harness'));
@@ -325,8 +330,10 @@ async function discoverTests(controller: vscode.TestController, gnattestPath: st
325330
} else {
326331
addUnitTestItems(rootNode.unit, controller, mainPath);
327332
}
333+
return xmlDoc;
328334
}
329335
}
336+
return undefined;
330337
}
331338

332339
/*

integration/vscode/ada/src/gprTaskProvider.ts

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -51,11 +51,7 @@ export default class GprTaskProvider implements vscode.TaskProvider<vscode.Task>
5151
return this.glsTasks;
5252
}
5353

54-
async resolveTask(
55-
task: vscode.Task,
56-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
57-
_token: vscode.CancellationToken
58-
): Promise<vscode.Task | undefined> {
54+
async resolveTask(task: vscode.Task): Promise<vscode.Task | undefined> {
5955
const definition = task.definition;
6056
// Make sure that this looks like a execute task by checking that there is a projectFile.
6157
if (definition.type == GprTaskProvider.gprTaskType) {
@@ -199,7 +195,7 @@ function getMainBuildArgs(projectFile?: string, mainFile?: string): string[] {
199195
* @param args - the list of arguments
200196
* @returns a string
201197
*/
202-
function fullCommand(command: string, args: string[]) {
198+
export function fullCommand(command: string, args: string[]) {
203199
let cmd: string = command + ' ';
204200
for (const arg of args) {
205201
cmd += arg.replace(/^\s+|\s+$/g, '') + ' ';

integration/vscode/ada/test/TestWorkspace/src/highlighting/obsolescent/pkg_with_obsolescent_members.ads

Lines changed: 0 additions & 16 deletions
This file was deleted.

integration/vscode/ada/test/TestWorkspace/src/highlighting/obsolescent/pkg_with_obsolescent_members.ads.sem.tokens

Lines changed: 0 additions & 5 deletions
This file was deleted.

0 commit comments

Comments
 (0)