Skip to content

Commit

Permalink
GD-163: Collect the Godot log file into test report (#164)
Browse files Browse the repository at this point in the history
# Why
see #163

# What
- Added `GodotProjectSettings` to load the current project settings
- Copy finally the Godot log file into the results directory
  • Loading branch information
MikeSchulze authored Nov 17, 2024
1 parent dda0203 commit ca23c88
Show file tree
Hide file tree
Showing 11 changed files with 488 additions and 5 deletions.
4 changes: 2 additions & 2 deletions .github/actions/upload-test-report/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ runs:
retention-days: 10
name: artifact_${{ inputs.report-name }}
path: |
./test/TestResults/test-result.trx
./test/TestResults/**
./test/reports/**
./example/TestResults/test-result.trx
./example/TestResults/**
./example/reports/**
/var/lib/systemd/coredump/**
/var/log/syslog
2 changes: 1 addition & 1 deletion testadapter.test/gdUnit4TestAdapter.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<TargetFramework>net8.0</TargetFramework>
<LangVersion>11.0</LangVersion>
<IsPackable>false</IsPackable>
<RootNamespace>GdUnit4.TestAdapter.Test</RootNamespace>
<RootNamespace>GdUnit4.TestAdapter</RootNamespace>

<AssemblyName>gdUnit4.TestAdapter.Test</AssemblyName>
<!-- warning CS8785, prevent Godot ScriptPathAttributeGenerator errors-->
Expand Down
14 changes: 14 additions & 0 deletions testadapter.test/test/TestUtils.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
namespace GdUnit4.TestAdapter.Test;

using System;
using System.IO;

public static class TestUtils
{
public static string GetResourcePath(string resourcePath)
{
var baseDir = AppDomain.CurrentDomain.BaseDirectory;
var projectRoot = Path.GetFullPath(Path.Combine(baseDir, "..", "..", ".."));
return Path.Combine(projectRoot, "test", "resources", resourcePath);
}
}
19 changes: 19 additions & 0 deletions testadapter.test/test/resources/project.godot
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
; Engine configuration file.
; It's best edited using the editor UI and not directly,
; since the parameters that go here are not all obvious.
;
; Format:
; [section] ; section goes between []
; param=value ; assign values to parameters

config_version=5

[application]

config/name="gdUnit4Test"
config/features=PackedStringArray("4.3", "C#", "Forward Plus")
config/icon="res://icon.svg"

[dotnet]

project/assembly_name="gdUnit4Test"
83 changes: 83 additions & 0 deletions testadapter.test/test/resources/project.godot2
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
; Engine configuration file.
; It's best edited using the editor UI and not directly,
; since the parameters that go here are not all obvious.
;
; Format:
; [section] ; section goes between []
; param=value ; assign values to parameters

config_version=5

[application]

config/name="gdUnit4"
config/tags=PackedStringArray("addon", "godot4", "testing")
config/features=PackedStringArray("4.3", "C#")
config/icon="res://icon.png"

[audio]

default_bus_layout=""

[debug]

file_logging/log_path="res://godot_session.log"
gdscript/warnings/exclude_addons=false
gdscript/warnings/untyped_declaration=2
gdscript/warnings/unsafe_property_access=1
gdscript/warnings/unsafe_method_access=1
gdscript/warnings/unsafe_cast=1
gdscript/warnings/unsafe_call_argument=1

[dotnet]

project/assembly_name="gdUnit4"

[editor_plugins]

enabled=PackedStringArray("res://addons/gdUnit4/plugin.cfg")

[gdunit4]

ui/inspector/node_collapse=false
ui/toolbar/run_overall=true
ui/inspector/tree_sort_mode=1
report/godot/script_error=false
settings/test/flaky_check_enable=true
settings/common/update_notification_enabled=false

[importer_defaults]

texture={
"compress/channel_pack": 0,
"compress/hdr_compression": 1,
"compress/high_quality": false,
"compress/lossy_quality": 0.7,
"compress/mode": 0,
"compress/normal_map": 0,
"detect_3d/compress_to": 1,
"editor/convert_colors_with_editor_theme": true,
"editor/scale_with_editor_scale": true,
"mipmaps/generate": false,
"mipmaps/limit": -1,
"process/fix_alpha_border": true,
"process/hdr_as_srgb": false,
"process/hdr_clamp_exposure": false,
"process/normal_map_invert_y": false,
"process/premult_alpha": false,
"process/size_limit": 0,
"roughness/mode": 0,
"roughness/src_normal": "",
"svg/scale": 1.0
}

[network]

limits/debugger_stdout/max_chars_per_second=60048
limits/debugger_stdout/max_messages_per_frame=100
limits/debugger_stdout/max_errors_per_second=1000
limits/debugger_stdout/max_warnings_per_second=1000

[rendering]

environment/default_environment="res://default_env.tres"
64 changes: 64 additions & 0 deletions testadapter.test/test/settings/GodotProjectSettingsTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
namespace GdUnit4.TestAdapter.Test.Settings;

using System.IO;

using Microsoft.VisualStudio.TestTools.UnitTesting;

using TestAdapter.Settings;

using static TestUtils;

using static TestAdapter.Utilities.Utils;

[TestClass]
public class GodotProjectSettingsTest
{
[TestMethod]
public void GlobalizeGodotPath()
{
// user specific path
Assert.AreEqual(
Path.Combine(GetUserDataDirectory, "app_userdata", "gdUnit4Test", "logs", "godot.log"),
GodotProjectSettings.GlobalizeGodotPath("user://logs/godot.log", "gdUnit4Test"));
// project specific path
Assert.AreEqual(
Path.Combine(GetProjectDirectory, "logs", "godot.log"),
GodotProjectSettings.GlobalizeGodotPath("res://logs/godot.log", "gdUnit4Test"));
}

[TestMethod]
public void LoadGodotProjectSettingsWithoutDebugSection()
{
var projectFile = GetResourcePath("project.godot");
var settings = GodotProjectSettings.LoadFromFile(projectFile);
Assert.IsNotNull(settings);

Assert.AreEqual("gdUnit4Test", settings.Application.Config.Name);
CollectionAssert.Contains(settings.Application.Config.Features, "4.3");
CollectionAssert.Contains(settings.Application.Config.Features, "C#");
Assert.AreEqual("res://icon.svg", settings.Application.Config.Icon);

// validate the log file path points to the default user dir
Assert.IsNotNull(settings.Debug);
var expectedLogFilePath = GodotProjectSettings.GlobalizeGodotPath("user://logs/godot.log", "gdUnit4Test");
Assert.AreEqual(expectedLogFilePath, settings.Debug.FileLogging.LogPath);
}

[TestMethod]
public void LoadGodotProjectSettingsWithCustomLogPath()
{
var projectFile = GetResourcePath("project.godot2");
var settings = GodotProjectSettings.LoadFromFile(projectFile);
Assert.IsNotNull(settings);

Assert.AreEqual("gdUnit4", settings.Application.Config.Name);
CollectionAssert.Contains(settings.Application.Config.Features, "4.3");
CollectionAssert.Contains(settings.Application.Config.Features, "C#");
Assert.AreEqual("res://icon.png", settings.Application.Config.Icon);

// validate the log file path points to project root
Assert.IsNotNull(settings.Debug);
var expectedLogFilePath = Path.Combine(GetProjectDirectory, "godot_session.log");
Assert.AreEqual(expectedLogFilePath, settings.Debug.FileLogging.LogPath);
}
}
4 changes: 2 additions & 2 deletions testadapter.test/test/settings/RunSettingsProviderTest.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
namespace GdUnit4.TestAdapter.Test.settings;
namespace GdUnit4.TestAdapter.Test.Settings;

using System.Collections.Generic;

using Microsoft.VisualStudio.TestTools.UnitTesting;

using Settings;
using TestAdapter.Settings;

[TestClass]
public class RunSettingsProviderTest
Expand Down
30 changes: 30 additions & 0 deletions testadapter.test/test/utilities/UtilsTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
namespace GdUnit4.TestAdapter.Test.Utilities;

using System;

using Microsoft.VisualStudio.TestTools.UnitTesting;

using static TestAdapter.Utilities.Utils;

[TestClass]
public class UtilsTest
{
[TestMethod]
public void ProjectDirectory()
=> Assert.IsTrue(GetProjectDirectory.EndsWith("testadapter.test"));

[TestMethod]
public void UserDataDirectory()
{
switch (Environment.OSVersion.Platform)
{
case PlatformID.Win32NT:
Assert.IsTrue(GetUserDataDirectory.EndsWith("Godot")); break;
case PlatformID.Unix:
Assert.IsTrue(GetUserDataDirectory.EndsWith("godot")); break;
case PlatformID.MacOSX:
Assert.IsTrue(GetUserDataDirectory.EndsWith("Library/Application Support/Godot"));
break;
}
}
}
33 changes: 33 additions & 0 deletions testadapter/src/execution/TestExecutor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,12 @@ public TestExecutor(RunConfiguration configuration, GdUnit4Settings gdUnit4Setti
SessionTimeOut = (int)(configuration.TestSessionTimeout == 0
? ITestExecutor.DefaultSessionTimeout
: configuration.TestSessionTimeout);
ResultsDirectory = configuration.ResultsDirectory;

this.gdUnit4Settings = gdUnit4Settings;
}

private string ResultsDirectory { get; }
private object CancelLock { get; } = new();
private object ProcessLock { get; } = new();

Expand Down Expand Up @@ -173,6 +175,7 @@ public void Run(IFrameworkHandle frameworkHandle, IRunContext runContext, IReadO
File.Delete(configName);
// wait until all event messages are processed or the client is disconnected
testEventServerTask.Wait(TimeSpan.FromSeconds(1));
CollectGodotLogFile(frameworkHandle);
}
}

Expand Down Expand Up @@ -261,4 +264,34 @@ public override void _Ready()
""";
File.WriteAllText(Path.Combine(destinationFolderPath, "TestAdapterRunner.tscn"), srcTestRunnerScene);
}

private void CollectGodotLogFile(IFrameworkHandle frameworkHandle)
{
var godotProjectFile = Path.Combine(Directory.GetCurrentDirectory(), "project.godot");
if (!File.Exists(godotProjectFile))
return;

frameworkHandle.SendMessage(TestMessageLevel.Informational, "Append Godot logfile to the Results.");
try
{
var projectSettings = GodotProjectSettings.LoadFromFile(godotProjectFile);
var godotLogFile = projectSettings.Debug.FileLogging.LogPath;
if (!File.Exists(godotLogFile))
{
frameworkHandle.SendMessage(TestMessageLevel.Informational, $"Can't copy the Godot logfile, it is not found at: {godotLogFile}");
return;
}

var resultDir = Path.Combine(Directory.GetCurrentDirectory(), ResultsDirectory);
if (!Directory.Exists(resultDir))
Directory.CreateDirectory(resultDir);

var godotLogFileCopy = Path.Combine(Directory.GetCurrentDirectory(), ResultsDirectory, "godot.log");
File.Copy(godotLogFile, godotLogFileCopy);
}
catch (Exception e)
{
frameworkHandle.SendMessage(TestMessageLevel.Error, $"Can't copy the Godot logfile: {e.Message}");
}
}
}
Loading

0 comments on commit ca23c88

Please sign in to comment.