andresteingress / gcontracts

GContracts: Programming by Contract for Groovy
http://gcontracts.org
114 stars 11 forks source link

Assertion Errors need better messages #5

Closed HamletDRC closed 14 years ago

HamletDRC commented 14 years ago

The Class invariant produces error message that could be improved.

Here is one such exception: java.lang.AssertionError: [invariant] Invariant in class violated. Expression: this.$invariant$Ariane5.call() at gcontracts.Ariane5.accelerate(Ariane5.groovy:11) at gcontracts.Ariane5Test.test overflow(Ariane5Test.groovy:26)

It is possible in an AST Transformation to capture the source that produced a statement. You could capture the @Invariant source and and print it out as part of the failure message.

andresteingress commented 14 years ago

jup, you are right, better error messages are on top of my todo list.

i wanted to talk to peter in our next ejug meeting on his opinion about using power assertions in gcontracts. i really like the idea of getting a detailed explanation of what went wrong in an invariant/pre/postcondition.

HamletDRC commented 14 years ago

also, if you want to capture the code take a look at Groovy-core AstBuilder.buildFromCode. It does that as well. Power asserts is the way to go though.

andresteingress commented 14 years ago

okay, i'll have a look at it

HamletDRC commented 14 years ago

check out the convertClosureToSource method in: http://svn.codehaus.org/groovy/trunk/groovy/groovy-core/src/main/org/codehaus/groovy/ast/builder/AstBuilderTransformation.groovy

andresteingress commented 14 years ago

fixed in current master.

the message text should know look like:

[invariant] Invariant in class violated: { ... }.

preferred way is still the integration of power asserts, i am going to have a look at that topic in the next major version.

HamletDRC commented 14 years ago

nice response time :)