Skip to content

Commit a1de5ad

Browse files
committed
Reorganize VSCode Tests
Add tests for GNATtest integration. Create multiple test runner scripts.
1 parent 9a70149 commit a1de5ad

File tree

25 files changed

+649
-278
lines changed

25 files changed

+649
-278
lines changed

.vscode/launch.json

Lines changed: 32 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@
4747
}
4848
},
4949
{
50-
"name": "Extension Tests",
50+
"name": "Highlighting Tests (Update tests ref)",
5151
"type": "extensionHost",
5252
"request": "launch",
5353
"runtimeExecutable": "${execPath}",
@@ -57,7 +57,7 @@
5757
],
5858
"args": [
5959
"--extensionDevelopmentPath=${workspaceFolder}/integration/vscode/ada",
60-
"--extensionTestsPath=${workspaceFolder}/integration/vscode/ada/out/test/suite/index",
60+
"--extensionTestsPath=${workspaceFolder}/integration/vscode/ada/out/test/suite/general/highlighting/index",
6161
"${workspaceFolder}/integration/vscode/ada/test/TestWorkspace"
6262
],
6363
// Below we make the executables of node modules visible to the tests.
@@ -73,14 +73,19 @@
7373
// This is custom env var that we use in
7474
// integration/vscode/ada/test/suite/index.ts to prevent timeouts in
7575
// tests when debugging
76-
"MOCHA_TIMEOUT": "0"
76+
"MOCHA_TIMEOUT": "0",
77+
// Setting this environment variable causes the tests to overwrite
78+
// previous test references when they are stored in files. See
79+
// assertEqualToFileContent in
80+
// integration/vscode/ada/test/suite/highlighting.test.ts
81+
"MOCHA_ALS_UPDATE": "1"
7782
},
7883
"preLaunchTask": "npm: pretest",
7984
// Switch to Debug Console to see test results
8085
"internalConsoleOptions": "openOnSessionStart"
8186
},
8287
{
83-
"name": "Extension Tests (Update Test Refs)",
88+
"name": "Server Extensions Tests",
8489
"type": "extensionHost",
8590
"request": "launch",
8691
"runtimeExecutable": "${execPath}",
@@ -90,31 +95,35 @@
9095
],
9196
"args": [
9297
"--extensionDevelopmentPath=${workspaceFolder}/integration/vscode/ada",
93-
"--extensionTestsPath=${workspaceFolder}/integration/vscode/ada/out/test/suite/index",
98+
"--extensionTestsPath=${workspaceFolder}/integration/vscode/ada/out/test/suite/general/serverExtensions/index",
9499
"${workspaceFolder}/integration/vscode/ada/test/TestWorkspace"
95100
],
96-
// Below we make the executables of node modules visible to the tests.
97-
// In particular, vscode-tmgrammar-snap is used for syntax highlighting
98-
// tests.
99101
"env": {
100-
// This is necessary to make the "child" vscode inherit the PATH
101-
// variable set in the workspace settings. Without it in some setups
102-
// (e.g. vscode remote) the child vscode does not get visibility
103-
// over the Ada toolchain available in the parent vscode
104-
// environment.
105102
"PATH": "${env:PATH}",
106-
// This is custom env var that we use in
107-
// integration/vscode/ada/test/suite/index.ts to prevent timeouts in
108-
// tests when debugging
109-
"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"
103+
"MOCHA_TIMEOUT": "0"
104+
},
105+
"preLaunchTask": "npm: pretest",
106+
"internalConsoleOptions": "openOnSessionStart"
107+
},
108+
{
109+
"name": "GNATtest Integration Tests",
110+
"type": "extensionHost",
111+
"request": "launch",
112+
"runtimeExecutable": "${execPath}",
113+
"outFiles": [
114+
"${workspaceFolder}/integration/vscode/ada/out/**/*.js",
115+
"!**/node_modules/**"
116+
],
117+
"args": [
118+
"--extensionDevelopmentPath=${workspaceFolder}/integration/vscode/ada",
119+
"--extensionTestsPath=${workspaceFolder}/integration/vscode/ada/out/test/suite/gnattest/index",
120+
"${workspaceFolder}/integration/vscode/ada/test/GnattestWorkspace"
121+
],
122+
"env": {
123+
"PATH": "${env:PATH}",
124+
"MOCHA_TIMEOUT": "0"
115125
},
116126
"preLaunchTask": "npm: pretest",
117-
// Switch to Debug Console to see test results
118127
"internalConsoleOptions": "openOnSessionStart"
119128
},
120129
{
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, '') + ' ';
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
include ../Makefile.inc
2+
3+
tagged_rec: tagged substitution
4+
5+
tagged:
6+
$(PREFIX)gnattest -Ptagged_rec.gpr $(QUIET)
7+
$(PREFIX)gprbuild -Pobj/gnattest/harness/test_driver.gpr $(QUIET)
8+
ifeq ($(RUN),true)
9+
obj/gnattest/harness/test_runner$(EXE)
10+
endif
11+
12+
substitution:
13+
$(PREFIX)gnattest -Ptagged_rec.gpr --validate-type-extensions $(QUIET)
14+
$(PREFIX)gprbuild -f -Pobj/gnattest/harness/test_driver.gpr $(QUIET)
15+
ifeq ($(RUN),true)
16+
obj/gnattest/harness/test_runner$(EXE)
17+
endif
18+
19+
clean:
20+
$(PREFIX)gprclean -Ptagged_rec.gpr
21+
$(RM) -r obj/gnattest/harness
22+
$(RM) obj/gnattest/tests/speed1-controller_test_data.ad?
23+
$(RM) obj/gnattest/tests/speed1-controller_test_data-controller_tests.ads
24+
$(RM) obj/gnattest/tests/speed1-test_data*
25+
$(RM) obj/gnattest/tests/speed2-auto_controller_test_data-auto_controller_tests.ads
26+
$(RM) obj/gnattest/tests/speed2-auto_controller_test_data.ad?
27+
$(RM) obj/gnattest/tests/speed2-test_data*
28+
29+
.PHONY: clean tagged substitution
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
G N A T T E S T E X A M P L E S
2+
3+
In order to generate and compile test driver, make sure that 'gnattest' and
4+
'gprbuild' commands are in your path and AUnit is in your default project path.
5+
6+
To generate a test driver for a number of sources you need to use gnattest
7+
utility. Note that in order to process given files, gnattest has to
8+
semantically analyze the Ada sources. Therefore, test packages can only be
9+
generated legal Ada units. Moreover, when a unit depends semantically upon
10+
units located outside the current directory, the source search path has to be
11+
provided when calling gnattest through a specified project file.
12+
13+
Invocation
14+
----------
15+
16+
In order to build the executables provided in this example you need to
17+
generate a test driver for the project and compile it:
18+
$ gnattest -Ptagged_rec.gpr
19+
$ gprbuild -Pobj/gnattest/harness/test_driver.gpr
20+
21+
Actual tests are already provided for this example, so let's run the driver:
22+
$ obj/gnattest/harness/test_runner
23+
24+
Test Inheritance
25+
----------------
26+
27+
As can be seen from test driver output, the test for subprogram Speed is also
28+
applied to objects of derived type Auto_Controller.
29+
30+
Substitutability Testing
31+
------------------------
32+
33+
To see an example of Substitutability Testing of tagged types first invoke
34+
gnattest with a special switch:
35+
$ gnattest -Ptagged_rec.gpr --validate-type-extensions
36+
37+
After recompiling and running the driver you can see that while all the tests
38+
pass by themselves, the parent test for Adjust_Speed fails against object
39+
of derived type.
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
speed1.ads:12:4: error: corresponding test FAILED: Test not implemented. (speed1-controller_test_data-controller_tests.adb:44)
2+
speed1.ads:13:4: error: corresponding test FAILED: Test not implemented. (speed1-controller_test_data-controller_tests.adb:65)
3+
speed2.ads:10:4: error: corresponding test FAILED: Test not implemented. (speed2-auto_controller_test_data-auto_controller_tests.adb:44)
4+
speed2.ads:12:4: error: corresponding test FAILED: Test not implemented. (speed2-auto_controller_test_data-auto_controller_tests.adb:65)
5+
speed2.ads:16:4: error: corresponding test FAILED: Test not implemented. (speed2-auto_controller_test_data-auto_controller_tests.adb:86)
6+
speed1.ads:12:4: inherited at speed2.ads:20:4: error: corresponding test FAILED: Test not implemented. (speed1-controller_test_data-controller_tests.adb:44)
7+
6 tests run: 0 passed; 6 failed; 0 crashed.
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
--
2+
-- Copyright (C) 2011-2012, AdaCore
3+
--
4+
5+
package body Speed1 is
6+
function Speed (This : Controller) return Speed_Type is
7+
begin
8+
return This.Actual_Speed;
9+
end Speed;
10+
11+
procedure Adjust_Speed
12+
(This : in out Controller; Increment : Speed_Delta) is
13+
begin
14+
This.Actual_Speed := This.Actual_Speed + Increment;
15+
end Adjust_Speed;
16+
17+
end Speed1;

0 commit comments

Comments
 (0)