-
-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
GD-517: Fic test discovery guard fails on CSharpScript tests when edi…
…ting # Why see #517 # What - added rebuild cs scripts before run discovery - fixed invalid script path resolving by using `localize_path` to convert cs script paths - fixes test suite scanner to run on Script class to accept GDScript and CSharpScript
- Loading branch information
1 parent
b5dfc3c
commit 7ba08c7
Showing
9 changed files
with
177 additions
and
38 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
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
79 changes: 79 additions & 0 deletions
79
addons/gdUnit4/test/core/discovery/GdUnitTestDiscoverGuardTest.gd
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,79 @@ | ||
# GdUnit generated TestSuite | ||
class_name GdUnitTestDiscoverGuardTest | ||
extends GdUnitTestSuite | ||
@warning_ignore('unused_parameter') | ||
@warning_ignore('return_value_discarded') | ||
|
||
# TestSuite generated from | ||
const GdUnitTestDiscoverGuard = preload("res://addons/gdUnit4/src/core/discovery/GdUnitTestDiscoverGuard.gd") | ||
|
||
|
||
|
||
|
||
|
||
func test_inital() -> void: | ||
var discoverer := GdUnitTestDiscoverGuard.new() | ||
|
||
assert_dict(discoverer._discover_cache).is_empty() | ||
|
||
|
||
func test_sync_cache() -> void: | ||
var discoverer := GdUnitTestDiscoverGuard.new() | ||
|
||
var dto := create_test_dto("res://test/my_test_suite.gd", ["test_a", "test_b"]) | ||
discoverer.sync_cache(dto) | ||
|
||
assert_dict(discoverer._discover_cache).contains_key_value("res://test/my_test_suite.gd", ["test_a", "test_b"]) | ||
|
||
|
||
func test_discover_on_GDScript() -> void: | ||
var discoverer :GdUnitTestDiscoverGuard = spy(GdUnitTestDiscoverGuard.new()) | ||
|
||
# connect to catch the events emitted by the test discoverer | ||
var emitted_events :Array[GdUnitEvent] = [] | ||
GdUnitSignals.instance().gdunit_event.connect(func on_gdunit_event(event :GdUnitEvent) -> void: | ||
emitted_events.append(event) | ||
) | ||
|
||
var script := load("res://addons/gdUnit4/test/core/discovery/resources/DiscoverExampleTestSuite.gd") | ||
assert_that(script).is_not_null() | ||
if script == null: | ||
return | ||
|
||
await discoverer.discover(script) | ||
# verify the rebuild is NOT called for gd scripts | ||
verify(discoverer, 0).rebuild_project(script) | ||
|
||
assert_array(emitted_events).has_size(1) | ||
assert_object(emitted_events[0]).is_instanceof(GdUnitEventTestDiscoverTestSuiteAdded) | ||
assert_dict(discoverer._discover_cache).contains_key_value("res://addons/gdUnit4/test/core/discovery/resources/DiscoverExampleTestSuite.gd", ["test_case1", "test_case2"]) | ||
|
||
|
||
func test_discover_on_CSharpScript(do_skip := !GdUnit4CSharpApiLoader.is_mono_supported()) -> void: | ||
var discoverer :GdUnitTestDiscoverGuard = spy(GdUnitTestDiscoverGuard.new()) | ||
|
||
# connect to catch the events emitted by the test discoverer | ||
var emitted_events :Array[GdUnitEvent] = [] | ||
GdUnitSignals.instance().gdunit_event.connect(func on_gdunit_event(event :GdUnitEvent) -> void: | ||
emitted_events.append(event) | ||
) | ||
|
||
var script :Script = load("res://addons/gdUnit4/test/core/discovery/resources/DiscoverExampleTestSuite.cs") | ||
|
||
await discoverer.discover(script) | ||
# verify the rebuild is called for cs scripts | ||
verify(discoverer, 1).rebuild_project(script) | ||
assert_array(emitted_events).has_size(1) | ||
assert_object(emitted_events[0]).is_instanceof(GdUnitEventTestDiscoverTestSuiteAdded) | ||
assert_dict(discoverer._discover_cache).contains_key_value("res://addons/gdUnit4/test/core/discovery/resources/DiscoverExampleTestSuite.cs", ["TestCase1", "TestCase2"]) | ||
|
||
|
||
func create_test_dto(path: String, test_cases: PackedStringArray) -> GdUnitTestSuiteDto: | ||
var dto := GdUnitTestSuiteDto.new() | ||
dto._path = path | ||
for test_case in test_cases: | ||
var test_dto := GdUnitTestCaseDto.new() | ||
test_dto._name = test_case | ||
test_dto._line_number = 42 | ||
dto.add_test_case(test_dto) | ||
return dto |
21 changes: 21 additions & 0 deletions
21
addons/gdUnit4/test/core/discovery/resources/DiscoverExampleTestSuite.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,21 @@ | ||
namespace GdUnit4.Tests.Resource | ||
{ | ||
using static Assertions; | ||
|
||
[TestSuite] | ||
public partial class ExampleTestSuite | ||
{ | ||
|
||
[TestCase] | ||
public void TestCase1() | ||
{ | ||
AssertBool(true).IsEqual(true); | ||
} | ||
|
||
[TestCase] | ||
public void TestCase2() | ||
{ | ||
AssertBool(false).IsEqual(false); | ||
} | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
addons/gdUnit4/test/core/discovery/resources/DiscoverExampleTestSuite.gd
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,9 @@ | ||
extends GdUnitTestSuite | ||
|
||
|
||
func test_case1() -> void: | ||
assert_bool(true).is_equal(true); | ||
|
||
|
||
func test_case2() -> void: | ||
assert_bool(false).is_equal(false); |