@@ -11,7 +11,7 @@ import { VscodeAdapter } from "../Infrastructure/VscodeAdapter";
1111
1212export default class CppUTestContainer {
1313 private runners : ExecutableRunner [ ] ;
14- private suites : Map < string , CppUTestGroup > ;
14+ private suites : Map < string , CppUTestSuite > ;
1515 private settingsProvider : SettingsProvider ;
1616 private vscodeAdapter : VscodeAdapter ;
1717 private resultParser : ResultParser ;
@@ -30,25 +30,24 @@ export default class CppUTestContainer {
3030 this . runners = runners ;
3131 this . vscodeAdapter = vscodeAdapter ;
3232 this . resultParser = resultParser ;
33- this . suites = new Map < string , CppUTestGroup > ( ) ;
33+ this . suites = new Map < string , CppUTestSuite > ( ) ;
3434 }
3535
36- public LoadTests ( ) : Promise < CppUTestGroup [ ] > {
36+ public LoadTests ( ) : Promise < CppUTestSuite [ ] > {
3737 return Promise . all ( this . runners
3838 . map ( runner => runner . GetTestList ( )
39- . then ( testString => this . EmbedInRunnerGroup ( runner , testString ) )
40- . catch ( error => new CppUTestGroup ( "ERROR ON LOADING TESTS" ) )
39+ . then ( testString => this . UpdateTestSuite ( runner , testString ) )
40+ . catch ( error => this . CreateTestSuiteError ( runner . Name ) )
4141 ) ) ;
4242 }
4343
4444 public ClearTests ( ) {
45- this . suites = new Map < string , CppUTestGroup > ( ) ;
45+ this . suites = new Map < string , CppUTestSuite > ( ) ;
4646 }
4747
4848 public async RunAllTests ( ) : Promise < TestResult [ ] > {
49- const testList = await this . LoadTests ( ) ;
5049 const testResults : TestResult [ ] = new Array < TestResult > ( ) ;
51- for ( const executableGroup of testList ) {
50+ for ( const executableGroup of this . suites . values ( ) ) {
5251 for ( const testGroup of executableGroup . children ) {
5352 for ( const test of ( testGroup as CppUTestGroup ) . children ) {
5453 const runner = this . runners . filter ( r => r . Name === executableGroup . label ) [ 0 ] ;
@@ -64,10 +63,9 @@ export default class CppUTestContainer {
6463 }
6564
6665 public async RunTest ( ...testId : string [ ] ) : Promise < TestResult [ ] > {
67- const testList = await this . LoadTests ( ) ;
6866 const testResults : TestResult [ ] = new Array < TestResult > ( ) ;
6967 const testsToRun : CppUTest [ ] = new Array < CppUTest > ( ) ;
70- for ( const executableGroup of testList ) {
68+ for ( const executableGroup of this . suites . values ( ) ) {
7169 testsToRun . splice ( 0 , testsToRun . length ) ;
7270 if ( testId . includes ( executableGroup . id ) ) {
7371 testsToRun . push ( ...executableGroup . Tests ) ;
@@ -106,8 +104,7 @@ export default class CppUTestContainer {
106104 if ( ! workspaceFolders ) {
107105 throw new Error ( "No workspaceFolders found. Not able to debug!" ) ;
108106 }
109- const testList = await this . LoadTests ( ) ;
110- for ( const executableGroup of testList ) {
107+ for ( const executableGroup of this . suites . values ( ) ) {
111108 const testOrGroup = this . GetGroupOrTest ( testId , executableGroup ) ;
112109 const runner = this . runners . filter ( r => r . Name === executableGroup . label ) [ 0 ] ;
113110 if ( testOrGroup && runner ) {
@@ -147,21 +144,33 @@ export default class CppUTestContainer {
147144 return Array < CppUTest > ( ) . concat ( ...tests ) ;
148145 }
149146
150- private async EmbedInRunnerGroup ( runner : ExecutableRunner , testString : string ) : Promise < CppUTestGroup > {
151- if ( this . suites . has ( runner . Name ) ) {
152- return ( this . suites . get ( runner . Name ) as CppUTestGroup ) ;
153- }
154- const testFactory = new CppUTestSuite ( runner . Name ) ;
155- const testGroup = testFactory . CreateTestGroupsFromTestListString ( testString ) ;
156- for ( const test of testGroup . Tests ) {
147+ private async UpdateTestSuite ( runner : ExecutableRunner , testString : string ) : Promise < CppUTestSuite > {
148+ const testSuite = this . GetTestSuite ( runner . Name ) ;
149+ testSuite . UpdateFromTestListString ( testString ) ;
150+ for ( const test of testSuite . Tests ) {
157151 try {
158152 const debugString = await runner . GetDebugSymbols ( test . group , test . label ) ;
159- testFactory . AddDebugInformationToTest ( test , debugString ) ;
153+ test . AddDebugInformation ( debugString ) ;
160154 } catch ( error ) {
161155 console . error ( error ) ;
162156 }
163157 }
164- this . suites . set ( runner . Name , testGroup ) ;
165- return testGroup ;
158+ return testSuite ;
159+ }
160+
161+ private async CreateTestSuiteError ( runnerName : string ) : Promise < CppUTestSuite > {
162+ const testSuite = this . GetTestSuite ( runnerName ) ;
163+ testSuite . AddTestGroup ( "ERROR LOADING TESTS" ) ;
164+ return testSuite ;
165+ }
166+
167+ private GetTestSuite ( runnerName : string ) : CppUTestSuite {
168+ if ( this . suites . has ( runnerName ) ) {
169+ return ( this . suites . get ( runnerName ) as CppUTestSuite ) ;
170+ } else {
171+ const testSuite = new CppUTestSuite ( runnerName ) ;
172+ this . suites . set ( runnerName , testSuite ) ;
173+ return testSuite ;
174+ }
166175 }
167176}
0 commit comments