forked from space-syndicate/space-station-14
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'upstream/master' into upstream-sync
- Loading branch information
Showing
66 changed files
with
1,307 additions
and
865 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using Robust.Shared.Toolshed; | ||
|
||
namespace Content.IntegrationTests.Tests.Toolshed; | ||
|
||
[TestFixture] | ||
public sealed class AdminTest : ToolshedTest | ||
{ | ||
[Test] | ||
public async Task AllCommandsHavePermissions() | ||
{ | ||
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."); | ||
}); | ||
} | ||
} |
84 changes: 84 additions & 0 deletions
84
Content.IntegrationTests/Tests/Toolshed/CommandParseTest.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
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"); | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using Robust.Shared.Toolshed; | ||
|
||
namespace Content.IntegrationTests.Tests.Toolshed; | ||
|
||
[TestFixture] | ||
public sealed class LocTest : ToolshedTest | ||
{ | ||
[Test] | ||
public async Task AllCommandsHaveDescriptions() | ||
{ | ||
await Server.WaitAssertion(() => | ||
{ | ||
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."); | ||
}); | ||
} | ||
} |
153 changes: 153 additions & 0 deletions
153
Content.IntegrationTests/Tests/Toolshed/ToolshedTest.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,153 @@ | ||
#nullable enable | ||
using System.Collections.Generic; | ||
using Content.Server.Administration.Managers; | ||
using Robust.Server.Player; | ||
using Robust.Shared.Players; | ||
using Robust.Shared.Toolshed; | ||
using Robust.Shared.Toolshed.Errors; | ||
using Robust.Shared.Toolshed.Syntax; | ||
using Robust.UnitTesting; | ||
|
||
namespace Content.IntegrationTests.Tests.Toolshed; | ||
|
||
[TestFixture] | ||
[FixtureLifeCycle(LifeCycle.SingleInstance)] | ||
public abstract class ToolshedTest : IInvocationContext | ||
{ | ||
protected PairTracker PairTracker = default!; | ||
|
||
protected virtual bool NoClient => true; | ||
protected virtual bool AssertOnUnexpectedError => true; | ||
|
||
protected RobustIntegrationTest.ServerIntegrationInstance Server = default!; | ||
protected RobustIntegrationTest.ClientIntegrationInstance? Client = null; | ||
protected ToolshedManager Toolshed = default!; | ||
protected IAdminManager AdminManager = default!; | ||
|
||
protected IInvocationContext? Context = null; | ||
|
||
[TearDown] | ||
public virtual async Task TearDown() | ||
{ | ||
Assert.IsEmpty(_expectedErrors); | ||
ClearErrors(); | ||
} | ||
|
||
[OneTimeSetUp] | ||
public virtual async Task Setup() | ||
{ | ||
PairTracker = await PoolManager.GetServerClient(new PoolSettings {NoClient = NoClient}); | ||
Server = PairTracker.Pair.Server; | ||
|
||
if (!NoClient) | ||
{ | ||
Client = PairTracker.Pair.Client; | ||
await Client.WaitIdleAsync(); | ||
} | ||
|
||
await Server.WaitIdleAsync(); | ||
|
||
Toolshed = Server.ResolveDependency<ToolshedManager>(); | ||
AdminManager = Server.ResolveDependency<IAdminManager>(); | ||
} | ||
|
||
protected bool InvokeCommand(string command, out object? result, IPlayerSession? session = null) | ||
{ | ||
return Toolshed.InvokeCommand(this, command, null, out result); | ||
} | ||
|
||
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); | ||
|
||
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 (Context is not null) | ||
{ | ||
return Context.CheckInvokable(command, out error); | ||
} | ||
|
||
error = null; | ||
return true; | ||
} | ||
|
||
protected IPlayerSession? InvocationSession { get; set; } | ||
|
||
public ICommonSession? Session | ||
{ | ||
get | ||
{ | ||
if (Context is not null) | ||
{ | ||
return Context.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)); | ||
} | ||
} |
Oops, something went wrong.