tags:

views:

43

answers:

1

Groovy has a power assert, but I'd like a power print. For example,

def foo = 'banna5', monkey=7, x=70
println "foo=$foo, monkey=$monkey, x/2=${x/2}"

See the repeating foo, monkey, and expression in the println line... what I want to type is this,

pprint foo, monkey, x/2

This is the output I expect (from either println or pprintln),

foo=banna5, monkey=7, x/2=35

Is there a ditty that does this already?

A: 

There is nothing that does what you want currently in Groovy...

The problem would be getting the names of the variables when you print out the values.

The way that powerrassert seems to do it, is via AST manipulation of the bytecode (see line 947 of the class org.codehaus.groovy.classgen.AsmClassGenerator) to decorate the assert method with several classes inside the org.codehaus.groovy.runtime.powerassert package.

So to get the results you require, something similar would have to be added to manipulate the AST in a similar way.

You could add a new feature issue to the project's JIRA, and you never know...it might make it into future versions of Groovy

But for now, I think you're stuck with your println as you have it above

tim_yates
Added as http://jira.codehaus.org/browse/GROOVY-4302
Bob Herrmann