Skip to content

Commit 30f0f25

Browse files
committed
Harmonize the use of full paths in GNATtest integration
1 parent 369ad0d commit 30f0f25

File tree

2 files changed

+22
-23
lines changed

2 files changed

+22
-23
lines changed

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/test/suite/gnattest/gnattest.test.ts

Lines changed: 2 additions & 2 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 () {
@@ -40,7 +40,7 @@ suite('GNATtest Integration Tests', function () {
4040
test('Expected Tests discovered', async () => {
4141
const root = await gnattest.discoverTests(
4242
gnattest.controller,
43-
path.join('obj', 'gnattest')
43+
path.join(await getObjectDir(contextClients.adaClient), 'gnattest')
4444
);
4545
assert.notStrictEqual(root, undefined);
4646
const tests = gnattest.gatherChildTestItems(gnattest.controller.items);

0 commit comments

Comments
 (0)