Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 24 additions & 3 deletions Src/IronPythonTest/Cases/CPythonCases.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,14 @@ public int StandardCPythonTests(TestInfo testcase) {
TestContext.Progress.WriteLine(testcase.Name); // should be printed immediately
return executor.RunTest(testcase);
} catch (Exception e) {
Assert.Fail(executor.FormatException(e));
if(e is AggregateException ae) {
ae.Handle((x) => {
Assert.Fail(executor.FormatException(x));
return true;
});
} else {
Assert.Fail(executor.FormatException(e));
}
return -1;
}
}
Expand All @@ -48,7 +55,14 @@ public int AllCPythonTests(TestInfo testcase) {
TestContext.Progress.WriteLine(testcase.Name); // should be printed immediately
return executor.RunTest(testcase);
} catch (Exception e) {
Assert.Fail(executor.FormatException(e));
if(e is AggregateException ae) {
ae.Handle((x) => {
Assert.Fail(executor.FormatException(x));
return true;
});
} else {
Assert.Fail(executor.FormatException(e));
}
return -1;
}
}
Expand All @@ -69,7 +83,14 @@ public int CTypesCPythonTests(TestInfo testcase) {
TestContext.Progress.WriteLine(testcase.Name); // should be printed immediately
return executor.RunTest(testcase);
} catch (Exception e) {
Assert.Fail(executor.FormatException(e));
if(e is AggregateException ae) {
ae.Handle((x) => {
Assert.Fail(executor.FormatException(x));
return true;
});
} else {
Assert.Fail(executor.FormatException(e));
}
return -1;
}
}
Expand Down
21 changes: 6 additions & 15 deletions Src/IronPythonTest/Cases/CaseExecuter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -258,24 +258,15 @@ private int GetResult(TestInfo testcase, ScriptEngine engine, ScriptSource sourc
engine.GetSysModule().SetVariable("argv", List.FromArrayNoCopy(new object[] { source.Path }));
var compiledCode = source.Compile(new IronPython.Compiler.PythonCompilerOptions() { ModuleName = "__main__" });

var thread = new Thread(() => {
var task = Task<int>.Run(() => {
try {
res = engine.Operations.ConvertTo<int>(compiledCode.Execute(scope) ?? 0);
return engine.Operations.ConvertTo<int>(compiledCode.Execute(scope) ?? 0);
} catch (SystemExitException ex) {
res = ex.GetExitCode(out object otherCode);
} catch (ThreadAbortException) {
Thread.ResetAbort();
}
}) {
IsBackground = true
};

thread.Start();

if (!thread.Join(testcase.Options.Timeout)) {
if(!ClrModule.IsNetCoreApp) {
thread.Abort();
return ex.GetExitCode(out object otherCode);
}
});

if (!task.Wait(testcase.Options.Timeout)) {
NUnit.Framework.TestContext.Error.WriteLine($"{testcase.Name} timed out after {testcase.Options.Timeout / 1000.0} seconds.");
res = -1;
}
Expand Down
9 changes: 8 additions & 1 deletion Src/IronPythonTest/Cases/IronPythonCases.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,14 @@ public int IronPythonTests(TestInfo testcase) {
TestContext.Progress.WriteLine(testcase.Name);
return this.executor.RunTest(testcase);
} catch (Exception e) {
Assert.Fail(this.executor.FormatException(e));
if(e is AggregateException ae) {
ae.Handle((x) => {
Assert.Fail(executor.FormatException(x));
return true;
});
} else {
Assert.Fail(this.executor.FormatException(e));
}
return -1;
}
}
Expand Down