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

Data table cells can reference previous ones #526

Merged
merged 1 commit into from
Nov 13, 2015

Conversation

l0rinc
Copy link
Contributor

@l0rinc l0rinc commented Sep 12, 2015

For data driven tests it could be important for a parameter to depend
on a previously calculated value.

Until now this wasn't possible, because the whole where block was calculated,
before the test method was called (via its generated parameters).
Also, the data providers calculate the whole column,
before moving on to the next one, making the references seem unobvious.

The fix was to provide the data provider methods with the list of already
calculated columns.
And because a cell should only refer to cells in the same row,
the variable references were changed to array indexes (see the getAt part).

This commit should play well with partial parameter definitions.

Partially fixes: #509

@l0rinc l0rinc force-pushed the ColumnReference branch 9 times, most recently from 639d58c to 77a1efc Compare September 13, 2015 11:13
For parametarized tests it could be important for a parameter to depend
on a previously calculated value.

Until now this wasn't possible, because the whole where block was calculated,
before the test method was called (via its generated parameters).
Also, the data providers calculate the whole column,
before moving on to the next one, making the references seem unobvious.

The fix was to provide the data provider methods with the list of already
calculated columns.
And because a cell should only refer to cells in the same row,
the variable references were changed to array indexes (see the getAt part).

This commit should play well with partial parameter definitions.

Partially fixes spockframework#509
@PascalSchumacher
Copy link

+1

@l0rinc
Copy link
Contributor Author

l0rinc commented Nov 11, 2015

Why is it a breaking change exactly (and why is that a problem)?

@leonard84
Copy link
Member

This change brakes the current behavior of spocks public interface. The problem with breaking changes is that, perfectly good tests will start failing or won't even compile. So those changes shouldn't be done lightly and if they are done, they need to be communicated as such.

-  def "parameters in different order"(y, x) {
-    expect:
-    x == y
-
-    where:
-    x << [1, 2]
-    y << [1, 2]
-  }

}

@Ignore
def 'data table elements can reference each other'() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the problem here?

@l0rinc
Copy link
Contributor Author

l0rinc commented Nov 12, 2015

perfectly good tests will start failing or won't even compile

The test you quoted is wrong, because it uses a commutative operator (i.e. the x and y values are switched in reality).

They didn't work until now either, they just seemed to (feel free to change change the values the types or the operator).

I don't think this is a breaking change

@leonard84
Copy link
Member

@paplorinc you are right the test was wrong, I removed the label again.

Why is 'data table elements can reference each other' ignored, it looks like it should work.

a = 1
b = a + 1

c << [b + 1]
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No such property: b

The problem seems to be here, i.e. data tables cannot access previous variable declarations.
This was the case before the fix also.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can this be fixed? Otherwise the user will have to know which combinations work and which don't.
Also it might be a good idea to have more simple tests for each of the combinations used in this test, some exist already but there are still missing combinations. Especially the minimal failing where clause.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree perfectly, but:

  1. this seemed not strictly related (i.e. should be fixable separately)
  2. this change is complicated enough already
  3. ...and it's in review for 2 months

If someone reviews and merges them within a few weeks, I would gladly provide a PR for this also :)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@robfletcher and I were discussing this PR an decided to include it in the upcoming 1.1 Release, which is planned to happen when #17 is implemented and merged (hopefully within two weeks).

I'm ok with fixing it in a separate commit, as long as it is mentioned in the documentation (which is still missing 😉 ). The documentation should include examples for what is and what is not yet possible, and what will never work (e.g., referencing values from a previous execution). Could you please provide this documentation in another PR.

Regarding 3) yeah it's unfortunate, but we do this in our spare time and as you said in 2) it's a complicated change and it takes time and requires more mental work than a simple pr so you can't just do it on the side. Anyway thanks a lot for the PR and I'm looking forward to your next ones. And look on the bright sight, my PR #17 is from September 2013! and its been in limbo until recently ;) so two month vs. two years is not that bad.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @leonard84, @PascalSchumacher, and @robfletcher :)!

two month vs. two years is not that bad.

I wasn't complaining, just stating that I won't do more PRs until I know whether they're needed :)

Rebased my other related PR Implemented partial parameter definitions, can someone please review it?

leonard84 added a commit that referenced this pull request Nov 13, 2015
Data table cells can reference previous ones
@leonard84 leonard84 merged commit 805fd77 into spockframework:master Nov 13, 2015
@l0rinc l0rinc deleted the ColumnReference branch November 13, 2015 19:36
@l0rinc
Copy link
Contributor Author

l0rinc commented Nov 16, 2015

@PascalSchumacher, @leonard84, @robfletcher, @pniederw, could someone please explain what the difference between

where: a << 1

and

where: a = 1

is supposed to be?

Since it's not even documented afaik, could we merge the behavior of the two and keep the = for single values only (before and after data tables)?

The goal would be to make this test pass: https://github.com/paplorinc/spock/blob/a421de5972f0b7fc2a73c85fbfcc5e04c2428c67/spock-specs/src/test/groovy/org/spockframework/smoke/parameterization/DataTables.groovy#L324

@l0rinc
Copy link
Contributor Author

l0rinc commented Nov 26, 2015

I tried implementing that variables be usable before and after data tables/pipes, but I could only make one or the other work - either:

expect: CONST > 3 && b < 3
where:  CONST = Math.PI
        b << [CONST / 2, CONST / 3]

or

expect: a + 1 == b
where:  a << [1, 2]
        b = a + 1

(but not both, it wasn't designed that way and I have already rewritten too much...)

Could someone please respond to my questions, I cannot progress if I have to reverse engineer everything...

@PascalSchumacher
Copy link

@paplorinc I would like to help you, but I can't. I'm just a spock user, with no knowledge of spock internals. Sorry!

I guess @pniederw is the only one who could be able to help you, but he did his work on spock so long ago, that even he may not remember.

@l0rinc
Copy link
Contributor Author

l0rinc commented Nov 30, 2015

Created a refactoring commit, as fixing it ended up taking too much effort, let's do it in smaller steps: #554

@robfletcher robfletcher modified the milestone: 1.1-rc-1 Aug 24, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Where block parameters should be able to reference each other
4 participants