You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@groovy.apache.org by pa...@apache.org on 2019/09/26 00:26:20 UTC

[groovy] 01/23: add some tests and clean up some tests

This is an automated email from the ASF dual-hosted git repository.

paulk pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/groovy.git

commit 5073dc0492afaaac88a7fad3896d246b3ecadf7e
Author: Eric Milles <er...@thomsonreuters.com>
AuthorDate: Thu Sep 12 17:10:14 2019 -0500

    add some tests and clean up some tests
---
 .../PackageAndImportAnnotationTest.groovy          | 19 ++++--
 .../{Groovy4418Bug.groovy => Groovy4418.groovy}    |  4 +-
 src/test/groovy/bugs/Groovy8063.groovy             | 64 ++++++++++++++++++
 src/test/groovy/bugs/Groovy9204.groovy             | 78 ++++++++++++++++++++++
 src/test/groovy/bugs/Groovy9213.groovy             | 53 +++++++++++++++
 .../{Groovy9243Bug.groovy => Groovy9243.groovy}    | 17 +++--
 .../{Groovy7276Bug.groovy => Groovy7276.groovy}    |  2 +-
 7 files changed, 224 insertions(+), 13 deletions(-)

diff --git a/src/test/groovy/annotations/PackageAndImportAnnotationTest.groovy b/src/test/groovy/annotations/PackageAndImportAnnotationTest.groovy
index 304ef79..cfeac15 100644
--- a/src/test/groovy/annotations/PackageAndImportAnnotationTest.groovy
+++ b/src/test/groovy/annotations/PackageAndImportAnnotationTest.groovy
@@ -18,23 +18,32 @@
  */
 package groovy.annotations
 
-class PackageAndImportAnnotationTest extends GroovyTestCase {
+import groovy.transform.CompileStatic
+import org.junit.Test
+
+import static groovy.test.GroovyAssert.assertScript
+
+@CompileStatic
+final class PackageAndImportAnnotationTest {
+
+    @Test
     void testTransformationOfPropertyInvokedOnThis() {
-        assertScript """
+        assertScript '''
             def x = new groovy.annotations.MyClass()
             assert x.class.annotations[0].value() == 60
             assert x.class.package.annotations[0].value() == 30
             new AntBuilder().with {
                 mkdir(dir:'temp')
                 delete(file:'temp/log.txt')
-                taskdef(name:'groovyc', classname:"org.codehaus.groovy.ant.Groovyc")
+                taskdef(name:'groovyc', classname:'org.codehaus.groovy.ant.Groovyc')
                 groovyc(srcdir:'src/test', destdir:'temp', includes:'groovy/annotations/MyClass.groovy')
                 def text = new File('temp/log.txt').text
+                delete(dir:'temp')
+
                 assert text.contains('ClassNode 60')
                 assert text.contains('PackageNode 40')
                 assert text.contains('ImportNode 50')
-                delete(dir:'temp')
             }
-        """
+        '''
     }
 }
diff --git a/src/test/groovy/bugs/Groovy4418Bug.groovy b/src/test/groovy/bugs/Groovy4418.groovy
similarity index 98%
rename from src/test/groovy/bugs/Groovy4418Bug.groovy
rename to src/test/groovy/bugs/Groovy4418.groovy
index f96537d..8a7239b 100644
--- a/src/test/groovy/bugs/Groovy4418Bug.groovy
+++ b/src/test/groovy/bugs/Groovy4418.groovy
@@ -18,12 +18,14 @@
  */
 package groovy.bugs
 
+import groovy.transform.CompileStatic
 import org.junit.Test
 
 import static groovy.test.GroovyAssert.assertScript
 import static groovy.test.GroovyAssert.shouldFail
 
-final class Groovy4418Bug {
+@CompileStatic
+final class Groovy4418 {
 
     @Test
     void testStaticFieldAccess() {
diff --git a/src/test/groovy/bugs/Groovy8063.groovy b/src/test/groovy/bugs/Groovy8063.groovy
new file mode 100644
index 0000000..2644329
--- /dev/null
+++ b/src/test/groovy/bugs/Groovy8063.groovy
@@ -0,0 +1,64 @@
+/*
+ *  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 groovy.transform.CompileStatic
+import org.junit.Ignore
+import org.junit.Test
+
+import static groovy.test.GroovyAssert.assertScript
+import static groovy.test.GroovyAssert.shouldFail
+
+@CompileStatic
+final class Groovy8063 {
+
+    @Test
+    void testTypeAnnotationWithQualifiedInnerClassReference() {
+        assertScript '''
+            @interface Anno {
+                Class value()
+            }
+
+            @Anno(value=Outer.Inner)
+            class Outer {
+                static class Inner {}
+            }
+
+            new Outer()
+        '''
+    }
+
+    @Test @Ignore
+    void testTypeAnnotationWithUnqualifiedInnerClassReference() {
+        def err = shouldFail '''
+            @interface Anno {
+                Class value()
+            }
+
+            @Anno(value=Inner) // type annotation is outside the class scope
+            class Outer {
+                static class Inner {}
+            }
+
+            new Outer()
+        '''
+
+        assert err =~ / X /
+    }
+}
diff --git a/src/test/groovy/bugs/Groovy9204.groovy b/src/test/groovy/bugs/Groovy9204.groovy
new file mode 100644
index 0000000..d6fc95f
--- /dev/null
+++ b/src/test/groovy/bugs/Groovy9204.groovy
@@ -0,0 +1,78 @@
+/*
+ *  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 groovy.test.NotYetImplemented
+import org.codehaus.groovy.control.CompilerConfiguration
+import org.codehaus.groovy.tools.javac.JavaAwareCompilationUnit
+import org.junit.Test
+
+final class Groovy9204 {
+
+    @Test @NotYetImplemented
+    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 '''
+                public class A {
+                    public String meth() {
+                        return "hello";
+                    }
+                }
+
+                abstract class One<T extends A> {
+                    protected T field;
+                }
+
+                abstract class Two<T extends A> extends One<T> {
+                }
+
+                abstract class Three extends Two<A> {
+                }
+            '''
+            def b = new File(parentDir, 'B.groovy')
+            b.write '''
+                @groovy.transform.CompileStatic
+                class B extends Three {
+                    def test() {
+                        field.meth() // typeof(field) should be A
+                        //    ^^^^ Cannot find matching method java.lang.Object#meth()
+                    }
+                }
+            '''
+
+            def loader = new GroovyClassLoader(this.class.classLoader)
+            def cu = new JavaAwareCompilationUnit(config, loader)
+            cu.addSources(a, b)
+            cu.compile()
+
+            Class clazz = loader.loadClass('B')
+            assert clazz.newInstance().test() == 'hello'
+        } finally {
+            parentDir.deleteDir()
+            config.targetDirectory.deleteDir()
+        }
+    }
+}
diff --git a/src/test/groovy/bugs/Groovy9213.groovy b/src/test/groovy/bugs/Groovy9213.groovy
new file mode 100644
index 0000000..2e8980c
--- /dev/null
+++ b/src/test/groovy/bugs/Groovy9213.groovy
@@ -0,0 +1,53 @@
+/*
+ *  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 groovy.transform.CompileStatic
+import org.codehaus.groovy.control.CompilerConfiguration
+import org.junit.Ignore
+import org.junit.Test
+
+import static org.codehaus.groovy.control.ParserPluginFactory.antlr2
+import static org.codehaus.groovy.control.ParserPluginFactory.antlr4
+
+@CompileStatic @Ignore
+final class Groovy9213 {
+
+    @Test(timeout=15000L)
+    void testUnmatchedParenInLongScript2() {
+        def config = new CompilerConfiguration()
+        config.pluginFactory = antlr2()
+
+        new GroovyShell(config).evaluate('''
+            int a = 0
+            (
+        ''' + ('a = 0\n' * 50))
+    }
+
+    @Test(timeout=15000L)
+    void testUnmatchedParenInLongScript4() {
+        def config = new CompilerConfiguration()
+        config.pluginFactory = antlr4(config)
+
+        new GroovyShell(config).evaluate('''
+            int a = 0
+            (
+        ''' + ('a = 0\n' * 50))
+    }
+}
diff --git a/src/test/groovy/bugs/Groovy9243Bug.groovy b/src/test/groovy/bugs/Groovy9243.groovy
similarity index 73%
rename from src/test/groovy/bugs/Groovy9243Bug.groovy
rename to src/test/groovy/bugs/Groovy9243.groovy
index e0fb10b..c03e211 100644
--- a/src/test/groovy/bugs/Groovy9243Bug.groovy
+++ b/src/test/groovy/bugs/Groovy9243.groovy
@@ -18,15 +18,20 @@
  */
 package groovy.bugs
 
+import groovy.transform.CompileStatic
 import org.codehaus.groovy.tools.GroovyStarter
+import org.junit.Test
 
-class Groovy9243Bug extends GroovyTestCase {
-    void testResolveNestedClassFromBaseType() {
-        def mainScriptPath = new File(this.getClass().getResource('/groovy/bugs/groovy9243/Main.groovy').toURI()).absolutePath
-        runScript(mainScriptPath)
+@CompileStatic
+final class Groovy9243 {
+
+    private static void runScript(String path) {
+        GroovyStarter.main('--main', 'groovy.ui.GroovyMain', path)
     }
 
-    static void runScript(String path) {
-        GroovyStarter.main(new String[] { "--main", "groovy.ui.GroovyMain", path })
+    @Test
+    void testResolveNestedClassFromBaseType() {
+        def mainScriptPath = new File(getClass().getResource('/groovy/bugs/groovy9243/Main.groovy').toURI()).absolutePath
+        runScript(mainScriptPath)
     }
 }
diff --git a/src/test/org/codehaus/groovy/classgen/asm/sc/bugs/Groovy7276Bug.groovy b/src/test/org/codehaus/groovy/classgen/asm/sc/bugs/Groovy7276.groovy
similarity index 96%
rename from src/test/org/codehaus/groovy/classgen/asm/sc/bugs/Groovy7276Bug.groovy
rename to src/test/org/codehaus/groovy/classgen/asm/sc/bugs/Groovy7276.groovy
index 69bcdf1..97d8529 100644
--- a/src/test/org/codehaus/groovy/classgen/asm/sc/bugs/Groovy7276Bug.groovy
+++ b/src/test/org/codehaus/groovy/classgen/asm/sc/bugs/Groovy7276.groovy
@@ -22,7 +22,7 @@ import groovy.test.NotYetImplemented
 import groovy.transform.stc.StaticTypeCheckingTestCase
 import org.codehaus.groovy.classgen.asm.sc.StaticCompilationTestSupport
 
-final class Groovy7276Bug extends StaticTypeCheckingTestCase implements StaticCompilationTestSupport {
+final class Groovy7276 extends StaticTypeCheckingTestCase implements StaticCompilationTestSupport {
 
     void testShouldGoThroughPrivateBridgeAccessor() {
         assertScript '''