1- import * as fs from 'fs-extra' ;
2- import { inspect } from 'util' ;
3- import { mergeFiles } from 'junit-report-merger' ;
1+ import * as fs from 'fs' ;
2+ import { inspect , promisify } from 'util' ;
43import { Suite } from '../Suite' ;
54import { AbstractRunnable , RunnableReloadResult } from '../AbstractRunnable' ;
65import { CppUTestTest } from './CppUTestTest' ;
7- import { Parser } from 'xml2js' ;
86import { RunnableProperties } from '../RunnableProperties' ;
97import { SharedVariables } from '../SharedVariables' ;
108import { RunningRunnable , ProcessResult } from '../RunningRunnable' ;
@@ -28,67 +26,11 @@ export class CppUTestRunnable extends AbstractRunnable {
2826 return this . properties . testGrouping ;
2927 } else {
3028 const grouping = { groupByExecutable : this . _getGroupByExecutable ( ) } ;
29+ grouping . groupByExecutable . groupByTags = { tags : [ ] , tagFormat : '${tag}' } ;
3130 return grouping ;
3231 }
3332 }
3433
35- private async _reloadFromXml ( xmlStr : string , cancellationFlag : CancellationFlag ) : Promise < RunnableReloadResult > {
36- const testGrouping = this . getTestGrouping ( ) ;
37-
38- interface XmlObject {
39- [ prop : string ] : any ; //eslint-disable-line
40- }
41-
42- let xml : XmlObject = { } ;
43-
44- new Parser ( { explicitArray : true } ) . parseString ( xmlStr , ( err : Error , result : Record < string , unknown > ) => {
45- if ( err ) {
46- throw err ;
47- } else {
48- xml = result ;
49- }
50- } ) ;
51-
52- const reloadResult = new RunnableReloadResult ( ) ;
53-
54- const processTestcases = async ( testsuite : any , reloadResult : RunnableReloadResult ) => {
55- const suiteName = testsuite . $ . name ;
56- for ( let i = 0 ; i < testsuite . testcase . length ; i ++ ) {
57- if ( cancellationFlag . isCancellationRequested ) return ;
58-
59- const testCase = testsuite . testcase [ i ] ;
60- const testName = testCase . $ . name . startsWith ( 'DISABLED_' ) ? testCase . $ . name . substr ( 9 ) : testCase . $ . name ;
61- const testNameAsId = suiteName + '.' + testCase . $ . name ;
62-
63- const file = testCase . $ . file ? await this . _resolveSourceFilePath ( testCase . $ . file ) : undefined ;
64- const line = testCase . $ . line ? testCase . $ . line - 1 : undefined ;
65-
66- reloadResult . add (
67- ...( await this . _createSubtreeAndAddTest (
68- testGrouping ,
69- testNameAsId ,
70- testName ,
71- file ,
72- [ suiteName ] ,
73- ( parent : Suite ) => new CppUTestTest ( this . _shared , this , parent , testNameAsId , testName , file , line ) ,
74- ( old : AbstractTest ) => ( old as CppUTestTest ) . update ( testNameAsId , file , line ) ,
75- ) ) ,
76- ) ;
77- }
78- } ;
79-
80- if ( xml . testsuites !== undefined ) {
81- for ( let i = 0 ; i < xml . testsuites . testsuite . length ; ++ i ) {
82- await processTestcases ( xml . testsuites . testsuite [ i ] , reloadResult )
83- . catch ( ( err ) => this . _shared . log . info ( 'Error' , err ) ) ;
84- }
85- } else {
86- await processTestcases ( xml . testsuite , reloadResult ) ;
87- }
88-
89- return reloadResult ;
90- }
91-
9234 private async _reloadFromString (
9335 stdOutStr : string ,
9436 cancellationFlag : CancellationFlag ,
@@ -120,18 +62,18 @@ export class CppUTestRunnable extends AbstractRunnable {
12062 }
12163
12264 protected async _reloadChildren ( cancellationFlag : CancellationFlag ) : Promise < RunnableReloadResult > {
123- const cacheFile = this . properties . path + '.TestMate.testListCache.xml ' ;
65+ const cacheFile = this . properties . path + '.TestMate.testListCache.txt ' ;
12466
12567 if ( this . _shared . enabledTestListCaching ) {
12668 try {
127- const cacheStat = await fs . stat ( cacheFile ) ;
128- const execStat = await fs . stat ( this . properties . path ) ;
69+ const cacheStat = await promisify ( fs . stat ) ( cacheFile ) ;
70+ const execStat = await promisify ( fs . stat ) ( this . properties . path ) ;
12971
13072 if ( cacheStat . size > 0 && cacheStat . mtime > execStat . mtime ) {
13173 this . _shared . log . info ( 'loading from cache: ' , cacheFile ) ;
132- const xmlStr = await fs . readFile ( cacheFile , 'utf8' ) ;
74+ const str = await promisify ( fs . readFile ) ( cacheFile , 'utf8' ) ;
13375
134- return await this . _reloadFromXml ( xmlStr , cancellationFlag ) ;
76+ return await this . _reloadFromString ( str , cancellationFlag ) ;
13577 }
13678 } catch ( e ) {
13779 this . _shared . log . info ( 'coudnt use cache' , e ) ;
@@ -149,47 +91,23 @@ export class CppUTestRunnable extends AbstractRunnable {
14991 ) ;
15092
15193 if ( cppUTestListOutput . stderr && ! this . properties . ignoreTestEnumerationStdErr ) {
152- this . _shared . log . warn ( 'reloadChildren -> cppUTestListOutput .stderr: ' , cppUTestListOutput ) ;
94+ this . _shared . log . warn ( 'reloadChildren -> googleTestListOutput .stderr: ' , cppUTestListOutput ) ;
15395 return await this . _createAndAddUnexpectedStdError ( cppUTestListOutput . stdout , cppUTestListOutput . stderr ) ;
15496 }
15597
156- if ( cppUTestListOutput . stdout . length === 0 ) {
157- this . _shared . log . debug ( cppUTestListOutput ) ;
158- throw Error ( 'stoud is empty' ) ;
159- }
160-
161- const result = this . _reloadFromString ( cppUTestListOutput . stdout , cancellationFlag ) ;
98+ const result = await this . _reloadFromString ( cppUTestListOutput . stdout , cancellationFlag ) ;
16299
163100 if ( this . _shared . enabledTestListCaching ) {
164- //Generate xmls folder
165- const junitXmlsFolderPath = this . properties . path + '_junit_xmls' ;
166- fs . mkdir ( junitXmlsFolderPath )
167- . then ( ( ) => this . _shared . log . info ( 'junit-xmls folder created' , junitXmlsFolderPath ) )
168- . catch ( err => this . _shared . log . error ( 'error creating xmls folder: ' , junitXmlsFolderPath , err ) ) ;
169- //Generate xml files
170- const args = this . properties . prependTestListingArgs . concat ( [ '-ojunit' ] ) ;
171- const options = { cwd : junitXmlsFolderPath } ;
172- await this . properties . spawner
173- . spawnAsync ( this . properties . path , args , options , 30000 )
174- . then ( ( ) => this . _shared . log . info ( 'create cpputest xmls' , this . properties . path , args , options . cwd ) ) ;
175- //Merge xmls into single xml
176- fs . readdir ( junitXmlsFolderPath , ( err , files ) => {
177- if ( files . length > 1 ) {
178- mergeFiles ( cacheFile , [ junitXmlsFolderPath + '/*.xml' ] )
179- . then ( ( ) => this . _shared . log . info ( 'cache xml written' , cacheFile ) )
180- . catch ( err => this . _shared . log . warn ( 'combine xml cache file could not create: ' , cacheFile , err ) ) ;
181- } else {
182- fs . copyFile ( junitXmlsFolderPath + '/' + files [ 0 ] , cacheFile ) ;
183- }
184- } ) ;
185- //Delete xmls folder
186- fs . remove ( junitXmlsFolderPath )
187- . then ( ( ) => this . _shared . log . info ( 'junit-xmls folder deleted' , junitXmlsFolderPath ) )
188- . catch ( err => this . _shared . log . error ( 'error deleting xmls folder: ' , junitXmlsFolderPath , err ) ) ;
101+ promisify ( fs . writeFile ) ( cacheFile , cppUTestListOutput . stdout ) . catch ( err =>
102+ this . _shared . log . warn ( 'couldnt write cache file:' , err ) ,
103+ ) ;
189104 }
105+
190106 return result ;
191107 }
192108
109+ //TODO:matepek: reviewed until this
110+
193111 protected _getRunParamsInner ( childrenToRun : readonly Readonly < AbstractTest > [ ] ) : string [ ] {
194112 // TODO: Add multiple options
195113 const execParams : string [ ] = [ ] ;
@@ -201,7 +119,7 @@ export class CppUTestRunnable extends AbstractRunnable {
201119 return execParams ;
202120 }
203121
204- protected _getDebugParamsInner ( childrenToRun : readonly Readonly < AbstractTest > [ ] , breakOnFailure : boolean ) : string [ ] {
122+ protected _getDebugParamsInner ( childrenToRun : readonly Readonly < AbstractTest > [ ] , _breakOnFailure : boolean ) : string [ ] {
205123 // TODO: Proper debug options
206124 // TODO: colouring 'debug.enableOutputColouring'
207125 // TODO: Add multiple options
@@ -333,7 +251,7 @@ export class CppUTestRunnable extends AbstractRunnable {
333251 } else {
334252 if ( code !== null && code !== undefined ) resolve ( ProcessResult . createFromErrorCode ( code ) ) ;
335253 else if ( signal !== null && signal !== undefined ) resolve ( ProcessResult . createFromSignal ( signal ) ) ;
336- else resolve ( ProcessResult . error ( 'unknown sfngvdlfkxdvgn ' ) ) ;
254+ else resolve ( ProcessResult . error ( 'unknown sgrstbdfg ' ) ) ;
337255 }
338256 } ) ;
339257 } )
0 commit comments