Skip to content

Commit

Permalink
Add core test fail, provide inner exception when a test case fails in…
Browse files Browse the repository at this point in the history
…side EVIL.
  • Loading branch information
vddCore committed May 18, 2024
1 parent 797ee6c commit 44a74df
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<IsPackable>false</IsPackable>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Ceres.ExecutionEngine.Collections;
using System;
using Ceres.Runtime;
using Ceres.Runtime.Modules;
using NUnit.Framework;
using Shouldly;
Expand All @@ -7,6 +8,12 @@ namespace Ceres.RuntimeTests.RuntimeModules
{
public class CoreModuleTest : ModuleTest<CoreModule>
{

[Test]
public void CoreFailTerminatesExecution()
{
var e = Should.Throw<Exception>(() => EvilTestResult("(fn -> core.fail(':( your computer ran'))();"));
e.InnerException.ShouldBeOfType<UserFailException>();
((UserFailException)e.InnerException).Message.ShouldBe(":( your computer ran");
}
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using System;
using System.Threading;
using System.Threading.Tasks;
using Ceres.ExecutionEngine;
using Ceres.ExecutionEngine.Concurrency;
using Ceres.ExecutionEngine.TypeSystem;
Expand Down Expand Up @@ -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)
{
Expand All @@ -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.");
Expand Down

0 comments on commit 44a74df

Please sign in to comment.