Skip to content

Commit ca9f70c

Browse files
committed
Merge branch 'topic/fix_tests_windows' into 'master'
Fix GNATtest integration and testing on Windows See merge request eng/ide/ada_language_server!1369
2 parents 8ed34e4 + 30f0f25 commit ca9f70c

File tree

7 files changed

+59
-52
lines changed

7 files changed

+59
-52
lines changed

Makefile

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,21 @@ BUILD_DATE ?=
1010
# Location of home dir for tests
1111
export ALS_HOME=$(ROOTDIR)/testsuite
1212

13+
# Exectuable extension
14+
ifeq ($(OS),)
15+
# Not Windows
16+
EXE=""
17+
else
18+
# Windows
19+
EXE=.exe
20+
endif
21+
1322
# Command to run for tests
14-
export ALS=$(ROOTDIR)/.obj/server/ada_language_server
23+
export ALS=$(ROOTDIR)/.obj/server/ada_language_server$(EXE)
1524

1625
# Tester files
17-
TESTER=$(ROOTDIR)/.obj/tester/tester-run
18-
CODEC_TEST=.obj/codec_test/codec_test
26+
TESTER=$(ROOTDIR)/.obj/tester/tester-run$(EXE)
27+
CODEC_TEST=.obj/codec_test/codec_test$(EXE)
1928

2029
# Env variable to set for update VS Code test references
2130
MOCHA_ALS_UPDATE=
@@ -156,7 +165,6 @@ endif
156165

157166
vscode-test:
158167
# Run the VS Code integration testsuite.
159-
echo $(GPR_PROJECT_PATH)
160168
MOCHA_ALS_UPDATE=$(MOCHA_ALS_UPDATE) cd integration/vscode/ada; LD_LIBRARY_PATH= npm run test
161169

162170
vscode-package:

integration/vscode/ada/package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -635,14 +635,14 @@
635635
"vscode-tmgrammar-test": "0.1.1"
636636
},
637637
"scripts": {
638-
"check-licenses": "npx license-checker-rseidelsohn --summary --onlyAllow '0BSD;Apache-2.0;BSD-2-Clause;BSD-3-Clause;BlueOak-1.0.0;CC0-1.0;GPL-3.0;GPL-3.0-or-later;ISC;MIT;Python-2.0;Zlib'",
638+
"check-licenses": "npx license-checker-rseidelsohn --summary --onlyAllow \"0BSD;Apache-2.0;BSD-2-Clause;BSD-3-Clause;BlueOak-1.0.0;CC0-1.0;GPL-3.0;GPL-3.0-or-later;ISC;MIT;Python-2.0;Zlib\"",
639639
"vscode:prepublish": "npm run esbuild-base -- --minify",
640640
"esbuild-base": "esbuild ./src/extension.ts --bundle --outfile=out/src/extension.js --external:vscode --format=cjs --platform=node",
641641
"compile": "node ./node_modules/typescript/bin/tsc",
642642
"watch": "node ./node_modules/typescript/bin/tsc -watch",
643643
"pretest": "npm run compile",
644-
"lint": "eslint './src/**/*.{js,ts,tsx}' --quiet --fix",
645-
"cilint": "eslint './src/**/*.{js,ts,tsx}'",
644+
"lint": "eslint \"./src/**/*.{js,ts,tsx}\" --quiet --fix",
645+
"cilint": "eslint \"./src/**/*.{js,ts,tsx}\"",
646646
"test": "node ./out/test/runTest.js"
647647
},
648648
"dependencies": {

integration/vscode/ada/src/gnattest.ts

Lines changed: 20 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,8 @@ export async function initializeTestView(
7878
*/
7979
function startTestRun(
8080
controller: vscode.TestController,
81-
projectFile: string,
82-
gnattestPath: string
81+
projectFileFullPath: string,
82+
gnattestFullPath: string
8383
) {
8484
// terminal ID to seperate between each run
8585
let terminal_id = 0;
@@ -91,12 +91,12 @@ function startTestRun(
9191
const tests = gatherChildTestItems(controller.items);
9292
const terminal_name = 'Test_terminal_' + terminal_id.toString();
9393
// Run all tests handler
94-
handleRunAll(tests, run, terminal_name, gnattestPath);
94+
handleRunAll(tests, run, terminal_name, gnattestFullPath);
9595
terminal_id++;
9696
// Parse the results when the terminal is closed
9797
vscode.window.onDidCloseTerminal(async (terminal) => {
9898
if (terminal.name == terminal_name) {
99-
const file = await readResultFile(path.join(gnattestPath, 'result.txt'));
99+
const file = await readResultFile(path.join(gnattestFullPath, 'result.txt'));
100100
if (file != undefined) {
101101
parseResults(tests, run, file);
102102
}
@@ -110,12 +110,12 @@ function startTestRun(
110110
// create a temporary terminal to execute the command lines then close it.
111111
const terminalName = 'Test_terminal_' + terminal_id.toString();
112112
// test unit run handler
113-
handleUnitRun(tests, run, terminalName, gnattestPath);
113+
handleUnitRun(tests, run, terminalName, gnattestFullPath);
114114
terminal_id++;
115115
// Parse the results when the terminal is closed
116116
vscode.window.onDidCloseTerminal(async (terminal) => {
117117
if (terminal.name == terminalName) {
118-
const file = await readResultFile(path.join(gnattestPath, 'result.txt'));
118+
const file = await readResultFile(path.join(gnattestFullPath, 'result.txt'));
119119
if (file != undefined) {
120120
parseResults(tests, run, file);
121121
}
@@ -135,15 +135,15 @@ function startTestRun(
135135
// Tests Configuration Handler to Generates Tests for a Project.
136136
testRunProfile.configureHandler = () => {
137137
const terminal = vscode.window.createTerminal('Test Terminal');
138-
terminal.sendText('gnattest -P ' + projectFile);
138+
terminal.sendText('gnattest -P ' + projectFileFullPath);
139139
terminal.sendText('exit');
140140
};
141141
// Refresh Button to re discover the tests on the project.
142142
controller.refreshHandler = async () => {
143143
controller.items.forEach((item) => {
144144
controller.items.delete(item.id);
145145
});
146-
await discoverTests(controller, gnattestPath);
146+
await discoverTests(controller, gnattestFullPath);
147147
};
148148
}
149149

@@ -240,7 +240,7 @@ export function getParentTestSourceName(item: vscode.TestItem) {
240240
*/
241241
export async function readResultFile(resultPath: string) {
242242
if (vscode.workspace.workspaceFolders !== undefined) {
243-
if (pathExists(resultPath)) {
243+
if (pathIsReadable(resultPath)) {
244244
const file = await vscode.workspace.fs.readFile(vscode.Uri.file(resultPath));
245245
return file.toString();
246246
}
@@ -293,14 +293,12 @@ export function parseResults(
293293
/*
294294
Return the tests structure stored in gnattest.xml file
295295
*/
296-
export async function readXMLfile(harnessPath: string): Promise<string | undefined> {
296+
export async function readXMLfile(harnessFullPath: string): Promise<string | undefined> {
297297
if (vscode.workspace.workspaceFolders !== undefined) {
298-
const mainPath = vscode.workspace.workspaceFolders[0].uri.path;
299-
const fullHarnessPath = path.join(mainPath, harnessPath);
300298
let file;
301-
if (pathExists(fullHarnessPath)) {
299+
if (pathIsReadable(harnessFullPath)) {
302300
file = await vscode.workspace.fs.readFile(
303-
vscode.Uri.file(path.join(fullHarnessPath, 'gnattest.xml'))
301+
vscode.Uri.file(path.join(harnessFullPath, 'gnattest.xml'))
304302
);
305303
}
306304
return file?.toString().replace(/>\s+</g, '><').trim();
@@ -311,10 +309,10 @@ export async function readXMLfile(harnessPath: string): Promise<string | undefin
311309
/*
312310
Discover tests by parsing the xml input
313311
*/
314-
export async function discoverTests(controller: vscode.TestController, gnattestPath: string) {
312+
export async function discoverTests(controller: vscode.TestController, gnattestFullPath: string) {
315313
if (vscode.workspace.workspaceFolders !== undefined) {
316-
const mainPath = vscode.workspace.workspaceFolders[0].uri.path;
317-
const file = await readXMLfile(path.join(gnattestPath, 'harness'));
314+
const mainPath = vscode.workspace.workspaceFolders[0].uri.fsPath;
315+
const file = await readXMLfile(path.join(gnattestFullPath, 'harness'));
318316
const options = {
319317
ignoreAttributes: false,
320318
attributeNamePrefix: '@_',
@@ -423,10 +421,11 @@ function findFile(name: string, directory: string): string {
423421
return '';
424422
}
425423

426-
/*
427-
Checking if a path/file exists
428-
*/
429-
export function pathExists(p: string): boolean {
424+
/**
425+
* @param p - path to file or directory
426+
* @returns true if the path exists and access rights allow reading it, otherwise false
427+
*/
428+
export function pathIsReadable(p: string): boolean {
430429
try {
431430
fs.accessSync(p);
432431
} catch (err) {

integration/vscode/ada/src/helpers.ts

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -205,15 +205,8 @@ type ExecutablesResponse = {
205205
* @returns a string contains the path of the project file
206206
*/
207207
export async function getProjectFile(client: LanguageClient): Promise<string> {
208-
const configValue: string | undefined = vscode.workspace
209-
.getConfiguration('ada')
210-
.get('projectFile');
211-
if (configValue != undefined && configValue != '') {
212-
return configValue;
213-
} else {
214-
const result: ProjectFileResponse = await client.sendRequest('$/glsProjectFile');
215-
return result.projectFile;
216-
}
208+
const result: ProjectFileResponse = await client.sendRequest('$/glsProjectFile');
209+
return result.projectFile;
217210
}
218211

219212
/**

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

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import * as vscode from 'vscode';
22
import * as assert from 'assert';
3+
import * as path from 'path';
34
import { suite, test } from 'mocha';
45
import { contextClients } from '../../../src/extension';
56
import { activate } from '../utils';
@@ -43,15 +44,19 @@ suite('GPR Tasks Provider', function () {
4344
test('Tasks resolving', async () => {
4445
const prov = new GprTaskProvider(contextClients.adaClient);
4546
const task = new vscode.Task(
46-
{ type: 'gpr', main: 'src/program.adb' },
47+
{ type: 'gpr', main: path.join('src', 'program.adb') },
4748
'build main',
4849
'tasks'
4950
);
5051
const workspace = vscode.workspace.workspaceFolders?.at(0)?.uri.fsPath;
5152
if (workspace == undefined) {
5253
throw new Error('No workspace found');
5354
}
54-
const expectedCmd = `gprbuild -d -P ${workspace}/default.gpr src/program.adb `;
55+
const expectedCmd =
56+
'gprbuild -d -P ' +
57+
path.join(workspace, 'default.gpr') +
58+
' ' +
59+
path.join('src', 'program.adb ');
5560
const resolved = await prov.resolveTask(task);
5661
assert.notStrictEqual(resolved, undefined);
5762
if (resolved != undefined && resolved.execution) {

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

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import * as cp from 'child_process';
55
import { suite, test } from 'mocha';
66
import * as gnattest from '../../../src/gnattest';
77
import { contextClients } from '../../../src/extension';
8-
import { getProjectFile } from '../../../src/helpers';
8+
import { getObjectDir, getProjectFile } from '../../../src/helpers';
99
import { activate, assertEqualToFileContent } from '../utils';
1010

1111
suite('GNATtest Integration Tests', function () {
@@ -14,20 +14,14 @@ suite('GNATtest Integration Tests', function () {
1414
});
1515
test('Generate Tests', async () => {
1616
await contextClients.adaClient.onReady();
17-
const projectFile = vscode.workspace.asRelativePath(
18-
await getProjectFile(contextClients.adaClient)
19-
);
20-
if (vscode.workspace.workspaceFolders) {
21-
const fpath = path.join(vscode.workspace.workspaceFolders[0].uri.path, projectFile);
22-
cp.execSync('gnattest -P ' + fpath, { timeout: 60000 });
23-
} else {
24-
throw new Error('No workspace folder found for the specified URI');
25-
}
17+
const projectFile = await getProjectFile(contextClients.adaClient);
18+
// Generate tests and redirect the stderr to stdout if command failed
19+
cp.execSync('gnattest -P ' + projectFile + ' 2>&1', { timeout: 60000 });
2620
});
2721
test('Build & Run the tests', () => {
2822
if (vscode.workspace.workspaceFolders) {
2923
const ext: string = process.platform == 'win32' ? '.exe' : '';
30-
const cwd = vscode.workspace.workspaceFolders[0].uri.path;
24+
const cwd = vscode.workspace.workspaceFolders[0].uri.fsPath;
3125

3226
cp.execSync(
3327
'gprbuild -P ' + path.join(cwd, 'obj', 'gnattest', 'harness', 'test_driver.gpr'),
@@ -46,7 +40,7 @@ suite('GNATtest Integration Tests', function () {
4640
test('Expected Tests discovered', async () => {
4741
const root = await gnattest.discoverTests(
4842
gnattest.controller,
49-
path.join('obj', 'gnattest')
43+
path.join(await getObjectDir(contextClients.adaClient), 'gnattest')
5044
);
5145
assert.notStrictEqual(root, undefined);
5246
const tests = gnattest.gatherChildTestItems(gnattest.controller.items);
@@ -57,7 +51,7 @@ suite('GNATtest Integration Tests', function () {
5751
});
5852
test('Read & Parse & compare the results', async () => {
5953
if (vscode.workspace.workspaceFolders) {
60-
const cwd = vscode.workspace.workspaceFolders[0].uri.path;
54+
const cwd = vscode.workspace.workspaceFolders[0].uri.fsPath;
6155
const resultPath = path.join(cwd, 'obj', 'gnattest', 'result.txt');
6256
const result = await gnattest.readResultFile(resultPath);
6357
assert.notStrictEqual(

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ import { existsSync, readFileSync, writeFileSync } from 'fs';
1717
* @param expectedUri - path to the file containing the expected output
1818
*/
1919
export function assertEqualToFileContent(actual: string, expectedUri: vscode.Uri) {
20+
// Normalize the actual string
21+
actual = normalizeLineEndings(actual);
22+
2023
if (update()) {
2124
writeFileSync(expectedUri.fsPath, actual);
2225
} else {
@@ -25,10 +28,15 @@ export function assertEqualToFileContent(actual: string, expectedUri: vscode.Uri
2528
}
2629

2730
const expected: string = readFileSync(expectedUri.fsPath, 'utf-8');
31+
2832
assert.strictEqual(actual, expected);
2933
}
3034
}
3135

36+
export function normalizeLineEndings(str: string, lineEnding = '\n'): string {
37+
return str.replace(/\r?\n/g, lineEnding);
38+
}
39+
3240
/**
3341
*
3442
* @returns true if the testsuite is running in update mode, i.e. the

0 commit comments

Comments
 (0)