[prev in list] [next in list] [prev in thread] [next in thread] 

List:       groovy-user
Subject:    [groovy-user] Applying AST transformation for testing
From:       Jorge Franco <grooscript () gmail ! com>
Date:       2014-09-24 7:11:50
Message-ID: CAApEaYRYGPbseF3cfVFv6aW+2QLXAZgeEkcxMri2e91gaXSbDA () mail ! gmail ! com
[Download RAW message or body]

Hello!

In runtime, sometimes I load classes, after apply an AST with compiler
customization.

withConfig(configuration) { ast(MyAst) }

I want to offer a way to test that classes in Spock or other test
frameworks. I was thinking in offer an static method or AST, like Grails
does:

mockWithMyAst(ClassToTest)

@MockMyAst(ClassToTest)
class MyTest extends Specification {
...

But, I don't know the best way to implement that. Changing test
classloader? Changing metaClass of target class? any way to capture
classloading in spock?.... Do you have any tip or suggestion to implement
it?

Thank you!

[Attachment #3 (text/html)]

<div dir="ltr"><font face="verdana, sans-serif">Hello!</font><div><font \
face="verdana, sans-serif"><br></font></div><div><font face="verdana, sans-serif">In \
runtime, sometimes I load classes, after apply an AST with compiler \
customization.</font></div><div><br></div><div><span \
style="color:rgb(0,0,0);font-size:12px;line-height:16.7999992370605px;white-space:pre-wrap;background-color:rgb(245,245,245)"><font \
face="courier new, monospace">withConfig(configuration) {  ast(MyAst)
}</font></span><br></div><div><span \
style="color:rgb(0,0,0);font-family:Monaco,&#39;Andale Mono&#39;,&#39;Courier \
New&#39;,monospace;font-size:12px;line-height:16.7999992370605px;white-space:pre-wrap;background-color:rgb(245,245,245)"><br></span></div><div><span \
style="color:rgb(0,0,0);font-family:Monaco,&#39;Andale Mono&#39;,&#39;Courier \
New&#39;,monospace;font-size:12px;line-height:16.7999992370605px;white-space:pre-wrap;background-color:rgb(245,245,245)">I \
want to offer a way to test that classes in Spock or other test frameworks. I was \
thinking in offer an static method or AST, like Grails does:</span></div><div><span \
style="color:rgb(0,0,0);font-family:Monaco,&#39;Andale Mono&#39;,&#39;Courier \
New&#39;,monospace;font-size:12px;line-height:16.7999992370605px;white-space:pre-wrap;background-color:rgb(245,245,245)"><br></span></div><div><span \
style="color:rgb(0,0,0);font-size:12px;line-height:16.7999992370605px;white-space:pre-wrap;background-color:rgb(245,245,245)"><font \
face="courier new, monospace">mockWithMyAst(ClassToTest)</font></span></div><div><span \
style="color:rgb(0,0,0);font-size:12px;line-height:16.7999992370605px;white-space:pre-wrap;background-color:rgb(245,245,245)"><font \
face="courier new, monospace"><br></font></span></div><div><span \
style="color:rgb(0,0,0);font-size:12px;line-height:16.7999992370605px;white-space:pre-wrap;background-color:rgb(245,245,245)"><font \
face="courier new, monospace">@MockMyAst(ClassToTest)</font></span></div><div><span \
style="color:rgb(0,0,0);font-size:12px;line-height:16.7999992370605px;white-space:pre-wrap;background-color:rgb(245,245,245)"><font \
face="courier new, monospace">class MyTest extends Specification \
{</font></span></div><div><span \
style="color:rgb(0,0,0);font-size:12px;line-height:16.7999992370605px;white-space:pre-wrap;background-color:rgb(245,245,245)"><font \
face="courier new, monospace">...</font></span></div><div><span \
style="color:rgb(0,0,0);font-family:Monaco,&#39;Andale Mono&#39;,&#39;Courier \
New&#39;,monospace;font-size:12px;line-height:16.7999992370605px;white-space:pre-wrap;background-color:rgb(245,245,245)"><br></span></div><div><span \
style="color:rgb(0,0,0);font-size:12px;line-height:16.7999992370605px;white-space:pre-wrap;background-color:rgb(245,245,245)"><font \
face="verdana, sans-serif">But, I don&#39;t know the best way to implement that. \
Changing test classloader? Changing metaClass of target class? any way to capture \
classloading in spock?.... Do you have any tip or suggestion to implement it? \
</font></span></div><div><span \
style="color:rgb(0,0,0);font-size:12px;line-height:16.7999992370605px;white-space:pre-wrap;background-color:rgb(245,245,245)"><font \
face="verdana, sans-serif"><br></font></span></div><div><span \
style="color:rgb(0,0,0);font-size:12px;line-height:16.7999992370605px;white-space:pre-wrap;background-color:rgb(245,245,245)"><font \
face="verdana, sans-serif">Thank you!</font></span></div></div>



[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic