]> git.smokeofanarchy.ru Git - space-station-14.git/commitdiff
Make AllComponentsOneToOneDeleteTest skip components with Required fields (#30582)
authorTayrtahn <tayrtahn@gmail.com>
Thu, 17 Apr 2025 10:10:23 +0000 (06:10 -0400)
committerGitHub <noreply@github.com>
Thu, 17 Apr 2025 10:10:23 +0000 (20:10 +1000)
Content.IntegrationTests/Tests/EntityTest.cs

index 6b8b59a12cb94471837d566cbdd9de63b959e7fb..26365d8d96ffcffe762a17a37fe02fc59a1d590a 100644 (file)
@@ -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<IEntityManager>();
@@ -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))
                         {