Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use new test runner #265

Merged
merged 14 commits into from
Mar 19, 2024
30 changes: 30 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,36 @@
"args": ["${fileDirname}/${fileBasenameNoExtension}.tscn"],
"cwd": "${workspaceFolder}",
"stopAtEntry": false
},
{
"name": "🧪 Debug Tests",
"type": "coreclr",
"request": "launch",
"preLaunchTask": "build",
"program": "${env:GODOT}",
"args": [
"res://test/Test.tscn",
// These command line flags are used by GoDotTest to run tests.
"--run-tests",
"--quit-on-finish"
],
"cwd": "${workspaceFolder}",
"stopAtEntry": false
},
{
"name": "🧪 Debug Current Test",
"type": "coreclr",
"request": "launch",
"preLaunchTask": "build",
"program": "${env:GODOT}",
"args": [
"res://test/Test.tscn",
// These command line flags are used by GoDotTest to run tests.
"--run-tests=${fileBasenameNoExtension}",
"--quit-on-finish"
],
"cwd": "${workspaceFolder}",
"stopAtEntry": false
}
]
}
2 changes: 1 addition & 1 deletion .vscode/tasks.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"label": "build",
"command": "dotnet",
"type": "process",
"args": ["build"],
"args": ["build", "--no-restore"],
"problemMatcher": "$msCompile",
"presentation": {
"echo": true,
Expand Down
6 changes: 5 additions & 1 deletion godot-yat.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@
</PropertyGroup>
<ItemGroup>
<Compile Remove="script_templates/**/*.cs" />
<Compile Remove="test/**/*.cs" />
<Compile Remove="test/old/**/*.cs" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Chickensoft.GoDotTest" Version="1.5.1-godot4.2.2-rc.2" />
<PackageReference Include="Shouldly" Version="4.2.1" />
</ItemGroup>
</Project>
36 changes: 36 additions & 0 deletions test/Test.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
using Godot;

#if DEBUG
using System.Reflection;
using Chickensoft.GoDotTest;
#endif

namespace Test;

public partial class Test : Node
{
#if DEBUG
public TestEnvironment Environment = default!;
#endif

public override void _Ready()
{
#if DEBUG
// If this is a debug build, use GoDotTest to examine the
// command line arguments and determine if we should run tests.
Environment = TestEnvironment.From(OS.GetCmdlineArgs());
if (Environment.ShouldRunTests)
{
CallDeferred("RunTests");
return;
}
#endif
// If we don't need to run tests, we can just switch to the game scene.
// GetTree().ChangeSceneToFile("uid://d4fqgp0bjijcv");
}

#if DEBUG
private void RunTests()
=> _ = GoTest.RunTests(Assembly.GetExecutingAssembly(), this, Environment);
#endif
}
6 changes: 6 additions & 0 deletions test/Test.tscn
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[gd_scene load_steps=2 format=3 uid="uid://2x6cfhujoahs"]

[ext_resource type="Script" path="res://test/Test.cs" id="1_wogky"]

[node name="Test" type="Node"]
script = ExtResource("1_wogky")
114 changes: 57 additions & 57 deletions test/helpers/TestAttributeHelper.cs
Original file line number Diff line number Diff line change
@@ -1,77 +1,77 @@
using Chickensoft.GoDotTest;
using Godot;
using YAT.Attributes;
using YAT.Helpers;
using Shouldly;

namespace GdUnit4
namespace Test;

public class TestAttributeHelper : TestClass
{
using static Assertions;
public TestAttributeHelper(Node testScene) : base(testScene) { }

[Command("test")]
[Argument("arg1", "string")]
[Argument("arg3", "string")]
[Argument("arg3", "string")]
private class TestClass { }

[TestSuite]
public partial class TestAttributeHelper
[Test]
public void TestGetAttribute_AttributePresent()
{
[Command("test")]
[Argument("arg1", "string")]
[Argument("arg3", "string")]
[Argument("arg3", "string")]
private class TestClass { }

[TestCase]
public void TestGetAttribute_AttributePresent()
{
var obj = new TestClass();
var attribute = Reflection.GetAttribute<CommandAttribute>(obj);
var obj = new TestClass();
var attribute = Reflection.GetAttribute<CommandAttribute>(obj);

AssertObject(attribute).IsNotNull();
AssertString(attribute.Name).IsEqual("test");
}
attribute.ShouldNotBeNull();
attribute.Name.ShouldBe("test");
}

[TestCase]
public void TestGetAttribute_AttributeNotPresent()
{
var obj = new TestClass();
var attribute = Reflection.GetAttribute<OptionAttribute>(obj);
[Test]
public void TestGetAttribute_AttributeNotPresent()
{
var obj = new TestClass();
var attribute = Reflection.GetAttribute<OptionAttribute>(obj);

AssertObject(attribute).IsNull();
}
attribute.ShouldBeNull();
}

[TestCase]
public void TestGetAttribute_AttributesPresent()
{
var obj = new TestClass();
var attributes = Reflection.GetAttributes<ArgumentAttribute>(obj);
[Test]
public void TestGetAttribute_AttributesPresent()
{
var obj = new TestClass();
var attributes = Reflection.GetAttributes<ArgumentAttribute>(obj);

AssertObject(attributes).IsNotNull();
AssertInt(attributes.Length).IsEqual(3);
AssertString(attributes[0].Name).IsEqual("arg1");
AssertString(attributes[1].Name).IsEqual("arg3");
AssertString(attributes[2].Name).IsEqual("arg3");
}
attributes.ShouldNotBeNull();
attributes.Length.ShouldBe(3);
attributes[0].Name.ToString().ShouldBe("arg1");
attributes[1].Name.ToString().ShouldBe("arg3");
attributes[2].Name.ToString().ShouldBe("arg3");
}

[TestCase]
public void TestGetAttribute_AttributesNotPresent()
{
var obj = new TestClass();
var attributes = Reflection.GetAttributes<OptionAttribute>(obj);
[Test]
public void TestGetAttribute_AttributesNotPresent()
{
var obj = new TestClass();
var attributes = Reflection.GetAttributes<OptionAttribute>(obj);

AssertArray(attributes).IsEmpty();
}
attributes.ShouldBeEmpty();
}

[TestCase]
public void TestHasAttribute_AttributePresent()
{
var obj = new TestClass();
var hasAttribute = Reflection.HasAttribute<CommandAttribute>(obj);
[Test]
public void TestHasAttribute_AttributePresent()
{
var obj = new TestClass();
var hasAttribute = Reflection.HasAttribute<CommandAttribute>(obj);

AssertBool(hasAttribute).IsEqual(true);
}
hasAttribute.ShouldBeTrue();
}

[TestCase]
public void TestHasAttribute_AttributeNotPresent()
{
var obj = new TestClass();
var hasAttribute = Reflection.HasAttribute<OptionAttribute>(obj);
[Test]
public void TestHasAttribute_AttributeNotPresent()
{
var obj = new TestClass();
var hasAttribute = Reflection.HasAttribute<OptionAttribute>(obj);

AssertBool(hasAttribute).IsEqual(false);
}
hasAttribute.ShouldBeFalse();
}
}
Loading