Groovy AstTransformationSupport Test

Hi,

 

I'm writing a plugin to support a custom Groovy AST transformation.

The plugin itself is working as expected but I have problem writing up tests.

I set up a base class for my tests which adds the Groovy library: https://gist.github.com/felixscheinost/7636813a531df226851980e491166cb8

 

Just to test whether my setup works I copied a spec from the official Groovy plugin (from GrStubAstSwitchTest) where @Delegate is tested, which has similarities with custom annotation:

 

GroovyFileImpl file = myFixture.addFileToProject('a.groovy', '''\
class A {
def foo(){}
}
class B {
@Delegate
A a = new A()
}
''') as GroovyFileImpl

assert !file.contentsLoaded
PsiClass clazzB = file.classes[1]
assert !file.contentsLoaded

assert clazzB.methods.find { it.name == 'foo' }
assert !file.contentsLoaded

 

But not even that one passes. It seems like TransformationUtil#transformDefinition isn't called in time. Is there some way to trigger AstTransformationSupport and wait for it to finish?

Is someting with my setup wrong?

 

Thanks for your help!

Felix

3 comments
Comment actions Permalink

Hi, is your AstTransformationSupport registered in plugin.xml ?

0
Comment actions Permalink

Hi, yeah I think it is.

The plugin itself is working as expected when executing using runIde gradle task.

I just can't figure out how to test a AstTransformationSupport. What I find weird is that not even the built-in AstTransformationSupport like for @Delegat works in the test.

0
Comment actions Permalink

Do you mind sharing your project?

0

Please sign in to leave a comment.