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

Document loss of default values for method parameters when doubling #263

Closed
bitwes opened this issue Jan 7, 2021 · 4 comments
Closed

Document loss of default values for method parameters when doubling #263

bitwes opened this issue Jan 7, 2021 · 4 comments
Labels
documentation next release This has been implemented and will be in the next release.
Milestone

Comments

@bitwes
Copy link
Owner

bitwes commented Jan 7, 2021

Godot does not provide metadata about default parameters yet. Since it can't be known which parameters are defaulted, GUT defaults ALL parameters to ALL methods to null. This can cause hard to figure out issues when you do a partial_double (or stub a method to_call_super) and a method has a parameter that is defaulted to something other than null.

Example:

var _sum  = 0
func increment(inc_by=1):
  _sum += inc_by

The double definition for increment will be:

func increment(inc_by=null):

If this method is part of a partial_double or is stubbed to_call_super and is called without parameters during a test (directly or indirectly) then this will cause an Invalid operands 'int' and 'Nil' error.

@bitwes bitwes added this to the v7.2.0 milestone Feb 9, 2021
@astrale-sharp
Copy link
Contributor

Hey, so what would be the plan to tackle this problem? (waiting metadata and using them?) :)

@bitwes
Copy link
Owner Author

bitwes commented Sep 29, 2021

There is a Godot issue for this: godotengine/godot#33624

I think I'm going to expand on the solution for #266 and allow you to specify default values in addition to the number of parameters.

@bitwes bitwes added the next release This has been implemented and will be in the next release. label Oct 18, 2021
@bitwes
Copy link
Owner Author

bitwes commented Oct 18, 2021

Introduced stub(...).param_defaults([]) which allows you to specify the default values that a method should get.

@bitwes
Copy link
Owner Author

bitwes commented Oct 25, 2021

7.2.0 you can now stub default values for method parameters:

var Foo = load('res://foo.gd')
test_go_up_one_increments_sum_by_1():
  var dbl_foo = double(Foo).new()
  stub(dbl_foo, 'go_up_one').to_call_super().param_defaults([1])

  dbl_foo.go_up_one()
  assert_called(dbl_foo, 'increment', [1])

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation next release This has been implemented and will be in the next release.
Projects
None yet
Development

No branches or pull requests

2 participants