@@ -78,8 +78,8 @@ export async function initializeTestView(
7878*/
7979function 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*/
241241export 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 ) {
0 commit comments