Skip to content

Commit

Permalink
Update the Groovy plugin to 4.0.5
Browse files Browse the repository at this point in the history
for #1386
  • Loading branch information
eric-milles committed Sep 7, 2022
1 parent 08d9da0 commit 737150d
Show file tree
Hide file tree
Showing 50 changed files with 811 additions and 2,724 deletions.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -102,14 +102,13 @@ private IPath[] createSimpleProject(final String name, final boolean isGroovy) t

private void addJUnitAndSpock(final IPath projectPath) throws Exception {
String spockCorePath;
if (!isAtLeastGroovy(30)) {
spockCorePath = "lib/spock-core-2.1-groovy-2.5.jar";
env.addJar(projectPath, "lib/spock-groovy2-compat-2.1.jar");
if (isAtLeastGroovy(40)) {
spockCorePath = "lib/spock-core-2.2-groovy-4.0.jar";
} else if (isAtLeastGroovy(30)) {
spockCorePath = "lib/spock-core-2.2-groovy-3.0.jar";
} else {
spockCorePath = "lib/spock-core-2.1-groovy-3.0.jar";
if (isAtLeastGroovy(40)) {
System.setProperty("spock.iKnowWhatImDoing.disableGroovyVersionCheck", "true");
}
spockCorePath = "lib/spock-core-2.2-groovy-2.5.jar";
env.addJar(projectPath, "lib/spock-groovy2-compat-2.2.jar");
}
env.addJar(projectPath, spockCorePath);
env.addEntry(projectPath, JavaCore.newContainerEntry(new Path("org.eclipse.jdt.junit.JUNIT_CONTAINER/5")));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,13 @@ public final class SpockInferencingTests extends InferencingTestSuite {
@Before
public void setUp() throws Exception {
String spockCorePath;
if (isAtLeastGroovy(30)) {
spockCorePath = "lib/spock-core-2.1-groovy-3.0.jar";
if (isAtLeastGroovy(40)) {
spockCorePath = "lib/spock-core-2.2-groovy-4.0.jar";
} else if (isAtLeastGroovy(30)) {
spockCorePath = "lib/spock-core-2.2-groovy-3.0.jar";
} else {
spockCorePath = "lib/spock-core-2.1-groovy-2.5.jar";
env.addJar(project.getFullPath(), "lib/spock-groovy2-compat-2.1.jar");
spockCorePath = "lib/spock-core-2.2-groovy-2.5.jar";
env.addJar(project.getFullPath(), "lib/spock-groovy2-compat-2.2.jar");
}
env.addJar(project.getFullPath(), spockCorePath);
env.addEntry(project.getFullPath(), JavaCore.newContainerEntry(new Path("org.eclipse.jdt.junit.JUNIT_CONTAINER/5")));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ protected String[] getDefaultClassPaths() {
String[] cps = super.getDefaultClassPaths();
String[] newcps = Arrays.copyOf(cps, cps.length + 2);

String[] groovyVersions = {"4.0.4", "3.0.12-indy", "2.5.18-indy"};
String[] groovyVersions = {"4.0.5", "3.0.12-indy", "2.5.18-indy"};
String[] ivyVersions = {"2.5.0", "2.4.0"};
try {
URL groovyJar = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -700,6 +700,23 @@ public void testVariadicCategoryMethods() {
runConformTest(sources, "66436643");
}

@Test // GROOVY-10743
public void testInterfaceCategoryMethods() {
assumeTrue(isAtLeastJava(JDK9));

//@formatter:off
String[] sources = {
"Main.groovy",
"use (java.util.stream.Stream) {\n" +
" assert 16.iterate({it < 500}, {it * 2}).toList() == [16, 32, 64, 128, 256]\n" +
" assert [1, 1].iterate{f -> [f[1], f.sum()]}.limit(8).toList()*.head() == [1, 1, 2, 3, 5, 8, 13, 21]\n" +
"}\n",
};
//@formatter:on

runConformTest(sources);
}

@Test
public void testGreclipse719() {
//@formatter:off
Expand Down Expand Up @@ -6760,6 +6777,40 @@ public void testSuperDotPrivateMethod() {
}
}

@Test // GROOVY-10747
public void testSuperDotClone() {
//@formatter:off
String[] sources = {
"Main.groovy",
"class C implements Cloneable {\n" +
" C clone() {\n" +
" super.clone()\n" +
" }\n" +
"}\n" +
"def pogo = new C()\n" +
"def copy = pogo.clone()\n" +
"assert !copy.is( pogo )\n" +
"assert copy instanceof C\n",
};
//@formatter:on

runConformTest(sources);
}

@Test // GROOVY-10733
public void testArrayDotClone() {
//@formatter:off
String[] sources = {
"Main.groovy",
"int[] numbers = [1,2,3]\n" +
"assert numbers.clone() == [1,2,3]\n" +
"assert numbers.clone() instanceof int[]\n",
};
//@formatter:on

runConformTest(sources);
}

@Test
public void testPositions1() {
//@formatter:off
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1816,6 +1816,29 @@ public void testAnonymousInnerClass35() {
runConformTest(sources, "local then getter");
}

@Test // GROOVY-7370
public void testAnonymousInnerClass36() {
//@formatter:off
String[] sources = {
"Script.groovy",
"class C {\n" +
" public String[] strings\n" +
" C(String... args) {\n" +
" strings = args\n" +
" }\n" +
"}\n" +
"def c = new C() { }\n" +
"assert c.strings.length == 0\n" +
"c = new C('xy') { }\n" +
"assert c.strings.length == 1\n" +
"c = new C('x','y') { }\n" +
"assert c.strings.length == 2\n",
};
//@formatter:on

runConformTest(sources);
}

@Test
public void testMixedModeInnerProperties_GRE597() {
//@formatter:off
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1692,6 +1692,30 @@ public void testCompileStatic7490a() {
runConformTest(sources, "works");
}

@Test
public void testCompileStatic7506() {
//@formatter:off
String[] sources = {
"Main.groovy",
"class C {\n" +
" public String[] strings\n" +
" void setP(String[] strings) {\n" +
" this.strings = strings\n" +
" }\n" +
"}\n" +
"@groovy.transform.CompileStatic\n" +
"void test() {\n" +
" def c = new C()\n" +
" c.p = ['foo', 123 ]\n" +
" assert c.strings == ['foo','123']\n" +
"}\n" +
"test()\n",
};
//@formatter:on

runConformTest(sources);
}

@Test
public void testCompileStatic7526() {
//@formatter:off
Expand Down Expand Up @@ -2451,6 +2475,27 @@ public void testCompileStatic8051() {
runConformTest(sources, "1");
}

@Test
public void testCompileStatic8074() {
//@formatter:off
String[] sources = {
"Main.groovy",
"class M extends HashMap<String,Number> {\n" +
" def foo = 1\n" +
"}\n" +
"@groovy.transform.CompileStatic\n" +
"void test() {\n" +
" def map = new M()\n" +
" map.put('foo',42)\n" +
" print map.foo\n" +
"}\n" +
"test()\n",
};
//@formatter:on

runConformTest(sources, "42");
}

@Test
public void testCompileStatic8133() {
//@formatter:off
Expand Down Expand Up @@ -2975,6 +3020,31 @@ public void testCompileStatic8693() {
runConformTest(sources, "works");
}

@Test
public void testCompileStatic8737() {
//@formatter:off
String[] sources = {
"Main.groovy",
"String m(String key, Object[] args) {\n" +
" \"key=$key, args=$args\"\n" +
"}\n" +
"String m(String key, Object[] args, Object[] parts) {\n" +
" \"key=$key, args=$args, parts=$parts\"\n" +
"}\n" +
"String m(String key, Object[] args, String[] names) {\n" +
" \"key=$key, args=$args, names=$names\"\n" +
"}\n" +
"@groovy.transform.CompileStatic\n" +
"void test() {\n" +
" print m('hello', ['world'] as Object[])\n" + // exact match for m(String,Object[])
"}\n" +
"test()\n",
};
//@formatter:on

runConformTest(sources, "key=hello, args=[world]");
}

@Test
public void testCompileStatic8788() {
//@formatter:off
Expand Down Expand Up @@ -7544,4 +7614,103 @@ public void testCompileStatic10592a() {

runConformTest(sources, "worksworks");
}

@Test
public void testCompileStatic10712() {
//@formatter:off
String[] sources = {
"Main.groovy",
"@groovy.transform.CompileStatic\n" +
"void test() {\n" +
" final list = ['foo','bar']\n" +
" for (item in list.iterator()) print item.toUpperCase()\n" +
"}\n" +
"test()\n",
};
//@formatter:on

runConformTest(sources, "FOOBAR");
}

@Test
public void testCompileStatic10714() {
assumeTrue(isParrotParser());

//@formatter:off
String[] sources = {
"Main.groovy",
"import java.util.function.*\n" +
"class C {\n" +
" String which\n" +
" void m(int i) { which = 'int' }\n" +
" void m(Number n) { which = 'Number' }\n" +
"}\n" +
"interface I {\n" +
" I andThen(Consumer<? super Number> c)\n" +
" I andThen(BiConsumer<? super Number, ?> bc)\n" +
"}\n" +
"@groovy.transform.CompileStatic\n" +
"void test(I i, C c) {\n" +
" i = i.andThen(c::m)\n" + // "andThen" is ambiguous unless parameters of "m" overloads are taken into account
"}\n" +
"C x= new C()\n" +
"test(new I() {\n" +
" I andThen(Consumer<? super Number> c) {\n" +
" c.accept(42)\n" +
" return this\n" +
" }\n" +
" I andThen(BiConsumer<? super Number, ?> bc) {\n" +
" bc.accept(1234, null)\n" +
" return this\n" +
" }\n" +
"}, x)\n" +
"print x.which\n",
};
//@formatter:on

runConformTest(sources, "Number");
}

@Test
public void testCompileStatic10725() {
//@formatter:off
String[] sources = {
"Main.groovy",
"@groovy.transform.CompileStatic\n" +
"void test() {\n" +
" List<String> list = ['foo','bar']\n" +
" Set<Map<String,String>> set_of_maps = []\n" +
" set_of_maps.addAll(list.collectEntries { [it, it.toUpperCase()] })\n" +
" print set_of_maps.first()\n" +
"}\n" +
"test()\n",
};
//@formatter:on

runConformTest(sources, "[foo:FOO, bar:BAR]");
}

@Test
public void testCompileStatic10742() {
assumeTrue(isParrotParser());

//@formatter:off
String[] sources = {
"Main.groovy",
"void foo(bar) { }\n" +
"@groovy.transform.CompileStatic\n" +
"void test() {\n" +
" java.util.function.Function<?,String> f = this::foo\n" +
"}\n",
};
//@formatter:on

runNegativeTest(sources,
"----------\n" +
"1. ERROR in Main.groovy (at line 4)\n" +
"\tjava.util.function.Function<?,String> f = this::foo\n" +
"\t ^^^^^^^^^\n" +
"Groovy:Invalid return type: void is not convertible to java.lang.String\n" +
"----------\n");
}
}
Loading

0 comments on commit 737150d

Please sign in to comment.