10
10
using System . Reflection ;
11
11
using System . Runtime . CompilerServices ;
12
12
using System . Runtime . InteropServices ;
13
+ using System . Runtime . ExceptionServices ;
13
14
using System . Text . RegularExpressions ;
14
15
using System . Threading ;
15
16
@@ -290,7 +291,9 @@ private int GetResult(TestInfo testcase, ScriptEngine engine, ScriptSource sourc
290
291
engine . GetSysModule ( ) . SetVariable ( "argv" , PythonList . FromArrayNoCopy ( new object [ ] { source . Path } ) ) ;
291
292
var compiledCode = source . Compile ( new IronPython . Compiler . PythonCompilerOptions ( ) { ModuleName = "__main__" } ) ;
292
293
293
- int res = 0 ;
294
+ ExceptionDispatchInfo exceptionInfo = null ;
295
+
296
+ int res = - 1 ;
294
297
int maxStackSize = 2 * 1024 * 1024 ; // 2 MiB
295
298
var thread = new Thread ( ( ) => {
296
299
try {
@@ -301,12 +304,12 @@ private int GetResult(TestInfo testcase, ScriptEngine engine, ScriptSource sourc
301
304
#pragma warning disable SYSLIB0006 // 'Thread.ResetAbort is not supported and throws PlatformNotSupportedException.'
302
305
Thread . ResetAbort ( ) ;
303
306
#pragma warning restore SYSLIB0006
304
- } catch ( Exception ex ) when ( ex . GetPythonException ( ) is object pex ) {
305
- if ( DynamicHelpers . GetPythonType ( pex ) . Name == "SkipTest" ) {
307
+ } catch ( Exception ex ) {
308
+ if ( ex . GetPythonException ( ) is object pex && DynamicHelpers . GetPythonType ( pex ) . Name == "SkipTest" ) {
306
309
NUnit . Framework . TestContext . Progress . WriteLine ( $ "Test { testcase . Name } skipped: { pex } ") ;
307
310
res = 0 ;
308
311
} else {
309
- throw ;
312
+ exceptionInfo = ExceptionDispatchInfo . Capture ( ex ) ;
310
313
}
311
314
}
312
315
} , maxStackSize ) {
@@ -324,6 +327,9 @@ private int GetResult(TestInfo testcase, ScriptEngine engine, ScriptSource sourc
324
327
NUnit . Framework . TestContext . Error . WriteLine ( $ "{ testcase . Name } timed out after { testcase . Options . Timeout / 1000.0 } seconds.") ;
325
328
return - 1 ;
326
329
}
330
+
331
+ exceptionInfo ? . Throw ( ) ;
332
+
327
333
return res ;
328
334
} finally {
329
335
Environment . CurrentDirectory = cwd ;
0 commit comments