Add support for tests to load extra prototypes from multiple "files" (#4232)

This commit is contained in:
Leon Friedrich
2023-08-04 16:50:08 +12:00
committed by GitHub
parent ce8b2d82a3
commit 2ff99d4a62

View File

@@ -19,7 +19,6 @@ using Robust.Server;
using Robust.Server.Console;
using Robust.Server.ServerStatus;
using Robust.Shared;
using Robust.Shared.Analyzers;
using Robust.Shared.Asynchronous;
using Robust.Shared.Configuration;
using Robust.Shared.ContentPack;
@@ -30,7 +29,6 @@ using Robust.Shared.Log;
using Robust.Shared.Network;
using Robust.Shared.Serialization;
using Robust.Shared.Timing;
using Robust.Shared.Utility;
using ServerProgram = Robust.Server.Program;
namespace Robust.UnitTesting
@@ -544,6 +542,23 @@ namespace Robust.UnitTesting
{
Stop();
}
protected void LoadExtraPrototypes(IDependencyCollection deps, IntegrationOptions options)
{
var resMan = deps.Resolve<IResourceManagerInternal>();
if (options.ExtraPrototypes != null)
{
resMan.MountString("/Prototypes/__integration_extra.yml", options.ExtraPrototypes);
}
if (options.ExtraPrototypeList is {} list)
{
for (var i = 0; i < list.Count; i++)
{
resMan.MountString($"/Prototypes/__integration_extra_{i}.yml", list[i]);
}
}
}
}
public sealed class ServerIntegrationInstance : IntegrationInstance
@@ -646,12 +661,7 @@ namespace Robust.UnitTesting
{
Options.BeforeStart?.Invoke();
cfg.OverrideConVars(Options.CVarOverrides.Select(p => (p.Key, p.Value)));
if (Options.ExtraPrototypes != null)
{
deps.Resolve<IResourceManagerInternal>()
.MountString("/Prototypes/__integration_extra.yml", Options.ExtraPrototypes);
}
LoadExtraPrototypes(deps, Options);
}
cfg.OverrideConVars(new[]
@@ -814,12 +824,7 @@ namespace Robust.UnitTesting
{
Options.BeforeStart?.Invoke();
cfg.OverrideConVars(Options.CVarOverrides.Select(p => (p.Key, p.Value)));
if (Options.ExtraPrototypes != null)
{
deps.Resolve<IResourceManagerInternal>()
.MountString("/Prototypes/__integration_extra.yml", Options.ExtraPrototypes);
}
LoadExtraPrototypes(deps, Options);
}
cfg.OverrideConVars(new[]
@@ -1002,7 +1007,19 @@ namespace Robust.UnitTesting
public Action? BeforeRegisterComponents { get; set; }
public Action? BeforeStart { get; set; }
public Assembly[]? ContentAssemblies { get; set; }
/// <summary>
/// String containing extra prototypes to load. Contents of the string are treated like a yaml file in the
/// resources folder.
/// </summary>
public string? ExtraPrototypes { get; set; }
/// <summary>
/// List of strings containing extra prototypes to load. Contents of the strings are treated like yaml files
/// in the resources folder.
/// </summary>
public List<string>? ExtraPrototypeList;
public LogLevel? FailureLogLevel { get; set; } = RTCVars.FailureLogLevel.DefaultValue;
public bool ContentStart { get; set; } = false;