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-275: Move c# api into onwn module #277

Merged
merged 2 commits into from
Jun 4, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
2 changes: 1 addition & 1 deletion addons/gdUnit3/bin/GdUnitCmdTool.gd
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ class CLIRunner extends Node:
_executor.fail_fast(true)

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

var err := _executor.connect("send_event", self, "_on_executor_event")
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public void CreateTestSuite()
{
var tmp = CreateTempDir("build-test-suite-test");
string sourceClass = Path.Combine(tmp, "TestPerson.cs");
File.Copy(Path.GetFullPath(Godot.ProjectSettings.GlobalizePath("res://addons/gdUnit3/test/core/resources/sources/TestPerson.cs")), sourceClass);
File.Copy(Path.GetFullPath(Godot.ProjectSettings.GlobalizePath("res://addons/gdUnit3/mono/test/core/resources/sources/TestPerson.cs")), sourceClass);

// first time generates the test suite and adds the test case
string path = Path.Combine(tmp, "TestPersonTest.cs");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,33 +20,33 @@ public void AfterEach()
[TestCase]
public void ParseType()
{
AssertObject(GdUnitTestSuiteBuilder.ParseType("addons/gdUnit3/test/core/resources/testsuites/mono/noSpace/TestSuiteWithoutNamespace.cs")).IsEqual(typeof(TestSuiteWithoutNamespace));
AssertObject(GdUnitTestSuiteBuilder.ParseType("addons/gdUnit3/test/core/resources/testsuites/mono/spaceA/TestSuite.cs")).IsEqual(typeof(GdUnit3.Tests.SpaceA.TestSuite));
AssertObject(GdUnitTestSuiteBuilder.ParseType("addons/gdUnit3/test/core/resources/testsuites/mono/spaceB/TestSuite.cs")).IsEqual(typeof(GdUnit3.Tests.SpaceB.TestSuite));
AssertObject(GdUnitTestSuiteBuilder.ParseType("addons/gdUnit3/mono/test/core/resources/testsuites/mono/noSpace/TestSuiteWithoutNamespace.cs")).IsEqual(typeof(TestSuiteWithoutNamespace));
AssertObject(GdUnitTestSuiteBuilder.ParseType("addons/gdUnit3/mono/test/core/resources/testsuites/mono/spaceA/TestSuite.cs")).IsEqual(typeof(GdUnit3.Tests.SpaceA.TestSuite));
AssertObject(GdUnitTestSuiteBuilder.ParseType("addons/gdUnit3/mono/test/core/resources/testsuites/mono/spaceB/TestSuite.cs")).IsEqual(typeof(GdUnit3.Tests.SpaceB.TestSuite));
// source file not exists
AssertObject(GdUnitTestSuiteBuilder.ParseType("addons/gdUnit3/test/core/resources/testsuites/mono/spaceC/TestSuite.cs")).IsNull();
AssertObject(GdUnitTestSuiteBuilder.ParseType("addons/gdUnit3/mono/test/core/resources/testsuites/mono/spaceC/TestSuite.cs")).IsNull();
}

[TestCase]
public void FindMethod_LineOutOfRange()
{
var classPath = Godot.ProjectSettings.GlobalizePath("res://addons/gdUnit3/test/core/resources/sources/TestPerson.cs");
var classPath = Godot.ProjectSettings.GlobalizePath("res://addons/gdUnit3/mono/test/core/resources/sources/TestPerson.cs");
AssertThrown(() => GdUnitTestSuiteBuilder.FindMethod(classPath, 0)).StartsWithMessage("Specified argument was out of the range of valid values.");
AssertThrown(() => GdUnitTestSuiteBuilder.FindMethod(classPath, 10000)).StartsWithMessage("Specified argument was out of the range of valid values.");
}

[TestCase]
public void FindMethod_NoMethodFound()
{
var classPath = Godot.ProjectSettings.GlobalizePath("res://addons/gdUnit3/test/core/resources/sources/TestPerson.cs");
var classPath = Godot.ProjectSettings.GlobalizePath("res://addons/gdUnit3/mono/test/core/resources/sources/TestPerson.cs");
AssertString(GdUnitTestSuiteBuilder.FindMethod(classPath, 5)).IsNull();
AssertString(GdUnitTestSuiteBuilder.FindMethod(classPath, 11)).IsNull();
}

[TestCase]
public void FindMethod_Found()
{
var classPath = Godot.ProjectSettings.GlobalizePath("res://addons/gdUnit3/test/core/resources/sources/TestPerson.cs");
var classPath = Godot.ProjectSettings.GlobalizePath("res://addons/gdUnit3/mono/test/core/resources/sources/TestPerson.cs");
AssertString(GdUnitTestSuiteBuilder.FindMethod(classPath, 14)).IsEqual("FirstName");
AssertString(GdUnitTestSuiteBuilder.FindMethod(classPath, 16)).IsEqual("LastName");
AssertString(GdUnitTestSuiteBuilder.FindMethod(classPath, 18)).IsEqual("FullName");
Expand All @@ -62,7 +62,7 @@ public void CreateTestSuite()
{
var tmp = CreateTempDir("build-test-suite-test");
string sourceClass = Path.Combine(tmp, "TestPerson.cs");
File.Copy(Path.GetFullPath(Godot.ProjectSettings.GlobalizePath("res://addons/gdUnit3/test/core/resources/sources/TestPerson.cs")), sourceClass);
File.Copy(Path.GetFullPath(Godot.ProjectSettings.GlobalizePath("res://addons/gdUnit3/mono/test/core/resources/sources/TestPerson.cs")), sourceClass);

// first time generates the test suite and adds the test case
string testSuite = Path.Combine(tmp, "TestPersonTest.cs");
Expand All @@ -83,7 +83,7 @@ public void CreateTestSuite_NoMethodFound()
{
var tmp = CreateTempDir("build-test-suite-test");
string sourceClass = Path.Combine(tmp, "TestPerson.cs");
File.Copy(Path.GetFullPath(Godot.ProjectSettings.GlobalizePath("res://addons/gdUnit3/test/core/resources/sources/TestPerson.cs")), sourceClass);
File.Copy(Path.GetFullPath(Godot.ProjectSettings.GlobalizePath("res://addons/gdUnit3/mono/test/core/resources/sources/TestPerson.cs")), sourceClass);

// use of a line number for which no method is defined in the source class
Dictionary<string, object> dictionary = GdUnitTestSuiteBuilder.Build(sourceClass, 4, Path.Combine(tmp, "TestPersonTest.cs"));
Expand All @@ -97,7 +97,7 @@ public void CreateTestSuite_NoNamespace()
{
var tmp = CreateTempDir("build-test-suite-test");
string sourceClass = Path.Combine(tmp, "TestPerson2.cs");
File.Copy(Path.GetFullPath(Godot.ProjectSettings.GlobalizePath("res://addons/gdUnit3/test/core/resources/sources/TestPerson2.cs")), sourceClass);
File.Copy(Path.GetFullPath(Godot.ProjectSettings.GlobalizePath("res://addons/gdUnit3/mono/test/core/resources/sources/TestPerson2.cs")), sourceClass);

// use of a line number for which no method is defined in the source class
string testSuite = Path.Combine(tmp, "TestPerson2Test.cs");
Expand All @@ -111,7 +111,7 @@ public void CreateTestSuite_WithNamespace()
{
var tmp = CreateTempDir("build-test-suite-test");
string sourceClass = Path.Combine(tmp, "TestPerson.cs");
File.Copy(Path.GetFullPath(Godot.ProjectSettings.GlobalizePath("res://addons/gdUnit3/test/core/resources/sources/TestPerson.cs")), sourceClass);
File.Copy(Path.GetFullPath(Godot.ProjectSettings.GlobalizePath("res://addons/gdUnit3/mono/test/core/resources/sources/TestPerson.cs")), sourceClass);

// use of a line number for which no method is defined in the source class
string testSuite = Path.Combine(tmp, "TestPersonTest.cs");
Expand All @@ -125,7 +125,7 @@ public void CreateTestSuite_TestCaseAlreadyExists()
{
var tmp = CreateTempDir("build-test-suite-test");
string sourceClass = Path.Combine(tmp, "TestPerson.cs");
File.Copy(Path.GetFullPath(Godot.ProjectSettings.GlobalizePath("res://addons/gdUnit3/test/core/resources/sources/TestPerson.cs")), sourceClass);
File.Copy(Path.GetFullPath(Godot.ProjectSettings.GlobalizePath("res://addons/gdUnit3/mono/test/core/resources/sources/TestPerson.cs")), sourceClass);

string expected = NewCreatedTestSuite(sourceClass);

Expand Down
2 changes: 1 addition & 1 deletion addons/gdUnit3/src/core/GdObjects.gd
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,7 @@ static func is_cs_test_suite(instance :Node) -> bool:

static func is_cs_testsuite(script :Script) -> bool:
if GdUnitTools.is_mono_supported():
var csTools = load("res://addons/gdUnit3/src/core/CsTools.cs").new()
var csTools = load("res://addons/gdUnit3/mono/src/core/CsTools.cs").new()
return not script.resource_path.empty() and csTools.IsTestSuite(script.resource_path)
return false;

Expand Down
2 changes: 1 addition & 1 deletion addons/gdUnit3/src/core/GdUnitRunner.gd
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ func _init():
# store current runner instance to engine meta data to can be access in as a singleton
Engine.set_meta(GDUNIT_RUNNER, self)
if GdUnitTools.is_mono_supported():
_cs_executor = load("res://addons/gdUnit3/src/core/execution/Executor.cs").new()
_cs_executor = load("res://addons/gdUnit3/mono/src/core/execution/Executor.cs").new()
_cs_executor.AddGdTestEventListener(self)

func _ready():
Expand Down
2 changes: 1 addition & 1 deletion addons/gdUnit3/src/core/GdUnitTestSuiteBuilder.gd
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ func create(source :Script, line_number :int) -> Result:
if GdObjects.is_cs_script(source):
if not GdUnitTools.is_mono_supported():
return Result.error("Can't create test. No c# support found.")
var csTools = load("res://addons/gdUnit3/src/core/CsTools.cs").new()
var csTools = load("res://addons/gdUnit3/mono/src/core/CsTools.cs").new()
var result := csTools.CreateTestSuite(source.resource_path, line_number+1, test_suite_path) as Dictionary
if result.has("error"):
return Result.error(result.get("error"))
Expand Down
2 changes: 1 addition & 1 deletion addons/gdUnit3/src/core/_TestSuiteScanner.gd
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ static func _is_script_format_supported(resource_path :String) -> bool:
return false

func _parse_cs_test_suite(script :Script) -> Node:
var csTools = load("res://addons/gdUnit3/src/core/CsTools.cs").new()
var csTools = load("res://addons/gdUnit3/mono/src/core/CsTools.cs").new()
return csTools.ParseTestSuite(script.resource_path)

func _parse_test_suite(script :GDScript) -> GdUnitTestSuite:
Expand Down
4 changes: 2 additions & 2 deletions addons/gdUnit3/test/core/GdObjectsTest.gd
Original file line number Diff line number Diff line change
Expand Up @@ -588,8 +588,8 @@ func test_is_snake_case() -> void:
func test_is_test_suite() -> void:
assert_bool(GdObjects.is_test_suite(GdUnitTestResourceLoader.load_gd_script("res://addons/gdUnit3/test/core/ResultTest.gd"))).is_true()
if GdUnitTools.is_mono_supported():
assert_bool(GdObjects.is_test_suite(GdUnitTestResourceLoader.load_cs_script("res://addons/gdUnit3/test/core/ExampleTestSuite.cs"))).is_true()
assert_bool(GdObjects.is_test_suite(GdUnitTestResourceLoader.load_cs_script("res://addons/gdUnit3/test/core/resources/testsuites/mono/NotATestSuite.cs"))).is_false()
assert_bool(GdObjects.is_test_suite(GdUnitTestResourceLoader.load_cs_script("res://addons/gdUnit3/mono/test/core/ExampleTestSuite.cs"))).is_true()
assert_bool(GdObjects.is_test_suite(GdUnitTestResourceLoader.load_cs_script("res://addons/gdUnit3/mono/test/core/resources/testsuites/mono/NotATestSuite.cs"))).is_false()
# currently not supported
assert_bool(GdObjects.is_test_suite(NativeScript.new())).is_false()
assert_bool(GdObjects.is_test_suite(PluginScript.new())).is_false()
Expand Down
2 changes: 1 addition & 1 deletion addons/gdUnit3/test/core/GdUnitTestSuiteBuilderTest.gd
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ func before_test():
var result := GdUnitTools.copy_file("res://addons/gdUnit3/test/core/resources/sources/test_person.gd", temp)
assert_result(result).is_success()
_example_source_gd = result.value() as String
result = GdUnitTools.copy_file("res://addons/gdUnit3/test/core/resources/sources/TestPerson.cs", temp)
result = GdUnitTools.copy_file("res://addons/gdUnit3/mono/test/core/resources/sources/TestPerson.cs", temp)
assert_result(result).is_success()
_example_source_cs = result.value() as String
_test_suite_builder = GdUnitTestSuiteBuilder.new()
Expand Down