Add prototype serialization tests. (#18458)
Co-authored-by: metalgearsloth <31366439+metalgearsloth@users.noreply.github.com>
This commit is contained in:
@@ -40,7 +40,7 @@ public sealed class PrototypeSaveTest
|
||||
[Test]
|
||||
public async Task UninitializedSaveTest()
|
||||
{
|
||||
// Apparently SpawnTest fails to clean up properly. Due to the similarities, I'll assume this also fails.
|
||||
// Apparently SpawnTest fails to clean up properly. Due to the similarities, I'll assume this also fails.
|
||||
await using var pairTracker = await PoolManager.GetServerClient();
|
||||
var server = pairTracker.Pair.Server;
|
||||
|
||||
@@ -190,14 +190,14 @@ public sealed class PrototypeSaveTest
|
||||
await pairTracker.CleanReturnAsync();
|
||||
}
|
||||
|
||||
private sealed class TestEntityUidContext : ISerializationContext,
|
||||
public sealed class TestEntityUidContext : ISerializationContext,
|
||||
ITypeSerializer<EntityUid, ValueDataNode>
|
||||
{
|
||||
public SerializationManager.SerializerProvider SerializerProvider { get; }
|
||||
public bool WritingReadingPrototypes { get; set; }
|
||||
|
||||
public string WritingComponent = string.Empty;
|
||||
public EntityPrototype Prototype = default!;
|
||||
public EntityPrototype? Prototype;
|
||||
|
||||
public TestEntityUidContext()
|
||||
{
|
||||
@@ -215,7 +215,7 @@ public sealed class PrototypeSaveTest
|
||||
IDependencyCollection dependencies, bool alwaysWrite = false,
|
||||
ISerializationContext? context = null)
|
||||
{
|
||||
if (WritingComponent != "Transform" && !Prototype.NoSpawn)
|
||||
if (WritingComponent != "Transform" && (Prototype?.NoSpawn == false))
|
||||
{
|
||||
// Maybe this will be necessary in the future, but at the moment it just indicates that there is some
|
||||
// issue, like a non-nullable entityUid data-field. If a component MUST have an entity uid to work with,
|
||||
|
||||
@@ -0,0 +1,52 @@
|
||||
using Robust.Shared.Prototypes;
|
||||
using Robust.UnitTesting;
|
||||
|
||||
namespace Content.IntegrationTests.Tests.PrototypeTests;
|
||||
|
||||
public sealed class PrototypeTests
|
||||
{
|
||||
/// <summary>
|
||||
/// This test writes all known prototypes as yaml files, then validates that the result is valid yaml.
|
||||
/// Can help prevent instances where prototypes have bad C# default values.
|
||||
/// </summary>
|
||||
[Test]
|
||||
public async Task TestAllPrototypesAreSerializable()
|
||||
{
|
||||
await using var pairTracker = await PoolManager.GetServerClient();
|
||||
var context = new PrototypeSaveTest.TestEntityUidContext();
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
Validate(pairTracker.Pair.Server, "server", context);
|
||||
|
||||
// TODO fix client serialization
|
||||
//Validate(pairTracker.Pair.Client, "client", context);
|
||||
});
|
||||
await pairTracker.CleanReturnAsync();
|
||||
}
|
||||
|
||||
public void Validate(RobustIntegrationTest.IntegrationInstance instance, string instanceId,
|
||||
PrototypeSaveTest.TestEntityUidContext ctx)
|
||||
{
|
||||
var protoMan = instance.ResolveDependency<IPrototypeManager>();
|
||||
var errors = protoMan.ValidateAllPrototypesSerializable(ctx);
|
||||
|
||||
if (errors.Count == 0)
|
||||
return;
|
||||
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
foreach (var (kind, ids) in errors)
|
||||
{
|
||||
foreach (var (id, nodes) in ids)
|
||||
{
|
||||
var msg = $"Error when validating {instanceId} prototype ({kind.Name}, {id}). Errors: \n";
|
||||
foreach (var errorNode in nodes)
|
||||
{
|
||||
msg += $" - {errorNode.ErrorReason}\n";
|
||||
}
|
||||
Assert.Fail(msg);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user