8000 Godot 4 inner classes by bitwes · Pull Request #448 · bitwes/Gut · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Godot 4 inner classes #448

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

Merged
merged 4 commits into from
Nov 23, 2022
Merged
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
25 changes: 12 additions & 13 deletions GODOT_4_README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@


## Overview
Ported to Godot 4 Beta 4
Ported to Godot 4 Beta 5

GUT is currently somewhat usable in 4.0. Some features work, but many do not. The CLI works, but the in-editor panel does not.

Expand All @@ -13,18 +13,17 @@ This file tracks the changes that have occurred in porting GUT to Godot 4.0. Al
```
Totals
Scripts: 172
Passing tests 1057
Failing tests 37
Risky tests 14
Pending: 28
Asserts: 1618 of 1661 passed
Passing tests 1042
Failing tests 14
Risky tests 16
Pending: 27
Asserts: 1608 of 1630 passed

Warnings/Errors:
* 15 Errors.
* 6 Warnings.
* 36 Warnings.


1057 passed 37 failed. Tests finished in 132.005s
1042 passed 14 failed. Tests finished in 132.377s
```


Expand Down Expand Up @@ -66,12 +65,12 @@ These are changes to Godot that affect how GUT is used/implemented.
* Doubling, Spying, Stubbing (mostly). Cannot double inner classes.
* Using `await` (the new `yield`) in tests, and all the GUT supplied `yield_` methods. See notes in Changes section.
* Input mocking.
* Doubling Inner Classes has been fixed and all the tests have been restored.

## Broken Features
* Gut Panel. The in-editor panel is not working, you must use the CLI for now.
* Cannot double inner classes due to Godot bug #65666.
* Dictionary/array asserts are broke in some cases.
* Probably much much more.
* Gut Panel. The in-editor panel is not working, you must use the CLI or the VSCode plugin (which uses the cli) for now.
* Dictionary/array asserts are broke in some cases. Godot 4 passes all arrays and dictionaries by reference now (arrays were by value, dictionaries were by reference). This has broken a lot of the logic for comparing dictionaris, arrays, arrays in dictionaries, dictionaries in arrays.
* Probably somewhat more.



Expand Down
8 changes: 4 additions & 4 deletions addons/gut/doubler.gd
Original file line number Diff line number Diff line change
Expand Up @@ -322,11 +322,11 @@ func partial_double_gdnative(which):
func double_inner(parent, inner, strategy=_strategy):
var parsed = _script_collector.parse(parent, inner)
return _create_double(parsed, strategy, null, false)
return null

func partial_double_inner(path, subpath, strategy=_strategy):
_lgr.error('Cannot double inner classes due to Godot bug.')
return null

func partial_double_inner(parent, inner, strategy=_strategy):
var parsed = _script_collector.parse(parent, inner)
return _create_double(parsed, strategy, null, true)


func add_ignored_method(obj, method_name):
Expand Down
8 changes: 5 additions & 3 deletions addons/gut/script_parser.gd
Original file line number Diff line number Diff line change
Expand Up @@ -129,14 +129,16 @@ class ParsedScript:
if(!script_or_inst is Resource):
to_load = load(script_or_inst.get_script().get_path())

_script_path = to_load.resource_path
if(inner_class != null):
_subpath = _find_subpath(to_load, inner_class)

if(inner_class == null):
_resource = to_load
else:
_resource = inner_class
_script_path = to_load.resource_path
to_load = inner_class

if(inner_class != null):
_subpath = _find_subpath(to_load, inner_class)

_parse_methods(to_load)

Expand Down
20 changes: 11 additions & 9 deletions addons/gut/test.gd
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ class DoubleInfo:
var _is_native = false
var is_valid = false
var resource = null
var inner_resource = null

# Flexible init method. p2 can be subpath or stategy unless p3 is
# specified, then p2 must be subpath and p3 is strategy.
Expand All @@ -67,7 +68,7 @@ class DoubleInfo:
if(_utils.is_instance(thing)):
return

if(typeof(p2) == TYPE_STRING):
if(typeof(p2) != TYPE_INT):
strategy = p3
subpath = p2

Expand All @@ -77,12 +78,13 @@ class DoubleInfo:
resource = thing
elif(typeof(thing) == TYPE_STRING):
resource = load(thing)
if(su 8000 bpath != null and typeof(subpath) == TYPE_STRING):
var parts = subpath.split('/')
for i in range(parts.size()):
resource = resource.get(parts[i])
elif(subpath != null):
resource = subpath

if(subpath != null and typeof(subpath) == TYPE_STRING):
var parts = subpath.split('/')
for i in range(parts.size()):
inner_resource = resource.get(parts[i])
elif(subpath != null):
inner_resource = subpath

is_valid = true

Expand Down Expand Up @@ -1305,9 +1307,9 @@ func _smart_double(double_info):
to_return = gut.get_doubler().double(double_info.resource, override_strat)
else:
if(double_info.make_partial):
to_return = gut.get_doubler().partial_double_inner(double_info.resource, double_info.subpath, override_strat)
to_return = gut.get_doubler().partial_double_inner(double_info.resource, double_info.inner_resource, override_strat)
else:
to_return = gut.get_doubler().double_inner(double_info.resource, double_info.subpath, override_strat)
to_return = gut.get_doubler().double_inner(double_info.resource, double_info.inner_resource, override_strat)
return to_return

# ------------------------------------------------------------------------------
Expand Down
2 changes: 2 additions & 0 deletions addons/gut/utils.gd
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,8 @@ func _on_http_request_latest_version_completed(result, response_code, headers, b

const GUT_METADATA = '__gutdbl'

# Note, these cannot change since places are checking for TYPE_INT to determine
# how to process parameters.
enum DOUBLE_STRATEGY{
SCRIPT_ONLY,
INCLUDE_SUPER
Expand Down
66 changes: 57 additions & 9 deletions scratch/find_inner_classes.gd
Original file line number Diff line number Diff line change
Expand Up @@ -67,19 +67,67 @@ func get_inner_class_string(inner, parent_script):
return to_return


func print_other_info(loaded, msg = '', indent=''):
print(indent, loaded)

var base_script_path = 'NO base script'
if(loaded.has_method('get_base_script')):
if(loaded.get_base_script() != null):
base_script_path = str('"', loaded.get_base_script().get_path(), '"')
else:
base_script_path = 'Null base script'

print(indent, 'base_script path ', base_script_path)
print(indent, 'class ', loaded.get_class())
print(indent, 'instance base type ', loaded.get_instance_base_type())
print(indent, 'instance_id ', loaded.get_instance_id())
print(indent, 'meta_list ', loaded.get_meta_list())
print(indent, 'name ', loaded.get_name())
print(indent, 'path ', loaded.get_path())
print(indent, 'resource local to scene ', loaded.resource_local_to_scene)
print(indent, 'resource name ', loaded.resource_name)
print(indent, 'resource path ', loaded.resource_path)
print(indent, 'RID ', loaded.get_rid())
print(indent, 'script ', loaded.get_script())
print()





func find_parent_script(InnerClass):
var max_search = 20
var start_id = InnerClass.get_instance_id()
var search_id = start_id + 1
var found = false

while(search_id < start_id + max_search and !found):
print(search_id)
var search_obj = instance_from_id(search_id)
print(search_obj)
if(search_obj != null):
print(search_obj)
search_id += 1


func _init():
var result = get_inner_class_string(HasSomeInners.Inner2.Inner2_b, self.get_script())
print(result)
print(GutDoubleTestInnerClasses)
print(GutDoubleTestInnerClasses.InnerA)
print(ThatInnerClassScript.get_instance_id() + ThatInnerClassScript.InnerA.get_instance_id())
find_parent_script(GutDoubleTestInnerClasses.InnerA)
quit()

print()
result = get_inner_class_string(ThatInnerClassScript.InnerWithSignals, ThatInnerClassScript)
print(result)
# var result = get_inner_class_string(HasSomeInners.Inner2.Inner2_b, self.get_script())
# print(result)

# print()
# result = get_inner_class_string(ThatInnerClassScript.InnerWithSignals, ThatInnerClassScript)
# print(result)

print(get_extends_text(HasSomeInners.Inner2.Inner2_b, self.get_script()))
# print(get_extends_text(HasSomeInners.Inner2.Inner2_b, self.get_script()))

print(get_extends_text(HasSomeInners.Inner2.Inner2_b, HasSomeInners))
# print(get_extends_text(HasSomeInners.Inner2.Inner2_b, HasSomeInners))

print(get_extends_text(ThatInnerClassScript.InnerWithSignals, ThatInnerClassScript))
# print(get_extends_text(ThatInnerClassScript.InnerWithSignals, ThatInnerClassScript))

quit()
# quit()
18 changes: 14 additions & 4 deletions scratch/get_info.gd
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ const DOUBLE_ME_PATH = 'res://test/resources/doubler_test_objects/double_me.gd'
var DoubleMe = load(DOUBLE_ME_PATH)
var DoubleMeScene = load('res://test/resources/doubler_test_objects/double_me_scene.tscn')
var SetGetTestNode = load('res://test/resources/test_assert_setget_test_objects/test_node.gd')
# const INNER_CLASSES_PATH = 'res://test/resources/doubler_test_objects/inner_classes.gd'
# var InnerClasses = load(INNER_CLASSES_PATH)

var json = JSON.new()
var _strutils = load('res://addons/gut/strutils.gd').new()

Expand Down Expand Up @@ -138,10 +141,10 @@ func get_defaults_and_types(method_meta):

func class_db_stuff():
print(ClassDB.class_exists('Node2D'))
#print('category = ', ClassDB.('Node2D'))
#print(str(JSON.print(ClassDB.class_get_method_list('Node2D'), ' ')))
# print('category = ', ClassDB.('Node2D'))
# print(str(JSON.print(ClassDB.class_get_method_list('Node2D'), ' ')))
# print(ClassDB.class_get_integer_constant_list('Node2D'))
# print(ClassDB.get_class_list())
print(ClassDB.get_class_list())


func does_inherit_from_test(thing):
Expand Down Expand Up @@ -186,6 +189,7 @@ func print_other_info(loaded, msg = '', indent=''):
var const_map = loaded.new().get_script().get_script_constant_map()
if(const_map.size() > 0):
print(indent, '--- Constants ---')

for key in const_map:
var thing = const_map[key]
print(indent, key, ' = ', thing)
Expand Down Expand Up @@ -385,8 +389,14 @@ func get_scene_script_object(scene):
return to_return




func _init():
pp(Button.new().get_method_list())
# pp(Button.new().get_method_list())
print_other_info(GutDoubleTestInnerClasses)
# print("---------------\n\n\n\n-------------------")
# print_other_info(GutDoubleTestInnerClasses.InnerA)
# class_db_stuff()
# print_all_info(DoubleMeScene)
# var TestScene = load('res://test/resources/doubler_test_objects/double_me_scene.tscn')
# print_scene_info(TestScene)
Expand Down
9 changes: 3 additions & 6 deletions test/integration/test_gut_integration.gd
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
extends 'res://addons/gut/test.gd'
extends GutTest

class CoupledScriptTest:
extends 'res://addons/gut/test.gd'
extends GutTest

var _gut = null

Expand Down Expand Up @@ -54,9 +54,6 @@ class TestYieldInBeforeAfterMethods:
_assert_pass_fail_count(1, 0)

func test_gut_waits_for_yield_in_after_all():
pending('local method _get_inner_class_script_instance is broke in 4.0')
return

_run_tests(SCRIPT_PATH, 'TestYieldInAfterAll', null)
await yield_to(_gut, 'end_run', 10)
var test_script = _get_inner_class_script_instance('TestYieldInAfterAll')
Expand All @@ -80,7 +77,7 @@ class TestYieldInBeforeAfterMethods:
# assert_eq(test_script.before_each_value, 'set', 'before_each_value')

class TestOutputWhenRunDirectly:
extends 'res://addons/gut/test.gd'
extends GutTest

var before_all_value = 'NOT_SET'
var before_each_value = 'NOT_SET'
Expand Down
Loading
0