Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.Sign up
Show code for blocks without description #96
Currently, empty blocks are shown like this:
Groovy tests should be written meaningful and often it doesn't make sense to describe each block (duplication or comment out of date):
What do you think about to generate block description from code (with Groovy ASTTransformation):
can be in report:
It could be experimental feature enabled by annotation.
I have a code draft that works for this example test like below.
added a commit
Mar 19, 2017
@hexmind I've been trying to fix the code you submitted for a week now, and I am nowhere near finishing. I had thought you had implemented something that at least would work for simple cases, but it doesn't even work for the simplest of cases at all.
Only one line of code is captured, and only if the line happens to be a simple case where the first statement is not a constant or any expression other than
FYI you did not handle the following other cases:
The mapping between code lines and blocks would only work if the spec had a single block definition for each keyword (ie. only one
Unfortunately, the code has been merged to next, which already contained quite a few other changes for the next release...
My question is: do you have time to help finish implementing this feature correctly?
I know how to do it, but I don't have all the time in the world to spend on this! So any help would be appreciated, I can tell you what needs to be done. Let me know.
I know how to do it the hard way, which is by handling every single statement type (shown in the image I posted). Would be awesome to let some library do it for us, though... Spock itself captures only single expressions, it seems, not the full source for a block... that's why it's hard, because we need to iterate through each statement, figure out how to handle each type, then ask the Spock's
This feature is now implemented correctly! I found out that Spock's source code lookup works for any AST node, no need to recurse into each expression, so it's much easier and much more reliable.
I had to change completely the implementation, but that was mostly refactoring and cleaning up, the hard part is done by Spock (to actually read the source code from each class).
I will still add more tests for the lots of edge cases (nested classes, several classes in one file, specs with methods that look like tests but are not, etc).
Soon we can have this released.
BTW. Please checkout the "next" branch and take this code for a spin!
Add this to your
Let me know if you have issues.