Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Code coverage #1

Closed
wants to merge 3 commits into from
Closed
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
16 changes: 14 additions & 2 deletions Content.Tests/DMTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using NUnit.Framework;
using OpenDreamRuntime;
using OpenDreamRuntime.Objects;
using OpenDreamRuntime.Procs.DebugAdapter;
using OpenDreamRuntime.Rendering;
using OpenDreamShared.Rendering;
using Robust.Shared.Asynchronous;
Expand All @@ -29,6 +30,7 @@ public sealed class DMTests : ContentUnitTest {
[Dependency] private readonly DreamManager _dreamMan = default!;
[Dependency] private readonly DreamObjectTree _objectTree = default!;
[Dependency] private readonly ITaskManager _taskManager = default!;
[Dependency] private readonly IDreamDebugManager _debugManager = default!;

[Flags]
public enum DMTestFlags {
Expand Down Expand Up @@ -71,7 +73,7 @@ private static void Cleanup(string? compiledFile) {
}

[Test, TestCaseSource(nameof(GetTests))]
public void TestFiles(string sourceFile, DMTestFlags testFlags) {
public void TestFiles(string sourceFile, string coverageFile, string coverageDirectory, DMTestFlags testFlags) {
string initialDirectory = Directory.GetCurrentDirectory();
TestContext.WriteLine($"--- TEST {sourceFile} | Flags: {testFlags}");
try {
Expand All @@ -85,10 +87,15 @@ 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}");

_debugManager.InitializeCoverage(coverageFile, coverageDirectory);

_dreamMan.StartWorld();

(bool successfulRun, DreamValue? returned, Exception? exception) = RunTest();

_debugManager.Shutdown();

if (testFlags.HasFlag(DMTestFlags.NoReturn)) {
Assert.IsFalse(returned.HasValue, "proc returned unexpectedly");
} else {
Expand Down Expand Up @@ -137,8 +144,11 @@ public void TestFiles(string sourceFile, DMTestFlags testFlags) {
var watch = new Stopwatch();
watch.Start();

// hack to hopefully force spawned calls to finish
var iterationsRemaining = 100;

// Tick until our inner call has finished
while (!callTask.IsCompleted) {
while (!callTask.IsCompleted || iterationsRemaining-- > 0) {
_dreamMan.Update();
_taskManager.ProcessPendingTasks();

Expand All @@ -163,6 +173,8 @@ private static IEnumerable<object[]> GetTests()

yield return new object[] {
sourceFile2,
Path.GetFullPath($"{sourceFile[..^2]}coverage.xml"),
Path.GetFullPath(TestProject),
testFlags
};
}
Expand Down
7 changes: 6 additions & 1 deletion OpenDreamRuntime/EntryPoint.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,18 @@ public override void Init() {
public override void PostInit() {
_commandSystem = _entitySystemManager.GetEntitySystem<DreamCommandSystem>();

var codeCoverageOutputFile = _configManager.GetCVar(OpenDreamCVars.CodeCoverage);
if (!String.IsNullOrWhiteSpace(codeCoverageOutputFile)) {
_debugManager.InitializeCoverage(codeCoverageOutputFile, Path.GetFullPath(Environment.CurrentDirectory));
}

int debugAdapterPort = _configManager.GetCVar(OpenDreamCVars.DebugAdapterLaunched);
if (debugAdapterPort == 0) {
_dreamManager.PreInitialize(_configManager.GetCVar<string>(OpenDreamCVars.JsonPath));
_dreamManager.StartWorld();
} else {
// The debug manager is responsible for running _dreamManager.PreInitialize() and .StartWorld()
_debugManager.Initialize(debugAdapterPort);
_debugManager.InitializeDebugging(debugAdapterPort);
}
}

Expand Down
13 changes: 7 additions & 6 deletions OpenDreamRuntime/Objects/DreamObjectTree.cs
Original file line number Diff line number Diff line change
Expand Up @@ -73,19 +73,20 @@ public void LoadJson(DreamCompiledJson json) {

Strings = json.Strings ?? new();

if (json.GlobalInitProc is { } initProcDef) {
GlobalInitProc = new DMProc(0, DreamPath.Root, initProcDef, "<global init>", _dreamManager, _atomManager, _dreamMapManager, _dreamDebugManager, _dreamResourceManager, this, _procScheduler);
} else {
GlobalInitProc = null;
}

var types = json.Types ?? Array.Empty<DreamTypeJson>();
var procs = json.Procs;
var globalProcs = json.GlobalProcs;

// Load procs first so types can set their init proc's super proc
LoadProcsFromJson(types, procs, globalProcs);
LoadTypesFromJson(types);

if (json.GlobalInitProc is { } initProcDef) {
GlobalInitProc = new DMProc(Procs.Count, DreamPath.Root, initProcDef, "<global init>", _dreamManager, _atomManager, _dreamMapManager, _dreamDebugManager, _dreamResourceManager, this, _procScheduler);
Procs.Add(GlobalInitProc);
} else {
GlobalInitProc = null;
}
}

public TreeEntry GetTreeEntry(DreamPath path) {
Expand Down
Loading
Loading