@@ -162,6 +162,83 @@ suite('End to End Tests: unittest adapters', () => {
162162 traceLog ( 'Symlink was not found to remove after tests, exiting successfully, nestedSymlink.' ) ;
163163 }
164164 } ) ;
165+ test ( 'unittest execution adapter seg fault error handling' , async ( ) => {
166+ resultResolver = new PythonResultResolver ( testController , unittestProvider , workspaceUri ) ;
167+ let callCount = 0 ;
168+ let failureOccurred = false ;
169+ let failureMsg = '' ;
170+ resultResolver . _resolveExecution = async ( data , _token ?) => {
171+ // do the following asserts for each time resolveExecution is called, should be called once per test.
172+ callCount = callCount + 1 ;
173+ traceLog ( `unittest execution adapter seg fault error handling \n ${ JSON . stringify ( data ) } ` ) ;
174+ try {
175+ if ( data . status === 'error' ) {
176+ if ( data . error === undefined ) {
177+ // Dereference a NULL pointer
178+ const indexOfTest = JSON . stringify ( data ) . search ( 'Dereference a NULL pointer' ) ;
179+ if ( indexOfTest === - 1 ) {
180+ failureOccurred = true ;
181+ failureMsg = 'Expected test to have a null pointer' ;
182+ }
183+ } else if ( data . error . length === 0 ) {
184+ failureOccurred = true ;
185+ failureMsg = "Expected errors in 'error' field" ;
186+ }
187+ } else {
188+ const indexOfTest = JSON . stringify ( data . result ) . search ( 'error' ) ;
189+ if ( indexOfTest === - 1 ) {
190+ failureOccurred = true ;
191+ failureMsg =
192+ 'If payload status is not error then the individual tests should be marked as errors. This should occur on windows machines.' ;
193+ }
194+ }
195+ if ( data . result === undefined ) {
196+ failureOccurred = true ;
197+ failureMsg = 'Expected results to be present' ;
198+ }
199+ // make sure the testID is found in the results
200+ const indexOfTest = JSON . stringify ( data ) . search ( 'test_seg_fault.TestSegmentationFault.test_segfault' ) ;
201+ if ( indexOfTest === - 1 ) {
202+ failureOccurred = true ;
203+ failureMsg = 'Expected testId to be present' ;
204+ }
205+ } catch ( err ) {
206+ failureMsg = err ? ( err as Error ) . toString ( ) : '' ;
207+ failureOccurred = true ;
208+ }
209+ return Promise . resolve ( ) ;
210+ } ;
211+
212+ const testId = `test_seg_fault.TestSegmentationFault.test_segfault` ;
213+ const testIds : string [ ] = [ testId ] ;
214+
215+ // set workspace to test workspace folder
216+ workspaceUri = Uri . parse ( rootPathErrorWorkspace ) ;
217+ configService . getSettings ( workspaceUri ) . testing . unittestArgs = [ '-s' , '.' , '-p' , '*test*.py' ] ;
218+
219+ // run pytest execution
220+ const executionAdapter = new UnittestTestExecutionAdapter (
221+ configService ,
222+ testOutputChannel . object ,
223+ resultResolver ,
224+ envVarsService ,
225+ ) ;
226+ const testRun = typeMoq . Mock . ofType < TestRun > ( ) ;
227+ testRun
228+ . setup ( ( t ) => t . token )
229+ . returns (
230+ ( ) =>
231+ ( {
232+ onCancellationRequested : ( ) => undefined ,
233+ } as any ) ,
234+ ) ;
235+ await executionAdapter
236+ . runTests ( workspaceUri , testIds , TestRunProfileKind . Run , testRun . object , pythonExecFactory )
237+ . finally ( ( ) => {
238+ assert . strictEqual ( callCount , 1 , 'Expected _resolveExecution to be called once' ) ;
239+ assert . strictEqual ( failureOccurred , false , failureMsg ) ;
240+ } ) ;
241+ } ) ;
165242 test ( 'unittest discovery adapter small workspace' , async ( ) => {
166243 // result resolver and saved data for assertions
167244 let actualData : {
@@ -518,81 +595,4 @@ suite('End to End Tests: unittest adapters', () => {
518595 assert . strictEqual ( failureOccurred , false , failureMsg ) ;
519596 } ) ;
520597 } ) ;
521- test ( 'unittest execution adapter seg fault error handling' , async ( ) => {
522- resultResolver = new PythonResultResolver ( testController , unittestProvider , workspaceUri ) ;
523- let callCount = 0 ;
524- let failureOccurred = false ;
525- let failureMsg = '' ;
526- resultResolver . _resolveExecution = async ( data , _token ?) => {
527- // do the following asserts for each time resolveExecution is called, should be called once per test.
528- callCount = callCount + 1 ;
529- traceLog ( `unittest execution adapter seg fault error handling \n ${ JSON . stringify ( data ) } ` ) ;
530- try {
531- if ( data . status === 'error' ) {
532- if ( data . error === undefined ) {
533- // Dereference a NULL pointer
534- const indexOfTest = JSON . stringify ( data ) . search ( 'Dereference a NULL pointer' ) ;
535- if ( indexOfTest === - 1 ) {
536- failureOccurred = true ;
537- failureMsg = 'Expected test to have a null pointer' ;
538- }
539- } else if ( data . error . length === 0 ) {
540- failureOccurred = true ;
541- failureMsg = "Expected errors in 'error' field" ;
542- }
543- } else {
544- const indexOfTest = JSON . stringify ( data . result ) . search ( 'error' ) ;
545- if ( indexOfTest === - 1 ) {
546- failureOccurred = true ;
547- failureMsg =
548- 'If payload status is not error then the individual tests should be marked as errors. This should occur on windows machines.' ;
549- }
550- }
551- if ( data . result === undefined ) {
552- failureOccurred = true ;
553- failureMsg = 'Expected results to be present' ;
554- }
555- // make sure the testID is found in the results
556- const indexOfTest = JSON . stringify ( data ) . search ( 'test_seg_fault.TestSegmentationFault.test_segfault' ) ;
557- if ( indexOfTest === - 1 ) {
558- failureOccurred = true ;
559- failureMsg = 'Expected testId to be present' ;
560- }
561- } catch ( err ) {
562- failureMsg = err ? ( err as Error ) . toString ( ) : '' ;
563- failureOccurred = true ;
564- }
565- return Promise . resolve ( ) ;
566- } ;
567-
568- const testId = `test_seg_fault.TestSegmentationFault.test_segfault` ;
569- const testIds : string [ ] = [ testId ] ;
570-
571- // set workspace to test workspace folder
572- workspaceUri = Uri . parse ( rootPathErrorWorkspace ) ;
573- configService . getSettings ( workspaceUri ) . testing . unittestArgs = [ '-s' , '.' , '-p' , '*test*.py' ] ;
574-
575- // run pytest execution
576- const executionAdapter = new UnittestTestExecutionAdapter (
577- configService ,
578- testOutputChannel . object ,
579- resultResolver ,
580- envVarsService ,
581- ) ;
582- const testRun = typeMoq . Mock . ofType < TestRun > ( ) ;
583- testRun
584- . setup ( ( t ) => t . token )
585- . returns (
586- ( ) =>
587- ( {
588- onCancellationRequested : ( ) => undefined ,
589- } as any ) ,
590- ) ;
591- await executionAdapter
592- . runTests ( workspaceUri , testIds , TestRunProfileKind . Run , testRun . object , pythonExecFactory )
593- . finally ( ( ) => {
594- assert . strictEqual ( callCount , 1 , 'Expected _resolveExecution to be called once' ) ;
595- assert . strictEqual ( failureOccurred , false , failureMsg ) ;
596- } ) ;
597- } ) ;
598598} ) ;
0 commit comments