Toolshed part 2 (#18997)

* fixe

* Save work.

* Rune-aware parser.

* oogh

* pass tests pass tests pass tests pass tests pass tests pass tests pass tests pass tests pass tests pass tests pass tests pass tests pass tests pass tests pass tests pass tests pass tests pass tests pass tests pass tests pass tests pass tests pass tests pass tests pass tests pass tests pass tests pass tests pass tests pass tests pass tests pass tests pass tests pass tests pass tests pass tests pass tests pass tests pass tests pass tests pass tests pass tests pass tests pass tests pass tests pass tests pass tests pass tests pass tests pass tests pass tests pass tests pass tests pass tests pass tests pass tests pass tests pass tests pass tests pass tests pass tests pass tests pass tests pass tests pass tests pass tests

* Publicizes a lot of common generic commands, so custom toolshed envs can include them.

* i think i might implode

* Tests.

* a

* b

* awa

---------

Co-authored-by: moonheart08 <moonheart08@users.noreply.github.com>
This commit is contained in:
Moony
2023-08-23 16:03:41 -05:00
committed by GitHub
parent 852b66dee6
commit 3d3c9e3348
20 changed files with 349 additions and 162 deletions

View File

@@ -13,8 +13,7 @@ public sealed class AdminTest : ToolshedTest
await Server.WaitAssertion(() =>
{
Assert.That(InvokeCommand("cmd:list where { acmd:perms isnull }", out var res));
var list = ((IEnumerable<CommandSpec>) res).ToList();
Assert.That(list, Is.Empty, "All commands must have admin permissions set up.");
Assert.That((IEnumerable<CommandSpec>) res, Is.Empty, "All commands must have admin permissions set up.");
});
}
}

View File

@@ -1,84 +0,0 @@
using System.Collections.Generic;
using Robust.Shared.GameObjects;
using Robust.Shared.Toolshed;
using Robust.Shared.Toolshed.Syntax;
using Robust.Shared.Toolshed.TypeParsers;
namespace Content.IntegrationTests.Tests.Toolshed;
[TestFixture]
public sealed class CommandRunTest : ToolshedTest
{
[Test]
public async Task SimpleCommandRun()
{
await Server.WaitAssertion(() =>
{
ParseCommand("entities");
ParseCommand("entities select 1");
ParseCommand("entities with Item select 1");
ExpectError<OutOfInputError>();
ParseCommand("entities with");
ExpectError<NoImplementationError>();
ParseCommand("player:list with MetaData");
ExpectError<ExpressionOfWrongType>();
ParseCommand("player:list", expectedType: typeof(IEnumerable<EntityUid>));
ParseCommand("entities not with MetaData");
ParseCommand("with MetaData select 2 any", inputType: typeof(List<EntityUid>));
ParseCommand("entities not with MetaData => $myEntities");
ParseCommand("=> $fooBar with MetaData", inputType: typeof(List<EntityUid>));
});
}
[Test]
public async Task EntityUidTypeParser()
{
await Server.WaitAssertion(() =>
{
ParseCommand("ent 1");
ParseCommand("ent c1");
ExpectError<InvalidEntityUid>();
ParseCommand("ent foodigity");
});
}
[Test]
public async Task QuantityTypeParser()
{
await Server.WaitAssertion(() =>
{
ParseCommand("entities select 100");
ParseCommand("entities select 50%");
ExpectError<InvalidQuantity>();
ParseCommand("entities select -1");
ExpectError<InvalidQuantity>();
ParseCommand("entities select 200%");
ExpectError<InvalidQuantity>();
ParseCommand("entities select hotdog");
});
}
[Test]
public async Task ComponentTypeParser()
{
await Server.WaitAssertion(() =>
{
ParseCommand("entities with MetaData");
ExpectError<UnknownComponentError>();
ParseCommand("entities with Foodiddy");
ExpectError<UnknownComponentError>();
ParseCommand("entities with MetaDataComponent");
});
}
}

View File

@@ -1,9 +1,13 @@
using System.Collections.Generic;
using System.Linq;
using System.Globalization;
using Robust.Shared.IoC;
using Robust.Shared.Localization;
using Robust.Shared.Toolshed;
namespace Content.IntegrationTests.Tests.Toolshed;
// this is an EXACT DUPLICATE of LocTest from robust. If you modify this, modify that too.
// Anyone who fails to heed these instructions consents to being scrungled to death.
[TestFixture]
public sealed class LocTest : ToolshedTest
{
@@ -12,8 +16,10 @@ public sealed class LocTest : ToolshedTest
{
await Server.WaitAssertion(() =>
{
IoCManager.Resolve<ILocalizationManager>().LoadCulture(new CultureInfo("en-US"));
Assert.That(InvokeCommand("cmd:list where { cmd:descloc loc:tryloc isnull }", out var res));
Assert.That((IEnumerable<CommandSpec>)res, Is.Empty, "All commands must have localized descriptions.");
Assert.That((IEnumerable<CommandSpec>)res!, Is.Empty, "All commands must have localized descriptions.");
});
}
}

View File

@@ -22,10 +22,12 @@ public abstract class ToolshedTest : IInvocationContext
protected RobustIntegrationTest.ServerIntegrationInstance Server = default!;
protected RobustIntegrationTest.ClientIntegrationInstance? Client = null;
protected ToolshedManager Toolshed = default!;
public ToolshedManager Toolshed { get; private set; } = default!;
public ToolshedEnvironment Environment => Toolshed.DefaultEnvironment;
protected IAdminManager AdminManager = default!;
protected IInvocationContext? Context = null;
protected IInvocationContext? InvocationContext = null;
[TearDown]
public async Task TearDownInternal()
@@ -44,11 +46,11 @@ public abstract class ToolshedTest : IInvocationContext
public virtual async Task Setup()
{
PairTracker = await PoolManager.GetServerClient(new PoolSettings {Connected = Connected});
Server = PairTracker.Pair.Server;
Server = PairTracker.Server;
if (Connected)
{
Client = PairTracker.Pair.Client;
Client = PairTracker.Client;
await Client.WaitIdleAsync();
}
@@ -63,10 +65,17 @@ public abstract class ToolshedTest : IInvocationContext
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 void ParseCommand(string command, Type? inputType = null, Type? expectedType = null, bool once = false)
{
var parser = new ForwardParser(command, Toolshed);
var success = CommandRun.TryParse(false, false, parser, inputType, expectedType, once, out _, out _, out var error);
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);
@@ -77,9 +86,9 @@ public abstract class ToolshedTest : IInvocationContext
public bool CheckInvokable(CommandSpec command, out IConError? error)
{
if (Context is not null)
if (InvocationContext is not null)
{
return Context.CheckInvokable(command, out error);
return InvocationContext.CheckInvokable(command, out error);
}
error = null;
@@ -92,9 +101,9 @@ public abstract class ToolshedTest : IInvocationContext
{
get
{
if (Context is not null)
if (InvocationContext is not null)
{
return Context.Session;
return InvocationContext.Session;
}
return InvocationSession;