You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@groovy.apache.org by su...@apache.org on 2020/02/02 16:04:56 UTC
[groovy] branch GROOVY_3_0_X updated: Refine test for GROOVY-9204
This is an automated email from the ASF dual-hosted git repository.
sunlan pushed a commit to branch GROOVY_3_0_X
in repository https://gitbox.apache.org/repos/asf/groovy.git
The following commit(s) were added to refs/heads/GROOVY_3_0_X by this push:
new 17114bb Refine test for GROOVY-9204
17114bb is described below
commit 17114bb75fb8df3b2c6b6e86b06c5989e4f21b4d
Author: Bo Zhang <zh...@gmail.com>
AuthorDate: Sun Feb 2 13:20:08 2020 +0800
Refine test for GROOVY-9204
Use isolated test java classes instead.
(cherry picked from commit 29f43f165f002299e3e7e2f8e8daff003dbb3403)
---
src/test/groovy/bugs/Groovy9204.groovy | 85 -----------------------
src/test/groovy/bugs/groovy9204/Four.java | 24 +++++++
src/test/groovy/bugs/groovy9204/Groovy9204.groovy | 49 +++++++++++++
src/test/groovy/bugs/groovy9204/One.java | 25 +++++++
src/test/groovy/bugs/groovy9204/Three.java | 24 +++++++
src/test/groovy/bugs/groovy9204/Two.java | 24 +++++++
6 files changed, 146 insertions(+), 85 deletions(-)
diff --git a/src/test/groovy/bugs/Groovy9204.groovy b/src/test/groovy/bugs/Groovy9204.groovy
deleted file mode 100644
index abc64e3..0000000
--- a/src/test/groovy/bugs/Groovy9204.groovy
+++ /dev/null
@@ -1,85 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package groovy.bugs
-
-import org.codehaus.groovy.control.CompilerConfiguration
-import org.codehaus.groovy.tools.javac.JavaAwareCompilationUnit
-import org.junit.Test
-
-final class Groovy9204 {
-
- @Test
- void testGenerics() {
- def config = new CompilerConfiguration(
- targetDirectory: File.createTempDir(),
- jointCompilationOptions: [memStub: true]
- )
-
- def parentDir = File.createTempDir()
- try {
- def a = new File(parentDir, 'A.java')
- a.write '''
- class One<T extends java.util.List> {
- protected T field;
- }
-
- class Two<T extends java.util.List> extends One<T> {
- }
-
- class Three extends Two<java.util.List> {
- }
-
- class Four extends Two<java.util.LinkedList> {
- }
-
- '''
- def b = new File(parentDir, 'B.groovy')
- b.write '''
- @groovy.transform.CompileStatic
- class ArrayListTest extends Three {
- def test() {
- field = new ArrayList()
- field.add("hello")
- field[0]
- }
- }
-
- @groovy.transform.CompileStatic
- class LinkedListTest extends Four {
- def test() {
- field = new LinkedList()
- field.addFirst("hello")
- field[0]
- }
- }
- '''
-
- def loader = new GroovyClassLoader(this.class.classLoader)
- def cu = new JavaAwareCompilationUnit(config, loader)
- cu.addSources(a, b)
- cu.compile()
-
- assert loader.loadClass('LinkedListTest').getConstructor().newInstance().test() == 'hello'
- assert loader.loadClass('ArrayListTest').getConstructor().newInstance().test() == 'hello'
- } finally {
- parentDir.deleteDir()
- config.targetDirectory.deleteDir()
- }
- }
-}
diff --git a/src/test/groovy/bugs/groovy9204/Four.java b/src/test/groovy/bugs/groovy9204/Four.java
new file mode 100644
index 0000000..58cd797
--- /dev/null
+++ b/src/test/groovy/bugs/groovy9204/Four.java
@@ -0,0 +1,24 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package groovy.bugs.groovy9204;
+
+import java.util.LinkedList;
+
+public class Four extends Two<LinkedList> {
+}
diff --git a/src/test/groovy/bugs/groovy9204/Groovy9204.groovy b/src/test/groovy/bugs/groovy9204/Groovy9204.groovy
new file mode 100644
index 0000000..7c689ef
--- /dev/null
+++ b/src/test/groovy/bugs/groovy9204/Groovy9204.groovy
@@ -0,0 +1,49 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package groovy.bugs.groovy9204
+
+import groovy.test.GroovyTestCase
+
+class Groovy9204 extends GroovyTestCase {
+ void testGenerics() {
+ assertScript '''
+ package groovy.bugs.groovy9204
+ @groovy.transform.CompileStatic
+ class ArrayListTest extends Three {
+ def test() {
+ field = new ArrayList()
+ field.add("hello")
+ field[0]
+ }
+ }
+
+ @groovy.transform.CompileStatic
+ class LinkedListTest extends Four {
+ def test() {
+ field = new LinkedList()
+ field.addFirst("hello")
+ field[0]
+ }
+ }
+
+ assert new ArrayListTest().test() == 'hello'
+ assert new LinkedListTest().test() == 'hello'
+ '''
+ }
+}
diff --git a/src/test/groovy/bugs/groovy9204/One.java b/src/test/groovy/bugs/groovy9204/One.java
new file mode 100644
index 0000000..d079490
--- /dev/null
+++ b/src/test/groovy/bugs/groovy9204/One.java
@@ -0,0 +1,25 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package groovy.bugs.groovy9204;
+
+import java.util.List;
+
+public class One<T extends List> {
+ protected T field;
+}
diff --git a/src/test/groovy/bugs/groovy9204/Three.java b/src/test/groovy/bugs/groovy9204/Three.java
new file mode 100644
index 0000000..640afcd
--- /dev/null
+++ b/src/test/groovy/bugs/groovy9204/Three.java
@@ -0,0 +1,24 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package groovy.bugs.groovy9204;
+
+import java.util.List;
+
+public class Three extends Two<List> {
+}
\ No newline at end of file
diff --git a/src/test/groovy/bugs/groovy9204/Two.java b/src/test/groovy/bugs/groovy9204/Two.java
new file mode 100644
index 0000000..c4b0142
--- /dev/null
+++ b/src/test/groovy/bugs/groovy9204/Two.java
@@ -0,0 +1,24 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package groovy.bugs.groovy9204;
+
+import java.util.List;
+
+public class Two<T extends List> extends One<T> {
+}