From 44a74df0b96a41c1255eda7f556cd88d173e076e Mon Sep 17 00:00:00 2001 From: vddCore Date: Sat, 18 May 2024 10:31:38 +0200 Subject: [PATCH] Add core test fail, provide inner exception when a test case fails inside EVIL. --- .../Ceres.RuntimeTests.csproj | 1 + .../RuntimeModules/CoreModuleTest.cs | 11 ++++++-- .../RuntimeModules/ModuleTest.cs | 25 +++++++++++++++---- 3 files changed, 30 insertions(+), 7 deletions(-) diff --git a/VirtualMachine/Tests/Ceres.RuntimeTests/Ceres.RuntimeTests.csproj b/VirtualMachine/Tests/Ceres.RuntimeTests/Ceres.RuntimeTests.csproj index efc795f1..dff8672c 100644 --- a/VirtualMachine/Tests/Ceres.RuntimeTests/Ceres.RuntimeTests.csproj +++ b/VirtualMachine/Tests/Ceres.RuntimeTests/Ceres.RuntimeTests.csproj @@ -3,6 +3,7 @@ net7.0 false + enable diff --git a/VirtualMachine/Tests/Ceres.RuntimeTests/RuntimeModules/CoreModuleTest.cs b/VirtualMachine/Tests/Ceres.RuntimeTests/RuntimeModules/CoreModuleTest.cs index 49042a9c..f857c281 100644 --- a/VirtualMachine/Tests/Ceres.RuntimeTests/RuntimeModules/CoreModuleTest.cs +++ b/VirtualMachine/Tests/Ceres.RuntimeTests/RuntimeModules/CoreModuleTest.cs @@ -1,4 +1,5 @@ -using Ceres.ExecutionEngine.Collections; +using System; +using Ceres.Runtime; using Ceres.Runtime.Modules; using NUnit.Framework; using Shouldly; @@ -7,6 +8,12 @@ namespace Ceres.RuntimeTests.RuntimeModules { public class CoreModuleTest : ModuleTest { - + [Test] + public void CoreFailTerminatesExecution() + { + var e = Should.Throw(() => EvilTestResult("(fn -> core.fail(':( your computer ran'))();")); + e.InnerException.ShouldBeOfType(); + ((UserFailException)e.InnerException).Message.ShouldBe(":( your computer ran"); + } } } \ No newline at end of file diff --git a/VirtualMachine/Tests/Ceres.RuntimeTests/RuntimeModules/ModuleTest.cs b/VirtualMachine/Tests/Ceres.RuntimeTests/RuntimeModules/ModuleTest.cs index f3b36b24..3dc6bf77 100644 --- a/VirtualMachine/Tests/Ceres.RuntimeTests/RuntimeModules/ModuleTest.cs +++ b/VirtualMachine/Tests/Ceres.RuntimeTests/RuntimeModules/ModuleTest.cs @@ -1,4 +1,6 @@ using System; +using System.Threading; +using System.Threading.Tasks; using Ceres.ExecutionEngine; using Ceres.ExecutionEngine.Concurrency; using Ceres.ExecutionEngine.TypeSystem; @@ -35,20 +37,33 @@ public virtual void Setup() public virtual void Teardown() { _vm.Dispose(); - _evilRuntime = null; - _parser = null; - _compiler = null; + _evilRuntime = null!; + _parser = null!; + _compiler = null!; } protected DynamicValue EvilTestResult(string source, params DynamicValue[] args) { var chunk = _compiler.Compile(source, "!module_test_file!"); - + var waitForCrashHandler = true; + _vm.MainFiber.Schedule(chunk); _vm.MainFiber.Schedule(chunk["test"]!, false, args); _vm.MainFiber.Resume(); + + Exception? fiberException = null; + _vm.MainFiber.SetCrashHandler((f, e) => + { + fiberException = e; + waitForCrashHandler = false; + }); _vm.MainFiber.BlockUntilFinished(); + + while (waitForCrashHandler) + { + Thread.Sleep(1); + } if (_vm.MainFiber.State == FiberState.Finished) { @@ -57,7 +72,7 @@ protected DynamicValue EvilTestResult(string source, params DynamicValue[] args) if (_vm.MainFiber.State == FiberState.Crashed) { - throw new Exception("Test has failed inside EVIL world."); + throw new Exception("Test has failed inside EVIL world.", fiberException); } throw new Exception("There is something wrong with the awaiter logic or the fiber itself.");