@@ -6,10 +6,13 @@ import { ContextClients } from './clients';
66import { getProjectFile , getObjectDir } from './helpers' ;
77import { 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
3941type 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 | - ) + ) .a d [ b | s ] : \d + : \d + : ( i n f o | e r r o r ) : c o r r e s p o n d i n g t e s t ( \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/*
0 commit comments