Skip to content

Commit

Permalink
Update world.time in DMTests
Browse files Browse the repository at this point in the history
  • Loading branch information
Cyberboss committed Nov 29, 2023
1 parent f0e4f27 commit 750403d
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions Content.Tests/DMTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ public sealed class DMTests : ContentUnitTest {
[Dependency] private readonly DreamObjectTree _objectTree = default!;
[Dependency] private readonly ProcScheduler _procScheduler = default!;
[Dependency] private readonly ITaskManager _taskManager = default!;
[Dependency] private readonly IGameTiming _gameTiming = default!;

[Flags]
public enum DMTestFlags {
Expand Down Expand Up @@ -87,6 +88,8 @@ public void TestFiles(string sourceFile, DMTestFlags testFlags) {

Assert.IsTrue(compiledFile is not null && File.Exists(compiledFile), "Failed to compile DM source file");
Assert.IsTrue(_dreamMan.LoadJson(compiledFile), $"Failed to load {compiledFile}");

_gameTiming.CurTick = new(1);
_dreamMan.StartWorld();

(bool successfulRun, DreamValue? returned, Exception? exception) = RunTest();
Expand Down Expand Up @@ -136,17 +139,17 @@ public void TestFiles(string sourceFile, DMTestFlags testFlags) {
}
});

var watch = new Stopwatch();
watch.Start();

var totalTicks = 0;
// Tick until our inner call has finished
while (!callTask.IsCompleted || _procScheduler.HasProcsQueued || _procScheduler.HasProcsSleeping) {
if (++totalTicks > 100000) {
Assert.Fail("Test ran for too many ticks!");
}

_dreamMan.Update();
_taskManager.ProcessPendingTasks();

if (watch.Elapsed.TotalSeconds > 5) {
Assert.Fail("Test timed out");
}
_gameTiming.CurTick += 1;
}

bool retSuccess = _dreamMan.LastDMException == prev; // Works because "null == null" is true in this language.
Expand Down

0 comments on commit 750403d

Please sign in to comment.