From 64327326fd19440fb31755122d5723b64cd33fb8 Mon Sep 17 00:00:00 2001 From: Tayrtahn Date: Thu, 17 Apr 2025 06:10:23 -0400 Subject: [PATCH] Make AllComponentsOneToOneDeleteTest skip components with Required fields (#30582) --- Content.IntegrationTests/Tests/EntityTest.cs | 36 +++++++++++++++++--- 1 file changed, 32 insertions(+), 4 deletions(-) diff --git a/Content.IntegrationTests/Tests/EntityTest.cs b/Content.IntegrationTests/Tests/EntityTest.cs index 6b8b59a12c..26365d8d96 100644 --- a/Content.IntegrationTests/Tests/EntityTest.cs +++ b/Content.IntegrationTests/Tests/EntityTest.cs @@ -9,6 +9,7 @@ using Robust.Shared.Log; using Robust.Shared.Map; using Robust.Shared.Maths; using Robust.Shared.Prototypes; +using Robust.Shared.Serialization.Manager.Attributes; namespace Content.IntegrationTests.Tests { @@ -333,6 +334,33 @@ namespace Content.IntegrationTests.Tests await pair.CleanReturnAsync(); } + private static bool HasRequiredDataField(Component component) + { + foreach (var field in component.GetType().GetFields()) + { + foreach (var attribute in field.GetCustomAttributes(true)) + { + if (attribute is not DataFieldAttribute dataField) + continue; + + if (dataField.Required) + return true; + } + } + foreach (var property in component.GetType().GetProperties()) + { + foreach (var attribute in property.GetCustomAttributes(true)) + { + if (attribute is not DataFieldAttribute dataField) + continue; + + if (dataField.Required) + return true; + } + } + return false; + } + [Test] public async Task AllComponentsOneToOneDeleteTest() { @@ -357,9 +385,6 @@ namespace Content.IntegrationTests.Tests "ActivatableUI", // Requires enum key }; - // TODO TESTS - // auto ignore any components that have a "required" data field. - await using var pair = await PoolManager.GetServerClient(); var server = pair.Server; var entityManager = server.ResolveDependency(); @@ -377,9 +402,12 @@ namespace Content.IntegrationTests.Tests foreach (var type in componentFactory.AllRegisteredTypes) { - var component = (Component) componentFactory.GetComponent(type); + var component = (Component)componentFactory.GetComponent(type); var name = componentFactory.GetComponentName(type); + if (HasRequiredDataField(component)) + continue; + // If this component is ignored if (skipComponents.Contains(name)) { -- 2.51.2