Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
Splamy committed Mar 16, 2020
2 parents 65aa9a1 + 7cb413a commit c7e44e4
Show file tree
Hide file tree
Showing 320 changed files with 10,101 additions and 7,719 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
.vs/
.vscode/
.idea/
[Pp]roperties/

# Build results
[Dd]ebug/
Expand Down
4 changes: 2 additions & 2 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
[submodule "TS3Client/Declarations"]
path = TS3Client/Declarations
[submodule "TSLib/Declarations"]
path = TSLib/Declarations
url = https://github.com/ReSpeak/tsdeclarations
6 changes: 4 additions & 2 deletions Directory.Build.targets
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
<Project>
<ItemGroup>
<PackageReference Include="NLog" Version="4.6.7" />
<PackageReference Condition="'$(TargetFramework)' != 'netcoreapp2.2'" Include="System.Memory" Version="4.5.3" />
<PackageReference Include="NLog" Version="4.6.8" />
<PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
<PackageReference Condition="'$(TargetFramework)' == 'net472'" Include="System.Memory" Version="4.5.3" />
<PackageReference Condition="'$(TargetFramework)' == 'netstandard2.0'" Include="System.Memory" Version="4.5.3" />
</ItemGroup>
</Project>
23 changes: 23 additions & 0 deletions GitVersion.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
assembly-versioning-scheme: MajorMinorPatch
mode: Mainline
branches:
master:
tag: ''
increment: Patch
prevent-increment-of-merged-branch-version: true
track-merge-target: false
regex: ^master$
tracks-release-branches: false
is-release-branch: false
is-mainline: true
develop:
tag: alpha
increment: Minor
prevent-increment-of-merged-branch-version: false
track-merge-target: true
regex: ^develop$
tracks-release-branches: true
is-release-branch: false
ignore:
sha: []
merge-message-formats: {}
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ Translations need to be manually approved and will then be automatically built a
This project is licensed under [OSL-3.0](https://opensource.org/licenses/OSL-3.0).

Why OSL-3.0:
- OSL allows you to link to our libraries without needing to disclose your own project, which might be useful if you want to use the TS3Client as a library.
- OSL allows you to link to our libraries without needing to disclose your own project, which might be useful if you want to use the TSLib as a library.
- If you create plugins you do not have to make them public like in GPL. (Although we would be happy if you shared them :)
- With OSL we want to allow you providing the TS3AB as a service (even commercially). We do not want the software to be sold but the service. We want this software to be free for everyone.
- TL; DR? https://tldrlegal.com/license/open-software-licence-3.0
Expand Down
165 changes: 82 additions & 83 deletions TS3ABotUnitTests/BotCommandTests.cs
Original file line number Diff line number Diff line change
@@ -1,48 +1,31 @@
// TS3AudioBot - An advanced Musicbot for Teamspeak 3
// Copyright (C) 2017 TS3AudioBot contributors
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the Open Software License v. 3.0
//
// You should have received a copy of the Open Software License along with this
// program. If not, see <https://opensource.org/licenses/OSL-3.0>.
using NUnit.Framework;
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Reflection;
using System.Threading;
using TS3AudioBot;
using TS3AudioBot.Algorithm;
using TS3AudioBot.CommandSystem;
using TS3AudioBot.CommandSystem.Ast;
using TS3AudioBot.CommandSystem.CommandResults;
using TS3AudioBot.CommandSystem.Commands;
using TS3AudioBot.Dependency;
using TSLib;

namespace TS3ABotUnitTests
{
using NUnit.Framework;
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Reflection;
using System.Threading;
using TS3AudioBot;
using TS3AudioBot.Dependency;
using TS3AudioBot.Algorithm;
using TS3AudioBot.Audio;
using TS3AudioBot.CommandSystem;
using TS3AudioBot.CommandSystem.Ast;
using TS3AudioBot.CommandSystem.CommandResults;
using TS3AudioBot.CommandSystem.Commands;

[TestFixture]
public class BotCommandTests
{
private readonly CommandManager cmdMgr;

public BotCommandTests()
{
cmdMgr = new CommandManager(null);
cmdMgr.RegisterCollection(MainCommands.Bag);
}

[Test]
public void BotCommandTest()
{
var execInfo = Utils.GetExecInfo("ic3");
string CallCommand(string command)
{
return cmdMgr.CommandSystem.ExecuteCommand(execInfo, command);
return CommandManager.ExecuteCommand(execInfo, command);
}

var output = CallCommand("!help");
Expand Down Expand Up @@ -93,6 +76,23 @@ string CallCommand(string command)
Assert.Throws<CommandException>(() => CallCommand("!if a == b text (!)"));
}

[Test]
public void TailStringTest()
{
var execInfo = Utils.GetExecInfo("ic3");
var group = execInfo.GetModule<CommandManager>().RootGroup;
group.AddCommand("cmd", new FunctionCommand(s => s));
string CallCommand(string command)
{
return CommandManager.ExecuteCommand(execInfo, command);
}

Assert.AreEqual("a", CallCommand("!cmd a"));
Assert.AreEqual("a b", CallCommand("!cmd a b"));
Assert.AreEqual("a", CallCommand("!cmd a \" b"));
Assert.AreEqual("a b 1", CallCommand("!cmd a b 1"));
}

[Test]
public void XCommandSystemFilterTest()
{
Expand Down Expand Up @@ -145,32 +145,30 @@ public void XCommandSystemFilterTest()
[Test]
public void XCommandSystemTest()
{
var execInfo = Utils.GetExecInfo("ic3");
var commandSystem = new XCommandSystem();
var group = commandSystem.RootCommand;
var execInfo = Utils.GetExecInfo("ic3", false);
var group = execInfo.GetModule<CommandManager>().RootGroup;
group.AddCommand("one", new FunctionCommand(() => "ONE"));
group.AddCommand("two", new FunctionCommand(() => "TWO"));
group.AddCommand("echo", new FunctionCommand(s => s));
group.AddCommand("optional", new FunctionCommand(GetType().GetMethod(nameof(OptionalFunc), BindingFlags.NonPublic | BindingFlags.Static)));

// Basic tests
Assert.AreEqual("ONE", ((StringCommandResult)commandSystem.Execute(execInfo,
new ICommand[] { new StringCommand("one") })).Content);
Assert.AreEqual("ONE", commandSystem.ExecuteCommand(execInfo, "!one"));
Assert.AreEqual("TWO", commandSystem.ExecuteCommand(execInfo, "!t"));
Assert.AreEqual("TEST", commandSystem.ExecuteCommand(execInfo, "!e TEST"));
Assert.AreEqual("ONE", commandSystem.ExecuteCommand(execInfo, "!o"));
Assert.AreEqual("ONE", CommandManager.ExecuteCommand(execInfo, new ICommand[] { new ResultCommand(new PrimitiveResult<string>("one")) }));
Assert.AreEqual("ONE", CommandManager.ExecuteCommand(execInfo, "!one"));
Assert.AreEqual("TWO", CommandManager.ExecuteCommand(execInfo, "!t"));
Assert.AreEqual("TEST", CommandManager.ExecuteCommand(execInfo, "!e TEST"));
Assert.AreEqual("ONE", CommandManager.ExecuteCommand(execInfo, "!o"));

// Optional parameters
Assert.Throws<CommandException>(() => commandSystem.ExecuteCommand(execInfo, "!e"));
Assert.AreEqual("NULL", commandSystem.ExecuteCommand(execInfo, "!op"));
Assert.AreEqual("NOT NULL", commandSystem.ExecuteCommand(execInfo, "!op 1"));
Assert.Throws<CommandException>(() => CommandManager.ExecuteCommand(execInfo, "!e"));
Assert.AreEqual("NULL", CommandManager.ExecuteCommand(execInfo, "!op"));
Assert.AreEqual("NOT NULL", CommandManager.ExecuteCommand(execInfo, "!op 1"));

// Command chaining
Assert.AreEqual("TEST", commandSystem.ExecuteCommand(execInfo, "!e (!e TEST)"));
Assert.AreEqual("TWO", commandSystem.ExecuteCommand(execInfo, "!e (!t)"));
Assert.AreEqual("NOT NULL", commandSystem.ExecuteCommand(execInfo, "!op (!e TEST)"));
Assert.AreEqual("ONE", commandSystem.ExecuteCommand(execInfo, "!(!e on)"));
Assert.AreEqual("TEST", CommandManager.ExecuteCommand(execInfo, "!e (!e TEST)"));
Assert.AreEqual("TWO", CommandManager.ExecuteCommand(execInfo, "!e (!t)"));
Assert.AreEqual("NOT NULL", CommandManager.ExecuteCommand(execInfo, "!op (!e TEST)"));
Assert.AreEqual("ONE", CommandManager.ExecuteCommand(execInfo, "!(!e on)"));

// Command overloading
var intCom = new Func<int, string>(_ => "INT");
Expand All @@ -180,17 +178,16 @@ public void XCommandSystemTest()
new FunctionCommand(strCom.Method, strCom.Target)
}));

Assert.AreEqual("INT", commandSystem.ExecuteCommand(execInfo, "!overlord 1"));
Assert.AreEqual("STRING", commandSystem.ExecuteCommand(execInfo, "!overlord a"));
Assert.Throws<CommandException>(() => commandSystem.ExecuteCommand(execInfo, "!overlord"));
Assert.AreEqual("INT", CommandManager.ExecuteCommand(execInfo, "!overlord 1"));
Assert.AreEqual("STRING", CommandManager.ExecuteCommand(execInfo, "!overlord a"));
Assert.Throws<CommandException>(() => CommandManager.ExecuteCommand(execInfo, "!overlord"));
}

[Test]
public void XCommandSystemTest2()
{
var execInfo = Utils.GetExecInfo("exact");
var commandSystem = new XCommandSystem();
var group = commandSystem.RootCommand;
var group = execInfo.GetModule<CommandManager>().RootGroup;

var o1 = new OverloadedFunctionCommand();
o1.AddCommand(new FunctionCommand(new Action<int>((_) => { })));
Expand All @@ -204,25 +201,25 @@ public void XCommandSystemTest2()
o2.AddCommand("b", new FunctionCommand(new Action(() => { })));
group.AddCommand("three", o2);

Assert.Throws<CommandException>(() => commandSystem.ExecuteCommand(execInfo, "!one"));
Assert.Throws<CommandException>(() => commandSystem.ExecuteCommand(execInfo, "!one \"\""));
Assert.Throws<CommandException>(() => commandSystem.ExecuteCommand(execInfo, "!one (!print \"\")"));
Assert.Throws<CommandException>(() => commandSystem.ExecuteCommand(execInfo, "!one string"));
Assert.DoesNotThrow(() => commandSystem.ExecuteCommand(execInfo, "!one 42"));
Assert.DoesNotThrow(() => commandSystem.ExecuteCommand(execInfo, "!one 4200000000000"));

Assert.Throws<CommandException>(() => commandSystem.ExecuteCommand(execInfo, "!two"));
Assert.Throws<CommandException>(() => commandSystem.ExecuteCommand(execInfo, "!two \"\""));
Assert.Throws<CommandException>(() => commandSystem.ExecuteCommand(execInfo, "!two (!print \"\")"));
Assert.Throws<CommandException>(() => commandSystem.ExecuteCommand(execInfo, "!two 42"));
Assert.DoesNotThrow(() => commandSystem.ExecuteCommand(execInfo, "!two None"));

Assert.Throws<CommandException>(() => commandSystem.ExecuteCommand(execInfo, "!three"));
Assert.Throws<CommandException>(() => commandSystem.ExecuteCommand(execInfo, "!three \"\""));
Assert.Throws<CommandException>(() => commandSystem.ExecuteCommand(execInfo, "!three (!print \"\")"));
Assert.Throws<CommandException>(() => commandSystem.ExecuteCommand(execInfo, "!three c"));
Assert.DoesNotThrow(() => commandSystem.ExecuteCommand(execInfo, "!three a"));
Assert.DoesNotThrow(() => commandSystem.ExecuteCommand(execInfo, "!three b"));
Assert.Throws<CommandException>(() => CommandManager.ExecuteCommand(execInfo, "!one"));
Assert.Throws<CommandException>(() => CommandManager.ExecuteCommand(execInfo, "!one \"\""));
Assert.Throws<CommandException>(() => CommandManager.ExecuteCommand(execInfo, "!one (!print \"\")"));
Assert.Throws<CommandException>(() => CommandManager.ExecuteCommand(execInfo, "!one string"));
Assert.DoesNotThrow(() => CommandManager.ExecuteCommand(execInfo, "!one 42"));
Assert.DoesNotThrow(() => CommandManager.ExecuteCommand(execInfo, "!one 4200000000000"));

Assert.Throws<CommandException>(() => CommandManager.ExecuteCommand(execInfo, "!two"));
Assert.Throws<CommandException>(() => CommandManager.ExecuteCommand(execInfo, "!two \"\""));
Assert.Throws<CommandException>(() => CommandManager.ExecuteCommand(execInfo, "!two (!print \"\")"));
Assert.Throws<CommandException>(() => CommandManager.ExecuteCommand(execInfo, "!two 42"));
Assert.DoesNotThrow(() => CommandManager.ExecuteCommand(execInfo, "!two None"));

Assert.Throws<CommandException>(() => CommandManager.ExecuteCommand(execInfo, "!three"));
Assert.Throws<CommandException>(() => CommandManager.ExecuteCommand(execInfo, "!three \"\""));
Assert.Throws<CommandException>(() => CommandManager.ExecuteCommand(execInfo, "!three (!print \"\")"));
Assert.Throws<CommandException>(() => CommandManager.ExecuteCommand(execInfo, "!three c"));
Assert.DoesNotThrow(() => CommandManager.ExecuteCommand(execInfo, "!three a"));
Assert.DoesNotThrow(() => CommandManager.ExecuteCommand(execInfo, "!three b"));
}

[Test]
Expand All @@ -231,10 +228,16 @@ public void EnsureAllCommandsHaveEnglishDocumentationEntry()
Thread.CurrentThread.CurrentCulture = CultureInfo.GetCultureInfo("en");
Thread.CurrentThread.CurrentUICulture = CultureInfo.GetCultureInfo("en");

var execInfo = Utils.GetExecInfo("exact");
var cmdMgr = execInfo.GetModule<CommandManager>();
var errors = new List<string>();
foreach (var cmd in cmdMgr.AllCommands)
{
Assert.IsFalse(string.IsNullOrEmpty(cmd.Description), $"Command {cmd.FullQualifiedName} has no documentation");
if (string.IsNullOrEmpty(cmd.Description))
errors.Add($"Command {cmd.FullQualifiedName} has no documentation");
}
if (errors.Count > 0)
Assert.Fail(string.Join("\n", errors));
}

[Test]
Expand Down Expand Up @@ -269,19 +272,15 @@ public static void TestStringParsing(string inp, string outp)

internal static class Utils
{
private static readonly CommandManager cmdMgr;

static Utils()
public static ExecutionInformation GetExecInfo(string matcher, bool addMainCommands = true)
{
cmdMgr = new CommandManager(null);
cmdMgr.RegisterCollection(MainCommands.Bag);
}
var cmdMgr = new CommandManager(null);
if (addMainCommands)
cmdMgr.RegisterCollection(MainCommands.Bag);

public static ExecutionInformation GetExecInfo(string matcher)
{
var execInfo = new ExecutionInformation();
execInfo.AddModule(new CallerInfo(false) { SkipRightsChecks = true, CommandComplexityMax = int.MaxValue });
execInfo.AddModule(new InvokerData("InvokerUid"));
execInfo.AddModule(new InvokerData((Uid)"InvokerUid"));
execInfo.AddModule(Filter.GetFilterByName(matcher));
execInfo.AddModule(cmdMgr);
return execInfo;
Expand Down
12 changes: 6 additions & 6 deletions TS3ABotUnitTests/M3uParserTests.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
using NUnit.Framework;
using System.IO;
using System.Text;
using TS3AudioBot.ResourceFactories.AudioTags;

namespace TS3ABotUnitTests
{
using NUnit.Framework;
using System.IO;
using System.Text;
using TS3AudioBot.ResourceFactories.AudioTags;

[TestFixture]
class M3uParserTests
internal class M3uParserTests
{
[Test]
public void SimpleListTest()
Expand Down
10 changes: 5 additions & 5 deletions TS3ABotUnitTests/RingQueueTest.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
using NUnit.Framework;
using System;
using TSLib.Full;

namespace TS3ABotUnitTests
{
using NUnit.Framework;
using System;
using TS3Client.Full;

[TestFixture]
class RingQueueTest
internal class RingQueueTest
{

[Test]
Expand Down
11 changes: 7 additions & 4 deletions TS3ABotUnitTests/TS3ABotUnitTests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<OutputType>Library</OutputType>
<TargetFrameworks>netcoreapp2.2;net472</TargetFrameworks>
<TargetFrameworks>netcoreapp2.2;netcoreapp3.1;net472</TargetFrameworks>

<LangVersion>7.3</LangVersion>
<PlatformTarget>AnyCPU</PlatformTarget>
Expand All @@ -11,13 +11,16 @@

<ItemGroup>
<PackageReference Include="NUnit" Version="3.12.0" />
<PackageReference Include="NUnit3TestAdapter" Version="3.15.1" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.3.0" />
<PackageReference Include="NUnit3TestAdapter" Version="3.16.1">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.5.0" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\TS3AudioBot\TS3AudioBot.csproj" />
<ProjectReference Include="..\TS3Client\TS3Client.csproj" />
<ProjectReference Include="..\TSLib\TSLib.csproj" />
</ItemGroup>

</Project>
Loading

0 comments on commit c7e44e4

Please sign in to comment.