mirror of
https://github.com/DeltaV-Station/Delta-v.git
synced 2026-10-01 00:27:59 +00:00
* Ports much of GameTest, minus all the WIP stuff. * remark. * EnsureCVar now adds test properties. * Some cleanup and functionality. * Ignore broken test. Needs fixed eventually. Also explicit context config. * TrackingIssue attribute. * oops * Pair config attribute. * Remove SystemAttribute in favor of using the EntitySystemManager dependency collection. * Ensure idleness. * More tests for tests. * More specific failure catching tests. * Reverse attribute resolution order so suite-wide attributes happen first. * Get rid of AffectedProperties again because I need to refactor PoolSettings for that. * Poke * Final cleanup pass. * Update Content.IntegrationTests/Fixtures/Attributes/RunOnSideAttribute.cs Co-authored-by: Tayrtahn <tayrtahn@gmail.com> * Update Content.IntegrationTests/Fixtures/Attributes/Side.cs Co-authored-by: Tayrtahn <tayrtahn@gmail.com> * Update Content.IntegrationTests/NUnit/Utilities/ITestExtensions.cs Co-authored-by: Tayrtahn <tayrtahn@gmail.com> * Fixes. * shut up nunit. * Make TrackingIssue a bit strict on purpose, so people don't put junk here. * Update Content.IntegrationTests/Tests/GameTestTests/DisconnectedDependencyTest.cs Co-authored-by: Tayrtahn <tayrtahn@gmail.com> * Address. --------- Co-authored-by: Tayrtahn <tayrtahn@gmail.com>
84 lines
2.8 KiB
C#
84 lines
2.8 KiB
C#
#nullable enable
|
|
using System.Collections.Generic;
|
|
using Content.IntegrationTests.Fixtures.Attributes;
|
|
using Robust.Shared.Configuration;
|
|
|
|
namespace Content.IntegrationTests.Fixtures;
|
|
|
|
// REMARK: You may be wondering why this doesn't bother storing the old CVars.
|
|
// This is because TestPair actually has some not-well-known functionality to
|
|
// automatically restore CVars to what they were pre-test for you.
|
|
//
|
|
// So instead of rolling that twice, this lets TestPair handle it.
|
|
public abstract partial class GameTest
|
|
{
|
|
[SidedDependency(Side.Server)] private readonly IConfigurationManager _serverCfg = default!;
|
|
[SidedDependency(Side.Client)] private readonly IConfigurationManager _clientCfg = default!;
|
|
|
|
private readonly Dictionary<string, object> _clientCVarOverrides = new();
|
|
private readonly Dictionary<string, object> _serverCVarOverrides = new();
|
|
|
|
/// <summary>
|
|
/// Adds a setup-time override for a given cvar, for use by <see cref="IGameTestModifier"/>s.
|
|
/// </summary>
|
|
public void PreTestAddOverride(Side side, string cVar, object value)
|
|
{
|
|
// ReSharper disable once ConditionIsAlwaysTrueOrFalse
|
|
if (_setupDone)
|
|
throw new NotSupportedException("Cannot use PreTest functions after test SetUp.");
|
|
|
|
if (side is Side.Neither)
|
|
throw new NotSupportedException($"Must specify a side, or both, for {nameof(PreTestAddOverride)}");
|
|
|
|
if ((side & Side.Server) != 0)
|
|
_serverCVarOverrides.Add(cVar, value);
|
|
|
|
if ((side & Side.Client) != 0)
|
|
_clientCVarOverrides.Add(cVar, value);
|
|
}
|
|
|
|
private async Task DoPreTestOverrides()
|
|
{
|
|
foreach (var (cvar, value) in _clientCVarOverrides)
|
|
{
|
|
await OverrideCVarByName(Side.Client, cvar, value, false);
|
|
}
|
|
|
|
foreach (var (cvar, value) in _serverCVarOverrides)
|
|
{
|
|
await OverrideCVarByName(Side.Server, cvar, value, false);
|
|
}
|
|
|
|
await Pair.RunUntilSynced();
|
|
}
|
|
|
|
/// <summary>
|
|
/// Sets a given CVar for the provided side.
|
|
/// </summary>
|
|
/// <remarks>Does its own cleanup, you do not need to set the CVar back yourself.</remarks>
|
|
public async Task OverrideCVar<T>(Side side, CVarDef<T> cvar, T value, bool sync = true)
|
|
where T: notnull
|
|
{
|
|
await OverrideCVarByName(side, cvar.Name, value, sync);
|
|
}
|
|
|
|
private async Task OverrideCVarByName(Side side, string cVar, object value, bool sync)
|
|
{
|
|
if (side is Side.Client)
|
|
{
|
|
_clientCfg.SetCVar(cVar, value);
|
|
}
|
|
else if (side is Side.Server)
|
|
{
|
|
_serverCfg.SetCVar(cVar, value);
|
|
}
|
|
else
|
|
{
|
|
throw new NotSupportedException($"Expected a specific side, got {side}.");
|
|
}
|
|
|
|
if (sync)
|
|
await Pair.RunUntilSynced();
|
|
}
|
|
}
|