Cleanup most warnings in unit tests (#5946)

* 2 warnings in JointDeletion_Test

* 1 warning in Collision_Test

* 2 warnings in Color_Test (deleted test of deprecated HCY color space)

* 1 warning in MapVelocity_Test

* 2 warnings in MapManager_Tests

* 2 warnings in MapPauseTests

* 1 warning in NetDisconnectMessageTest

* 1 warning in ContainerTests

* Suppress 1 warning in EntityEventBusTests.ComponentEvent

* 4 warnings in MapGridMap_Tests

* 1 warning in GridDeletion_Test

* Remove TryGetContainingContainer foolishness

---------

Co-authored-by: metalgearsloth <31366439+metalgearsloth@users.noreply.github.com>
This commit is contained in:
Tayrtahn
2025-05-28 10:12:58 -04:00
committed by GitHub
parent 50e06e43fa
commit 6d46d3f4a5
10 changed files with 28 additions and 33 deletions

View File

@@ -133,7 +133,9 @@ namespace Robust.UnitTesting.Shared.GameObjects
var entManMock = new Mock<IEntityManager>();
#pragma warning disable CS0618 // Type or member is obsolete
compInstance.Owner = entUid;
#pragma warning restore CS0618 // Type or member is obsolete
var compRegistration = new ComponentRegistration(
"MetaData",

View File

@@ -1,3 +1,4 @@
using System.Collections.Generic;
using System.Linq;
using NUnit.Framework;
using Robust.Shared.GameObjects;
@@ -21,12 +22,16 @@ public sealed class MapGridMap_Tests
var entManager = sim.Resolve<IEntityManager>();
var mapManager = sim.Resolve<IMapManager>();
var mapSystem = entManager.System<SharedMapSystem>();
var mapId = sim.CreateMap().MapId;
Assert.That(!mapManager.FindGridsIntersecting(mapId, Box2.UnitCentered).Any());
List<Entity<MapGridComponent>> grids = [];
mapManager.FindGridsIntersecting(mapId, Box2.UnitCentered, ref grids);
Assert.That(grids, Is.Empty);
entManager.AddComponent<MapGridComponent>(mapManager.GetMapEntityId(mapId));
Assert.That(mapManager.FindGridsIntersecting(mapId, Box2.UnitCentered).Count() == 1);
entManager.AddComponent<MapGridComponent>(mapSystem.GetMapOrInvalid(mapId));
mapManager.FindGridsIntersecting(mapId, Box2.UnitCentered, ref grids);
Assert.That(grids, Has.Count.EqualTo(1));
}
/// <summary>
@@ -46,7 +51,7 @@ public sealed class MapGridMap_Tests
Assert.DoesNotThrow(() =>
{
entManager.AddComponent<MapGridComponent>(mapManager.GetMapEntityId(mapId));
entManager.AddComponent<MapGridComponent>(mapSystem.GetMapOrInvalid(mapId));
entManager.TickUpdate(0.016f, false);
});

View File

@@ -27,12 +27,14 @@ namespace Robust.UnitTesting.Shared.Map
{
var sim = SimulationFactory();
var mapMan = sim.Resolve<IMapManager>();
var entMan = sim.Resolve<IEntityManager>();
var mapSys = entMan.System<SharedMapSystem>();
var mapID = sim.CreateMap().MapId;
mapMan.Restart();
Assert.That(mapMan.MapExists(mapID), Is.False);
Assert.That(mapSys.MapExists(mapID), Is.False);
}
/// <summary>
@@ -62,7 +64,7 @@ namespace Robust.UnitTesting.Shared.Map
var sim = SimulationFactory();
var entMan = sim.Resolve<IEntityManager>();
var oldEntity = entMan.CreateEntityUninitialized(null, MapCoordinates.Nullspace);
entMan.InitializeComponents(oldEntity);
entMan.InitializeEntity(oldEntity);
entMan.FlushEntities();
Assert.That(entMan.Deleted(oldEntity), Is.True);
}

View File

@@ -150,19 +150,17 @@ internal sealed class MapPauseTests
{
var sim = SimulationFactory();
var entMan = sim.Resolve<IEntityManager>();
var mapMan = sim.Resolve<IMapManager>();
// arrange
var map1 = sim.CreateMap().Uid;
entMan.System<SharedMapSystem>().SetPaused(map1, true);
var newEnt = entMan.SpawnEntity(null, new EntityCoordinates(map1, default));
var xform = entMan.GetComponent<TransformComponent>(newEnt);
var map2 = sim.CreateMap().Uid;
entMan.System<SharedMapSystem>().SetPaused(map2, false);
// Act
entMan.EntitySysManager.GetEntitySystem<SharedTransformSystem>().SetParent(xform.Owner, map2);
entMan.EntitySysManager.GetEntitySystem<SharedTransformSystem>().SetParent(newEnt, map2);
var metaData = entMan.GetComponent<MetaDataComponent>(newEnt);
Assert.That(metaData.EntityPaused, Is.False);
@@ -177,19 +175,17 @@ internal sealed class MapPauseTests
{
var sim = SimulationFactory();
var entMan = sim.Resolve<IEntityManager>();
var mapMan = sim.Resolve<IMapManager>();
// arrange
var map1 = sim.CreateMap().Uid;
entMan.System<SharedMapSystem>().SetPaused(map1, false);
var newEnt = entMan.SpawnEntity(null, new EntityCoordinates(map1, default));
var xform = entMan.GetComponent<TransformComponent>(newEnt);
var map2 = sim.CreateMap().Uid;
entMan.System<SharedMapSystem>().SetPaused(map2, true);
// Act
entMan.EntitySysManager.GetEntitySystem<SharedTransformSystem>().SetParent(xform.Owner, map2);
entMan.EntitySysManager.GetEntitySystem<SharedTransformSystem>().SetParent(newEnt, map2);
var metaData = entMan.GetComponent<MetaDataComponent>(newEnt);
Assert.That(metaData.EntityPaused, Is.True);

View File

@@ -396,17 +396,6 @@ namespace Robust.UnitTesting.Shared.Maths
Assert.That(MathHelper.CloseToPercent(color, controlColor));
}
[Test]
public void ToFromHcy([ValueSource(nameof(FourFloatsSource))] (float, float, float, float) floats)
{
var (rf, gf, bf, af) = floats;
var controlColor = new Color(rf, gf, bf, af);
var color = Color.FromHcy(Color.ToHcy(controlColor));
Assert.That(MathHelper.CloseToPercent(color, controlColor));
}
static IEnumerable<float> InterpolationValues => new float[]
{
0f,

View File

@@ -41,7 +41,7 @@ internal sealed class NetDisconnectMessageTest
};
var encoded = value.Encode();
TestContext.Write($"Encoded: {encoded}\n");
TestContext.Out.Write($"Encoded: {encoded}\n");
var decodedAgain = NetDisconnectMessage.Decode(encoded);
Assert.Multiple(() =>

View File

@@ -122,10 +122,10 @@ public sealed class Collision_Test
{
var sim = RobustServerSimulation.NewSimulation().InitializeInstance();
var entManager = sim.Resolve<IEntityManager>();
var mapManager = sim.Resolve<IMapManager>();
var fixtures = entManager.System<FixtureSystem>();
var physics = entManager.System<SharedPhysicsSystem>();
var xformSystem = entManager.System<SharedTransformSystem>();
var mapSystem = entManager.System<SharedMapSystem>();
var mapId = sim.CreateMap().MapId;
var mapId2 = sim.CreateMap().MapId;
@@ -151,7 +151,7 @@ public sealed class Collision_Test
Assert.That(body1.ContactCount == 1 && body2.ContactCount == 1);
// Reparent body2 and assert the contact is destroyed
xformSystem.SetParent(ent2, mapManager.GetMapEntityId(mapId2));
xformSystem.SetParent(ent2, mapSystem.GetMapOrInvalid(mapId2));
physics.Update(0.01f);
Assert.That(body1.ContactCount == 0 && body2.ContactCount == 0);

View File

@@ -1,3 +1,4 @@
using System.Collections.Generic;
using System.Numerics;
using System.Threading.Tasks;
using NUnit.Framework;
@@ -52,12 +53,11 @@ public sealed class GridDeletion_Test : RobustIntegrationTest
Assert.That(physics.LinearVelocity.Length, NUnit.Framework.Is.GreaterThan(0f));
entManager.DeleteEntity(grid);
List<Entity<MapGridComponent>> grids = [];
// So if gridtree is fucky then this SHOULD throw.
foreach (var _ in mapManager.FindGridsIntersecting(mapId,
mapManager.FindGridsIntersecting(mapId,
new Box2(new Vector2(float.MinValue, float.MinValue),
new Vector2(float.MaxValue, float.MaxValue))))
{
}
new Vector2(float.MaxValue, float.MaxValue)), ref grids);
});
}
}

View File

@@ -35,11 +35,12 @@ public sealed class JointDeletion_Test : RobustIntegrationTest
EntityUid ent2 = default!;
PhysicsComponent body1;
PhysicsComponent body2 = default!;
EntityUid mapEnt = default!;
MapId mapId = default!;
await server.WaitPost(() =>
{
entManager.System<SharedMapSystem>().CreateMap(out mapId);
mapEnt = entManager.System<SharedMapSystem>().CreateMap(out mapId);
ent1 = entManager.SpawnEntity(null, new MapCoordinates(Vector2.Zero, mapId));
ent2 = entManager.SpawnEntity(null, new MapCoordinates(Vector2.One, mapId));
@@ -67,7 +68,7 @@ public sealed class JointDeletion_Test : RobustIntegrationTest
await server.WaitAssertion(() =>
{
Assert.That(joint.Enabled);
physicsSystem.SetAwake(ent2, body2, false);
physicsSystem.SetAwake((ent2, body2), false);
Assert.That(!body2.Awake);
entManager.DeleteEntity(ent2);

View File

@@ -162,7 +162,7 @@ namespace Robust.UnitTesting.Shared.Physics
Assert.That(velocities.Item2, Is.Approximately(angularVelocity, 1e-6));
// but not if we update the local position:
xformSystem.SetWorldPosition(xform2!, Vector2.Zero);
xformSystem.SetWorldPosition((dummy2, xform2!), Vector2.Zero);
linearVelocity = physicsSys.GetMapLinearVelocity(dummy2, body2);
angularVelocity = physicsSys.GetMapAngularVelocity(dummy2, body2);
velocities = physicsSys.GetMapVelocities(dummy2, body2);