@@ -9,11 +9,10 @@ import { CancellationToken } from 'vscode-languageclient';
9
9
import { adaExtState } from './extension' ;
10
10
import { addCoverageData , GnatcovFileCoverage } from './gnatcov' ;
11
11
import { getScenarioArgs } from './gnatTaskProvider' ;
12
- import { escapeRegExp , exe , getObjectDir , setTerminalEnvironment , slugify } from './helpers' ;
12
+ import { escapeRegExp , exe , setTerminalEnvironment , slugify } from './helpers' ;
13
13
import {
14
14
DEFAULT_PROBLEM_MATCHER ,
15
15
findTaskByName ,
16
- runTaskAndGetResult ,
17
16
runTaskSequence ,
18
17
SimpleTaskDef ,
19
18
TASK_BUILD_TEST_DRIVER ,
@@ -160,19 +159,29 @@ export async function refreshTestItemTree() {
160
159
/**
161
160
* @returns the full path to the GNATtest XML file.
162
161
*/
163
- async function getGnatTestXmlPath ( ) : Promise < string > {
164
- const objDir = await getObjectDir ( ) ;
165
- const gnatTestXmlPath = path . join ( objDir , 'gnattest' , 'harness' , 'gnattest.xml' ) ;
162
+ export async function getGnatTestXmlPath ( ) : Promise < string > {
163
+ const gnatTestXmlPath = path . join ( await getHarnessDir ( ) , 'gnattest.xml' ) ;
166
164
return gnatTestXmlPath ;
167
165
}
168
166
167
+ export async function getHarnessDir ( ) {
168
+ return await adaExtState
169
+ . getProjectAttributeValue ( 'Harness_Dir' , 'Gnattest' )
170
+ . catch (
171
+ /**
172
+ * default to gnattest/harness if Harness_Dir is unspecified
173
+ */
174
+ ( ) => path . join ( 'gnattest' , 'harness' ) ,
175
+ )
176
+ . then ( async ( value ) => path . join ( await adaExtState . getObjectDir ( ) , value as string ) ) ;
177
+ }
178
+
169
179
/**
170
180
*
171
181
* @returns the full path to the GNATtest test driver GPR project.
172
182
*/
173
183
export async function getGnatTestDriverProjectPath ( ) : Promise < string > {
174
- const objDir = await getObjectDir ( ) ;
175
- const testDriverPath = path . join ( objDir , 'gnattest' , 'harness' , 'test_driver.gpr' ) ;
184
+ const testDriverPath = path . join ( await getHarnessDir ( ) , 'test_driver.gpr' ) ;
176
185
return testDriverPath ;
177
186
}
178
187
@@ -181,11 +190,26 @@ export async function getGnatTestDriverProjectPath(): Promise<string> {
181
190
* @returns the full path to the GNATtest test driver executable.
182
191
*/
183
192
export async function getGnatTestDriverExecPath ( ) : Promise < string > {
184
- const objDir = await getObjectDir ( ) ;
185
- const testDriverPath = path . join ( objDir , 'gnattest' , 'harness' , 'test_runner' + exe ) ;
193
+ const testDriverPath = path . join ( await getHarnessDir ( ) , 'test_runner' + exe ) ;
186
194
return testDriverPath ;
187
195
}
188
196
197
+ /**
198
+ *
199
+ * @returns path where GNATcoverage execution traces will be created during a test run
200
+ */
201
+ async function getTracesDir ( ) {
202
+ return path . join ( await adaExtState . getVSCodeObjectSubdir ( ) , 'test-traces' ) ;
203
+ }
204
+
205
+ /**
206
+ *
207
+ * @returns path where GNATcoverage report will be created after a test run
208
+ */
209
+ async function getGnatCovXMLReportDir ( ) {
210
+ return path . join ( await adaExtState . getVSCodeObjectSubdir ( ) , 'cov-xml' ) ;
211
+ }
212
+
189
213
/**
190
214
* Parse the GNATtest XML file and create the top-level TestItems in the test
191
215
* controller for later lazy resolution.
@@ -330,6 +354,7 @@ async function addTestCaseItem(parentItem: vscode.TestItem, testCase: TestCase)
330
354
const testFileBasename = test [ '@_file' ] ;
331
355
const pos = new vscode . Position ( parseInt ( test [ '@_line' ] ) , parseInt ( test [ '@_column' ] ) - 1 ) ;
332
356
const range = new vscode . Range ( pos , pos ) ;
357
+
333
358
const testUri = await findFileInWorkspace ( testFileBasename ) ;
334
359
335
360
// The name of the source file of the tested subprogram is not part of the
@@ -557,7 +582,16 @@ async function handleRunRequestedTests(
557
582
requestedRootTests . push ( ...request . include ) ;
558
583
} else {
559
584
/**
560
- * Consider all tests as included
585
+ * If the Testing view hasn't been opened yet, the tests may not
586
+ * have been loaded yet. Check for that and load the tests in that
587
+ * case.
588
+ */
589
+ if ( controller . items . size == 0 ) {
590
+ await refreshTestItemTree ( ) ;
591
+ }
592
+
593
+ /**
594
+ * Consider all tests as included.
561
595
*/
562
596
controller . items . forEach ( ( i ) => requestedRootTests . push ( i ) ) ;
563
597
}
@@ -606,7 +640,11 @@ async function handleRunRequestedTests(
606
640
* Invoke the test driver for each test
607
641
*/
608
642
const execPath = await getGnatTestDriverExecPath ( ) ;
609
- const tracesDir = path . dirname ( execPath ) ;
643
+ const tracesDir = await getTracesDir ( ) ;
644
+
645
+ if ( coverage ) {
646
+ fs . mkdirSync ( tracesDir , { recursive : true } ) ;
647
+ }
610
648
611
649
function getTracePath ( test : TestItem ) : string {
612
650
return path . join ( tracesDir , slugify ( test . id ) + '.srctrace' ) ;
@@ -684,7 +722,7 @@ async function handleRunRequestedTests(
684
722
/**
685
723
* Produce a GNATcov XML report
686
724
*/
687
- const outputDir = path . join ( await adaExtState . getObjectDir ( ) , 'cov-xml' ) ;
725
+ const outputDir = await getGnatCovXMLReportDir ( ) ;
688
726
const adaTP = adaExtState . getAdaTaskProvider ( ) ! ;
689
727
const gnatcovReportTask = ( await adaTP . resolveTask (
690
728
new vscode . Task (
@@ -708,7 +746,7 @@ async function handleRunRequestedTests(
708
746
) ,
709
747
) ) ! ;
710
748
gnatcovReportTask . presentationOptions . reveal = vscode . TaskRevealKind . Never ;
711
- const result = await runTaskAndGetResult ( gnatcovReportTask ) ;
749
+ const result = await runTaskSequence ( [ gnatcovReportTask ] , new WriteEmitter ( run ) ) ;
712
750
if ( result != 0 ) {
713
751
const msg =
714
752
`Error while running coverage analysis.` +
@@ -726,6 +764,20 @@ async function handleRunRequestedTests(
726
764
}
727
765
}
728
766
767
+ /**
768
+ * An EventEmitter that forwards data to a a TestRun given at construction
769
+ * time.
770
+ */
771
+ class WriteEmitter extends vscode . EventEmitter < string > {
772
+ constructor ( private run : vscode . TestRun ) {
773
+ super ( ) ;
774
+ }
775
+
776
+ override fire ( data : string ) : void {
777
+ this . run . appendOutput ( data ) ;
778
+ }
779
+ }
780
+
729
781
/**
730
782
* Build the test driver and report build failure as errors on the tests
731
783
* requested for execution.
@@ -739,12 +791,6 @@ async function buildTestDriverAndReportErrors(
739
791
testsToRun : vscode . TestItem [ ] ,
740
792
coverage : boolean ,
741
793
) {
742
- class WriteEmitter extends vscode . EventEmitter < string > {
743
- override fire ( data : string ) : void {
744
- run . appendOutput ( data ) ;
745
- }
746
- }
747
-
748
794
const buildTasks = [ ] ;
749
795
if ( coverage ) {
750
796
const adaTP = adaExtState . getAdaTaskProvider ( ) ;
@@ -836,7 +882,7 @@ async function buildTestDriverAndReportErrors(
836
882
buildTasks . push ( task ) ;
837
883
}
838
884
839
- const result = await runTaskSequence ( buildTasks , new WriteEmitter ( ) ) ;
885
+ const result = await runTaskSequence ( buildTasks , new WriteEmitter ( run ) ) ;
840
886
841
887
if ( result != 0 ) {
842
888
let msg =
0 commit comments