-
Notifications
You must be signed in to change notification settings - Fork 468
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
Implemented partial parameter definitions #525
Conversation
444bc42
to
800f74f
Compare
800f74f
to
782088d
Compare
Until now the parameters either included all the data table header elements or none. Their order wasn't enforced, but was replaced with a method call, based on the header, causing parameter values to be mixed up. This is changed now to variable number parameter definition, where only the order is enforced: - first you can define the type of any variable from the data table, followed by arbitrary number of extra parameters (called with `null`, no default values supported yet) * the data table header order is compile-time checked * the extra parameters can serve as type-safety declarations outside the method body * provided default parameter values are compile-time rejected (not supported yet) * primitives are auto-wrapped to nullable types (they need default values)
782088d
to
26dfd39
Compare
@@ -16,21 +16,27 @@ | |||
|
|||
package org.spockframework.compiler; | |||
|
|||
import java.util.*; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please don't change the ordering of the imports and also avoid whitespace changes, where nothing really happens, this makes this commit just harder to read.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The imports are done by Idea automatically.
The end of line trimming is an .editorconfig
setting, provided with the project: trim_trailing_whitespace = true
Would it be possible to configure these setting the way you would like to receive them, and reformat the whole codebase with it (and commit the config also).
It shouldn't take more than an hour, and would save all these reviews about formatting.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unfortunately .editorconfig
is too limited to really cover the whole spock formatting and not all code really has the correct one, however if you are using IntelliJ you can configure the formatting to only apply to your changed code.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would gladly unify the styles and provide a config for Idea
and .editorconfig
and reformat the whole codebase to avoid this confusion (so that new people have the correct settings from the start - it's not ok that everyone has to configure the styles on their own, and it's also not ok that the code is not uniform, and it's also not ok that I have to manually revert the imports and the trailing spaces every time I modify something)
I don't quite understand the use of this, why would I want to declare extra parameters in the method when they are not passed? IMHO most method declarations are too large anyway so I think its a good to declare local variables in I could see however the use to declare less parameters than, e.g. when you are using one for the description. I always disliked that I had to include it in the parameter definitions although I only used it in the Here a contrived example:
|
What's the impact on ordering of having assignments in addition to a data table? Is it clear what the expected order is in that case? I personally haven't ever used parameters in this way. I share the confusion around the point of being able to declare arbitrary extra parameters that will be |
The additional parameters are strictly at the end of existing data params (there's a test for that). Sometimes you have to reassign a variable because you're testing it in different states, i.e. when: a = [1,2,3]
then: ...
when: a = [4,5,6]
then: ... If you can define Also, sometimes the The given/when blocks are for assigning values, not necessarily for declaring types - but the param list IS. |
I disagree, some code style checkers even consider reassigning parameters a code smell. The only reason I leave the final modifier from the parameter declarations in most of my code is that it generates too much noise. IMHO the |
I consider it a smell too: the production code is probably too stateful. But I think the testing framework should be flexible enough to accommodate to that. We used Spock for testing our message sending framework and some of the tests looked something like: when: Message message = 'new'
then: ...
when: message = 'update'
then: ...
when: message = 'delete'
then: ...
when: message = 'update'
then: exception i.e. we reused the variable, because it plays the same role: it's the message that we're sending, but only the first one is defined. If however there is a consensus that params should only be used for data tables, I will remove it from my PR :) |
Please advise on what I should change for this to be merged! |
|
Such preamble (with different number of components) included in all tests. It will be better to reduce this code to
|
Hi @Fuud,
Mostly because it was buggy until now (it ignored the order and tried to call it anyway), and because it's counterintuitive (e.g. in your example you wouldn't want to confuse injected parameters with data providers).
In the current PR data providers are optional already (only the order is enforced).
+1.
I suppose you mean some kind of dependency injector (Spring/Guice?). @leonard84, @robfletcher, opinions? |
Please take a look at Fuud@16739b3 I solved this problem with resolving parameters by name. It is just a prototype because derived parametrization was broken. But IMHO it is better way to implement this. And interceptors can change IterationInfo.dataValues providing additional parameters. |
@Fuud, I still object to making the parameter orders permutable, for the above reasons. |
Please take a look at #566 |
Hey @leonard84, would it make sense for me to rebase this PR or should we close it? |
Hey @paplorinc this feature is now already in Spock 2.0 so I'll close this PR |
Until now the parameters either included all the data table header elements or none.
Their order wasn't enforced, but was replaced with a method call, based on the header,
causing parameter values to be mixed up.
This is changed now to variable number parameter definition, where only the order is enforced:
number of extra parameters (called with
null
, no default values supported yet)This change is