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

GD-129: Adding CSharp test support #137

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions .github/workflows/selftest-3.3.x-mono.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
name: Run selftest Godot 3.3.x - Mono
on: [push]

jobs:
testing:
strategy:
matrix:
godot: [mono-3.3.1, mono-3.3.2, mono-3.3.3]

name: GdUnit3 Selftest on Godot ${{ matrix.godot }}
runs-on: ubuntu-latest
container:
image: barichello/godot-ci:${{ matrix.godot }}

steps:
- name: Checkout
uses: actions/checkout@v2
with:
lfs: true

- name: Compile
run: |
nuget restore
mkdir -p .mono/assemblies/Debug
cp /usr/local/bin/GodotSharp/Api/Release/* .mono/assemblies/Debug
msbuild

- name: Run Selftes
timeout-minutes: 7
env:
GODOT_BIN: "/usr/local/bin/godot"
shell: bash
run: ./runtest.sh --selftest

- name: Collect Test Reports
uses: actions/upload-artifact@v2
with:
name: Report_${{ matrix.godot }}
path: reports/**
9 changes: 4 additions & 5 deletions .github/workflows/selftest-3.3.x.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ jobs:
testing:
strategy:
matrix:
godot: [3.3, 3.3.1, 3.3.2, 3.3.3, mono-3.3.3]
godot: [3.3, 3.3.1, 3.3.2, 3.3.3]

name: GdUnit3 Selftest on Godot ${{ matrix.godot }}
runs-on: ubuntu-latest
container:
Expand All @@ -20,15 +20,14 @@ jobs:
- name: Setup
shell: bash
run: echo "GODOT_BIN=/usr/local/bin/godot" >> $GITHUB_ENV

- name: Run Selftes
shell: bash
run: ./runtest.sh --selftest

- name: Collect Test Report
if: always()
uses: actions/upload-artifact@v2
with:
name: Report_${{ matrix.godot }}
path: reports/**

32 changes: 23 additions & 9 deletions addons/gdUnit3/bin/GdUnitCmdTool.gd
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ class CLIRunner extends Node:
const RETURN_ERROR = 100
const RETURN_WARNING = 101


var _state = INIT
var _signal_handler
var _test_suites_to_process :Array
Expand All @@ -24,6 +25,7 @@ class CLIRunner extends Node:
var _report_max: int = DEFAULT_REPORT_COUNT
var _runner_config := GdUnitRunnerConfig.new()
var _console := CmdConsole.new()
var _cs_executor

var _cmd_options: = CmdOptions.new([
CmdOption.new("-a, --add", "-a <directory|path of testsuite>", "Adds the given test suite or directory to the execution pipeline.", TYPE_STRING),
Expand All @@ -49,6 +51,11 @@ class CLIRunner extends Node:
_executor.disable_default_yield()
# stop on first test failure to fail fast
_executor.fail_fast(true)

if GdUnitTools.is_mono_supported():
_cs_executor = load("res://addons/gdUnit3/src/core/execution/Executor.cs").new()
_cs_executor.AddGdTestEventListener(self)

var err := _executor.connect("send_event", self, "_on_executor_event")
if err != OK:
push_error("Error on startup, can't connect executor for 'send_event'")
Expand All @@ -67,10 +74,13 @@ class CLIRunner extends Node:
_state = STOP
else:
# process next test suite
var test_suite := _test_suites_to_process.pop_front() as GdUnitTestSuite
var fs = _executor.execute(test_suite)
if fs is GDScriptFunctionState:
yield(fs, "completed")
var test_suite := _test_suites_to_process.pop_front() as Node
if GdObjects.is_cs_script(test_suite.get_script()):
_cs_executor.execute(test_suite)
else:
var fs = _executor.execute(test_suite)
if fs is GDScriptFunctionState:
yield(fs, "completed")
set_process(true)
STOP:
_state = EXIT
Expand Down Expand Up @@ -201,7 +211,7 @@ class CLIRunner extends Node:
for test_suite in test_suites:
skip_suite(test_suite, skipped)

func skip_suite(test_suite :GdUnitTestSuite, skipped :Dictionary) -> void:
func skip_suite(test_suite :Node, skipped :Dictionary) -> void:
var skipped_suites := skipped.keys()
if skipped_suites.empty():
return
Expand All @@ -217,7 +227,7 @@ class CLIRunner extends Node:
else:
# skip tests
for test_to_skip in skipped_tests:
var test_case :_TestCase = test_suite.find_node(test_to_skip, true, false)
var test_case :_TestCase = test_suite.get_test_case_by_name(test_to_skip)
if test_case:
test_case.skip(true)
else:
Expand All @@ -229,6 +239,9 @@ class CLIRunner extends Node:
total += (test_suite as Node).get_child_count()
return total

func PublishEvent(data) -> void:
_on_executor_event(GdUnitEvent.new().deserialize(data.AsDictionary()))

func _on_executor_event(event :GdUnitEvent):
match event.type():
GdUnitEvent.INIT:
Expand All @@ -244,21 +257,22 @@ class CLIRunner extends Node:
_report.add_testsuite_report(GdUnitTestSuiteReport.new(event.resource_path(), event.suite_name()))

GdUnitEvent.TESTSUITE_AFTER:
_report.update_test_suite_report(event.suite_name(), event.skipped_count(), event.orphan_nodes(), event.elapsed_time())
_report.update_test_suite_report(event.resource_path(), 0, event.orphan_nodes(), event.elapsed_time())

GdUnitEvent.TESTCASE_BEFORE:
_report.add_testcase_report(event.suite_name(), GdUnitTestCaseReport.new(event.test_name()))
_report.add_testcase_report(event.resource_path(), GdUnitTestCaseReport.new(event.resource_path(), event.test_name()))

GdUnitEvent.TESTCASE_AFTER:
var test_report := GdUnitTestCaseReport.new(
event.resource_path(),
event.test_name(),
event.is_error(),
event.is_failed(),
event.orphan_nodes(),
event.skipped_count(),
event.reports(),
event.elapsed_time())
_report.update_testcase_report(event.suite_name(), test_report)
_report.update_testcase_report(event.resource_path(), test_report)
print_status(event)

func report_exit_code(report :GdUnitHtmlReport) -> int:
Expand Down
2 changes: 1 addition & 1 deletion addons/gdUnit3/plugin.gd
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ func _enter_tree():
# show possible update notification when is enabled
if GdUnitSettings.is_update_notification_enabled():
_update_tool = load("res://addons/gdUnit3/src/update/GdUnitUpdate.tscn").instance()
get_parent().add_child(_update_tool)
add_child(_update_tool)

# install SignalHandler singleton
GdUnitSingleton.add_singleton(SignalHandler.SINGLETON_NAME, "res://addons/gdUnit3/src/core/event/SignalHandler.gd")
Expand Down
2 changes: 1 addition & 1 deletion addons/gdUnit3/src/GdUnitStringAssert.gd
Original file line number Diff line number Diff line change
Expand Up @@ -51,5 +51,5 @@ func ends_with(expected: String) -> GdUnitStringAssert:
return self

# Verifies that the current String has the expected length by used comparator.
func has_length(lenght: int, comparator: int = Comparator.EXACTLY) -> GdUnitStringAssert:
func has_length(lenght: int, comparator: int = Comparator.EQUAL) -> GdUnitStringAssert:
return self
47 changes: 47 additions & 0 deletions addons/gdUnit3/src/IAssert.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
using System.ComponentModel;

namespace GdUnit3
{

/// <summary> Main interface of all GdUnit asserts </summary>
public interface IAssert
{

enum EXPECT : int
{
[Description("assert expects ends with success")]
SUCCESS = 0,
[Description("assert expects ends with errors")]
FAIL = 1
}
}

/// <summary> Base interface of all GdUnit asserts </summary>
public interface IAssertBase<V> : IAssert
{

/// <summary>Verifies that the current value is null.</summary>
IAssertBase<V> IsNull();

/// <summary> Verifies that the current value is not null.</summary>
IAssertBase<V> IsNotNull();

/// <summary> Verifies that the current value is equal to expected one.
IAssertBase<V> IsEqual(V expected);

/// <summary> Verifies that the current value is not equal to expected one.</summary>
IAssertBase<V> IsNotEqual(V expected);

/// <summary></summary>
IAssertBase<V> TestFail();

/// <summary> Verifies the failure message is equal to expected one.</summary>
IAssertBase<V> HasFailureMessage(string expected);

/// <summary> Verifies that the failure starts with the given value.</summary>
IAssertBase<V> StartsWithFailureMessage(string value);

/// <summary> Overrides the default failure message by given custom message.</summary>
IAssertBase<V> OverrideFailureMessage(string message);
}
}
16 changes: 16 additions & 0 deletions addons/gdUnit3/src/IBoolAssert.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@

namespace GdUnit3
{

/// <summary> An Assertion Tool to verify boolean values </summary>
public interface IBoolAssert : IAssertBase<bool>
{

/// <summary> Verifies that the current value is true.</summary>
IBoolAssert IsTrue();

/// <summary> Verifies that the current value is false.</summary>
IBoolAssert IsFalse();

}
}
10 changes: 10 additions & 0 deletions addons/gdUnit3/src/IDoubleAssert.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@

namespace GdUnit3
{

/// <summary> Base interface for integer assertions.</summary>
public interface IDoubleAssert : INumberAssert<double>
{

}
}
9 changes: 9 additions & 0 deletions addons/gdUnit3/src/IIntAssert.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
namespace GdUnit3
{

/// <summary> Base interface for integer assertions.</summary>
public interface IIntAssert : INumberAssert<int>
{

}
}
62 changes: 62 additions & 0 deletions addons/gdUnit3/src/INumberAssert.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
using System;

namespace GdUnit3
{

/// <summary> Base interface for number assertions.</summary>
public interface INumberAssert<V> : IAssertBase<V>
{

/// <summary> Verifies that the current value is less than the given one.</summary>
public INumberAssert<V> IsLess(V expected);


/// <summary> Verifies that the current value is less than or equal the given one.</summary>
public INumberAssert<V> IsLessEqual(V expected);


/// <summary> Verifies that the current value is greater than the given one.</summary>
public INumberAssert<V> IsGreater(V expected);


/// <summary> Verifies that the current value is greater than or equal the given one.</summary>
public INumberAssert<V> IsGreaterEqual(V expected);


/// <summary> Verifies that the current value is even.</summary>
public INumberAssert<V> IsEven();


/// <summary> Verifies that the current value is odd.</summary>
public INumberAssert<V> IsOdd();


/// <summary> Verifies that the current value is negative.</summary>
public INumberAssert<V> IsNegative();


/// <summary> Verifies that the current value is not negative.</summary>
public INumberAssert<V> IsNotNegative();


/// <summary> Verifies that the current value is equal to zero.</summary>
public INumberAssert<V> IsZero();


/// <summary> Verifies that the current value is not equal to zero.</summary>
public INumberAssert<V> IsNotZero();


/// <summary> Verifies that the current value is in the given set of values.</summary>
public INumberAssert<V> IsIn(Array expected);


/// <summary> Verifies that the current value is not in the given set of values.</summary>
public INumberAssert<V> IsNotIn(Array expected);


/// <summary> Verifies that the current value is between the given boundaries (inclusive).</summary>
public INumberAssert<V> IsBetween(V from, V to);

}
}
21 changes: 21 additions & 0 deletions addons/gdUnit3/src/IObjectAssert.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@

namespace GdUnit3
{

/// <summary> An Assertion Tool to verify object values </summary>
public interface IObjectAssert : IAssertBase<object>
{
// Verifies that the current value is the same as the given one.
public IObjectAssert IsSame(object expected);

// Verifies that the current value is not the same as the given one.
public IObjectAssert IsNotSame(object expected);

// Verifies that the current value is an instance of the given type.
public IObjectAssert IsInstanceof<ExpectedType>();

// Verifies that the current value is not an instance of the given type.
public IObjectAssert IsNotInstanceof<ExpectedType>();

}
}
Loading