From 2ff99d4a62c06b32b486f5c8e7d2671f59d2b503 Mon Sep 17 00:00:00 2001 From: Leon Friedrich <60421075+ElectroJr@users.noreply.github.com> Date: Fri, 4 Aug 2023 16:50:08 +1200 Subject: [PATCH] Add support for tests to load extra prototypes from multiple "files" (#4232) --- Robust.UnitTesting/RobustIntegrationTest.cs | 45 ++++++++++++++------- 1 file changed, 31 insertions(+), 14 deletions(-) diff --git a/Robust.UnitTesting/RobustIntegrationTest.cs b/Robust.UnitTesting/RobustIntegrationTest.cs index 97607ef9c..40ff16816 100644 --- a/Robust.UnitTesting/RobustIntegrationTest.cs +++ b/Robust.UnitTesting/RobustIntegrationTest.cs @@ -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(); + 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() - .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() - .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; } + + /// + /// String containing extra prototypes to load. Contents of the string are treated like a yaml file in the + /// resources folder. + /// public string? ExtraPrototypes { get; set; } + + /// + /// List of strings containing extra prototypes to load. Contents of the strings are treated like yaml files + /// in the resources folder. + /// + public List? ExtraPrototypeList; + public LogLevel? FailureLogLevel { get; set; } = RTCVars.FailureLogLevel.DefaultValue; public bool ContentStart { get; set; } = false;