@@ -78,8 +78,8 @@ export async function initializeTestView(
78
78
*/
79
79
function startTestRun (
80
80
controller : vscode . TestController ,
81
- projectFile : string ,
82
- gnattestPath : string
81
+ projectFileFullPath : string ,
82
+ gnattestFullPath : string
83
83
) {
84
84
// terminal ID to seperate between each run
85
85
let terminal_id = 0 ;
@@ -91,12 +91,12 @@ function startTestRun(
91
91
const tests = gatherChildTestItems ( controller . items ) ;
92
92
const terminal_name = 'Test_terminal_' + terminal_id . toString ( ) ;
93
93
// Run all tests handler
94
- handleRunAll ( tests , run , terminal_name , gnattestPath ) ;
94
+ handleRunAll ( tests , run , terminal_name , gnattestFullPath ) ;
95
95
terminal_id ++ ;
96
96
// Parse the results when the terminal is closed
97
97
vscode . window . onDidCloseTerminal ( async ( terminal ) => {
98
98
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' ) ) ;
100
100
if ( file != undefined ) {
101
101
parseResults ( tests , run , file ) ;
102
102
}
@@ -110,12 +110,12 @@ function startTestRun(
110
110
// create a temporary terminal to execute the command lines then close it.
111
111
const terminalName = 'Test_terminal_' + terminal_id . toString ( ) ;
112
112
// test unit run handler
113
- handleUnitRun ( tests , run , terminalName , gnattestPath ) ;
113
+ handleUnitRun ( tests , run , terminalName , gnattestFullPath ) ;
114
114
terminal_id ++ ;
115
115
// Parse the results when the terminal is closed
116
116
vscode . window . onDidCloseTerminal ( async ( terminal ) => {
117
117
if ( terminal . name == terminalName ) {
118
- const file = await readResultFile ( path . join ( gnattestPath , 'result.txt' ) ) ;
118
+ const file = await readResultFile ( path . join ( gnattestFullPath , 'result.txt' ) ) ;
119
119
if ( file != undefined ) {
120
120
parseResults ( tests , run , file ) ;
121
121
}
@@ -135,15 +135,15 @@ function startTestRun(
135
135
// Tests Configuration Handler to Generates Tests for a Project.
136
136
testRunProfile . configureHandler = ( ) => {
137
137
const terminal = vscode . window . createTerminal ( 'Test Terminal' ) ;
138
- terminal . sendText ( 'gnattest -P ' + projectFile ) ;
138
+ terminal . sendText ( 'gnattest -P ' + projectFileFullPath ) ;
139
139
terminal . sendText ( 'exit' ) ;
140
140
} ;
141
141
// Refresh Button to re discover the tests on the project.
142
142
controller . refreshHandler = async ( ) => {
143
143
controller . items . forEach ( ( item ) => {
144
144
controller . items . delete ( item . id ) ;
145
145
} ) ;
146
- await discoverTests ( controller , gnattestPath ) ;
146
+ await discoverTests ( controller , gnattestFullPath ) ;
147
147
} ;
148
148
}
149
149
@@ -240,7 +240,7 @@ export function getParentTestSourceName(item: vscode.TestItem) {
240
240
*/
241
241
export async function readResultFile ( resultPath : string ) {
242
242
if ( vscode . workspace . workspaceFolders !== undefined ) {
243
- if ( pathExists ( resultPath ) ) {
243
+ if ( pathIsReadable ( resultPath ) ) {
244
244
const file = await vscode . workspace . fs . readFile ( vscode . Uri . file ( resultPath ) ) ;
245
245
return file . toString ( ) ;
246
246
}
@@ -293,14 +293,12 @@ export function parseResults(
293
293
/*
294
294
Return the tests structure stored in gnattest.xml file
295
295
*/
296
- export async function readXMLfile ( harnessPath : string ) : Promise < string | undefined > {
296
+ export async function readXMLfile ( harnessFullPath : string ) : Promise < string | undefined > {
297
297
if ( vscode . workspace . workspaceFolders !== undefined ) {
298
- const mainPath = vscode . workspace . workspaceFolders [ 0 ] . uri . path ;
299
- const fullHarnessPath = path . join ( mainPath , harnessPath ) ;
300
298
let file ;
301
- if ( pathExists ( fullHarnessPath ) ) {
299
+ if ( pathIsReadable ( harnessFullPath ) ) {
302
300
file = await vscode . workspace . fs . readFile (
303
- vscode . Uri . file ( path . join ( fullHarnessPath , 'gnattest.xml' ) )
301
+ vscode . Uri . file ( path . join ( harnessFullPath , 'gnattest.xml' ) )
304
302
) ;
305
303
}
306
304
return file ?. toString ( ) . replace ( / > \s + < / g, '><' ) . trim ( ) ;
@@ -311,10 +309,10 @@ export async function readXMLfile(harnessPath: string): Promise<string | undefin
311
309
/*
312
310
Discover tests by parsing the xml input
313
311
*/
314
- export async function discoverTests ( controller : vscode . TestController , gnattestPath : string ) {
312
+ export async function discoverTests ( controller : vscode . TestController , gnattestFullPath : string ) {
315
313
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' ) ) ;
318
316
const options = {
319
317
ignoreAttributes : false ,
320
318
attributeNamePrefix : '@_' ,
@@ -423,10 +421,11 @@ function findFile(name: string, directory: string): string {
423
421
return '' ;
424
422
}
425
423
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 {
430
429
try {
431
430
fs . accessSync ( p ) ;
432
431
} catch ( err ) {
0 commit comments