How did I do this? I did it by hooking into existing JDT functionality, just like I have been doing for the rest of my work on Greclipse. I downloaded the JDT core tests from CVS and used what I needed. Now, I can write extremely concise tests that exercise the code I want it to. For example, I wrote the following test case that tests code selection on a closure in a groovy script (i.e., this is the code that is executed when you perform Open Declaration in an editor):
public void testCodeSelectClosure() throws Exception {
IPath projectPath = createGenericProject();
IPath root = projectPath.append("src");
String contents =
"def x = {\n"+
"t -> print t\n"+
"}\n"+
"x('hello')\n";
env.addGroovyClass(root, "Script", contents);
GroovyCompilationUnit unit = getGroovyCompilationUnit(root, "Script.groovy");
IJavaElement[] elts = unit.codeSelect(contents.lastIndexOf('x'), 1);
assertEquals("Should have found a selection", 1, elts.length);
assertEquals("Should have found local variable 'x'", "x", elts[0].getElementName());
}
I have written many tests for JUnit support (or is that GUnit?), and some for code selection. I still need to work on content assist. So, I can now be confident that as we make changes towards the 2.0 release, we are not sliding back in functionality. There is a lot of good work that has already been put into the plugin (including groovy-aware type inference for content assist) and we need to make sure that this does not regress as we go forward.
Nice going!
ReplyDeleteGUnit? How about ClassUnit or is it CUUnit (Compilation Unit Unit ! ;), perhaps even Bytecode Unit.
I'm looking forward to seeing your first unit test (prob 3.8-style) that is written in Groovy.
It's funny seeing what's coming out of Spring Source recently... it's almost as though someone finally said "There should be an Eclipse-based direct competitor for IDEA"... and about time too