mirror of
https://github.com/space-wizards/RobustToolbox.git
synced 2026-02-14 19:29:36 +01:00
* Move to Central Package Management. Allows us to store NuGet package versions all in one place. Yay! * Update NuGet packages and fix code for changes. Notable: Changes to ILVerify. Npgsql doesn't need hacks for inet anymore, now we need hacks to make the old code work with this new reality. NUnit's analyzers are already complaining and I didn't even update it to 4.x yet. TerraFX changed to GetLastSystemError so error handling had to be changed. Buncha APIs have more NRT annotations. * Remove dotnet-eng NuGet package source. I genuinely don't know what this was for, and Central Package Management starts throwing warnings about it, so YEET. * Fix double loading of assemblies due to ALC shenanigans. Due to how the "sideloading" code for the ModLoader was set up, it would first try to load Microsoft.Extensions.Primitives from next to the content dll. But we already have that library in Robust! Chaos ensues. We now try to forcibly prioritize loading from the default ALC first to avoid this. * Remove Robust.Physics project. Never used. * Remove erroneous NVorbis reference. Should be VorbisPizza and otherwise wasn't used. * Sandbox fixes * Remove unused unit test package references. Castle.Core and NUnit.ConsoleRunner. * Update NUnit to 4.0.1 This requires replacing all the old assertion methods because they removed them 🥲 * Mute CA1416 (platform check) errors TerraFX started annotating APIs with this and I can't be arsed to entertain this analyzer so out it goes. * Fine ya cranky, no more CPM for Robust.Client.Injectors * Changelog * Oh so that's what dotnet-eng was used for. Yeah ok that makes sense. * Central package management for remaining 2 robust projects * Ok that was a bad idea let's just use NUnit 3 on the analyzer test project * Oh right forgot to remove this one * Update to a newer version of RemoteExecutor * Disable RemoteExecutor test https://github.com/dotnet/arcade/issues/8483 Yeah this package is not well maintained and clearly we can't rely on it. * Fix immutable list serialization
179 lines
4.5 KiB
C#
179 lines
4.5 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Threading.Tasks;
|
|
using NUnit.Framework;
|
|
using Robust.Shared.Network;
|
|
using Robust.Shared.Player;
|
|
using Robust.Shared.Toolshed;
|
|
using Robust.Shared.Toolshed.Errors;
|
|
using Robust.Shared.Toolshed.Syntax;
|
|
|
|
namespace Robust.UnitTesting.Shared.Toolshed;
|
|
|
|
[TestFixture, Parallelizable(ParallelScope.Fixtures)]
|
|
[FixtureLifeCycle(LifeCycle.SingleInstance)]
|
|
public abstract class ToolshedTest : RobustIntegrationTest, IInvocationContext
|
|
{
|
|
protected virtual bool AssertOnUnexpectedError => true;
|
|
|
|
protected ServerIntegrationInstance Server = default!;
|
|
|
|
public ToolshedManager Toolshed { get; private set; } = default!;
|
|
public ToolshedEnvironment Environment => Toolshed.DefaultEnvironment;
|
|
|
|
protected IInvocationContext? InvocationContext = null;
|
|
|
|
|
|
|
|
[TearDown]
|
|
public async Task TearDownInternal()
|
|
{
|
|
await TearDown();
|
|
Server.Dispose();
|
|
}
|
|
|
|
protected virtual async Task TearDown()
|
|
{
|
|
Assert.That(_expectedErrors, Is.Empty);
|
|
ClearErrors();
|
|
}
|
|
|
|
[SetUp]
|
|
public virtual async Task Setup()
|
|
{
|
|
var options = new ServerIntegrationOptions()
|
|
{
|
|
Pool = true
|
|
};
|
|
Server = StartServer(options);
|
|
|
|
await Server.WaitIdleAsync();
|
|
|
|
Toolshed = Server.ResolveDependency<ToolshedManager>();
|
|
}
|
|
|
|
protected bool InvokeCommand(string command, out object? result)
|
|
{
|
|
return Toolshed.InvokeCommand(this, command, null, out result);
|
|
}
|
|
|
|
protected T InvokeCommand<T>(string command)
|
|
{
|
|
InvokeCommand(command, out var res);
|
|
Assert.That(res, Is.AssignableTo<T>());
|
|
return (T) res!;
|
|
}
|
|
|
|
protected TOut InvokeCommand<TIn, TOut>(string command, TIn input)
|
|
{
|
|
Toolshed.InvokeCommand(this, command, input, out var res);
|
|
Assert.That(res, Is.AssignableTo<TOut>());
|
|
return (TOut) res!;
|
|
}
|
|
|
|
protected ParserContext Parser(string input) => new ParserContext(input, Toolshed);
|
|
|
|
protected void AssertParseable<T>()
|
|
{
|
|
Toolshed.TryParse<T>(Parser(""), out _, out var err);
|
|
Assert.That(err, Is.Not.TypeOf<UnparseableValueError>(), $"Couldn't find a parser for {typeof(T).PrettyName()}");
|
|
}
|
|
|
|
protected void ParseCommand(string command, Type? inputType = null, Type? expectedType = null, bool once = false)
|
|
{
|
|
var parser = new ParserContext(command, Toolshed);
|
|
var success = CommandRun.TryParse(false, parser, inputType, expectedType, once, out _, out _, out var error);
|
|
|
|
if (error is not null)
|
|
ReportError(error);
|
|
|
|
if (error is null)
|
|
Assert.That(success, $"Parse failed despite no error being reported. Parsed {command}");
|
|
}
|
|
|
|
public bool CheckInvokable(CommandSpec command, out IConError? error)
|
|
{
|
|
if (InvocationContext is not null)
|
|
{
|
|
return InvocationContext.CheckInvokable(command, out error);
|
|
}
|
|
|
|
error = null;
|
|
return true;
|
|
}
|
|
|
|
protected ICommonSession? InvocationSession { get; set; }
|
|
|
|
public NetUserId? User => Session?.UserId;
|
|
|
|
public ICommonSession? Session
|
|
{
|
|
get
|
|
{
|
|
if (InvocationContext is not null)
|
|
{
|
|
return InvocationContext.Session;
|
|
}
|
|
|
|
return InvocationSession;
|
|
}
|
|
}
|
|
|
|
public void WriteLine(string line)
|
|
{
|
|
return;
|
|
}
|
|
|
|
private Queue<Type> _expectedErrors = new();
|
|
|
|
private List<IConError> _errors = new();
|
|
|
|
public void ReportError(IConError err)
|
|
{
|
|
if (_expectedErrors.Count == 0)
|
|
{
|
|
if (AssertOnUnexpectedError)
|
|
{
|
|
Assert.Fail($"Got an error, {err.GetType()}, when none was expected.\n{err.Describe()}");
|
|
}
|
|
|
|
goto done;
|
|
}
|
|
|
|
var ty = _expectedErrors.Dequeue();
|
|
|
|
if (AssertOnUnexpectedError)
|
|
{
|
|
Assert.That(
|
|
err.GetType().IsAssignableTo(ty),
|
|
$"The error {err.GetType()} wasn't assignable to the expected type {ty}.\n{err.Describe()}"
|
|
);
|
|
}
|
|
|
|
done:
|
|
_errors.Add(err);
|
|
}
|
|
|
|
public IEnumerable<IConError> GetErrors()
|
|
{
|
|
return _errors;
|
|
}
|
|
|
|
public void ClearErrors()
|
|
{
|
|
_errors.Clear();
|
|
}
|
|
|
|
public Dictionary<string, object?> Variables { get; } = new();
|
|
|
|
protected void ExpectError(Type err)
|
|
{
|
|
_expectedErrors.Enqueue(err);
|
|
}
|
|
|
|
protected void ExpectError<T>()
|
|
{
|
|
_expectedErrors.Enqueue(typeof(T));
|
|
}
|
|
}
|