You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@groovy.apache.org by em...@apache.org on 2021/12/15 15:04:32 UTC

[groovy] branch master updated: add test cases

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

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


The following commit(s) were added to refs/heads/master by this push:
     new a5a75c1  add test cases
a5a75c1 is described below

commit a5a75c14a450fde7f8cd79a6dd9c9b24d0d7a1a9
Author: Eric Milles <er...@thomsonreuters.com>
AuthorDate: Wed Dec 15 09:04:24 2021 -0600

    add test cases
---
 .../groovy/bugs/groovyA144/Main.groovy             |  22 +++
 src/test-resources/groovy/bugs/groovyA144/T.groovy |  25 ++++
 src/test-resources/groovy/bugs/groovyA144/X.groovy |  26 ++++
 src/test/groovy/script/RuntimeResolveTests.groovy  |   7 +-
 .../traitx/TraitASTTransformationTest.groovy       | 164 +++++++++++++--------
 5 files changed, 181 insertions(+), 63 deletions(-)

diff --git a/src/test-resources/groovy/bugs/groovyA144/Main.groovy b/src/test-resources/groovy/bugs/groovyA144/Main.groovy
new file mode 100644
index 0000000..876e265
--- /dev/null
+++ b/src/test-resources/groovy/bugs/groovyA144/Main.groovy
@@ -0,0 +1,22 @@
+/*
+ *  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.groovyA144
+
+String result = new X().m()
+assert result == 'XT'
diff --git a/src/test-resources/groovy/bugs/groovyA144/T.groovy b/src/test-resources/groovy/bugs/groovyA144/T.groovy
new file mode 100644
index 0000000..14d738b
--- /dev/null
+++ b/src/test-resources/groovy/bugs/groovyA144/T.groovy
@@ -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.groovyA144
+
+trait T {
+    def m() {
+        return 'T'
+    }
+}
diff --git a/src/test-resources/groovy/bugs/groovyA144/X.groovy b/src/test-resources/groovy/bugs/groovyA144/X.groovy
new file mode 100644
index 0000000..3722ffe
--- /dev/null
+++ b/src/test-resources/groovy/bugs/groovyA144/X.groovy
@@ -0,0 +1,26 @@
+/*
+ *  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.groovyA144
+
+class X implements T {
+    @Override
+    def m() {
+        return 'X' + T.super.m()
+    }
+}
diff --git a/src/test/groovy/script/RuntimeResolveTests.groovy b/src/test/groovy/script/RuntimeResolveTests.groovy
index 922bdbf..c8e6303 100644
--- a/src/test/groovy/script/RuntimeResolveTests.groovy
+++ b/src/test/groovy/script/RuntimeResolveTests.groovy
@@ -57,7 +57,7 @@ final class RuntimeResolveTests {
     }
 
     @Test @Ignore('exception in script causes problem for build')
-    void testUnexistingInnerClass() {
+    void testUnresolvableInnerClass() {
         try {
             runScript('/groovy/bugs/groovy7812/MainWithErrors.groovy')
         } catch (Throwable t) {
@@ -74,4 +74,9 @@ final class RuntimeResolveTests {
     void testResolveNestedClassFromBaseType() {
         runScript('/groovy/bugs/groovy9243/Main.groovy')
     }
+
+    @Test
+    void testTraitSuperFromOverriddenMethod() {
+        runScript('/groovy/bugs/groovyA144/Main.groovy')
+    }
 }
diff --git a/src/test/org/codehaus/groovy/transform/traitx/TraitASTTransformationTest.groovy b/src/test/org/codehaus/groovy/transform/traitx/TraitASTTransformationTest.groovy
index 332221c..b49bb91 100644
--- a/src/test/org/codehaus/groovy/transform/traitx/TraitASTTransformationTest.groovy
+++ b/src/test/org/codehaus/groovy/transform/traitx/TraitASTTransformationTest.groovy
@@ -420,65 +420,63 @@ final class TraitASTTransformationTest {
 
     @Test
     void testClassImplementingTraitWithSameMethod() {
-        10.times {
-            assertScript '''
-                trait A {
-                    int foo() { 1 }
-                }
-                trait B {
-                    int foo() { 2 }
-                }
-                class AB implements A,B {
-                }
-                def x = new AB()
-                assert x.foo() == 2 // default order, B is first
-            '''
+        assertScript '''
+            trait A {
+                int foo() { 1 }
+            }
+            trait B {
+                int foo() { 2 }
+            }
+            class AB implements A,B {
+            }
+            def x = new AB()
+            assert x.foo() == 2 // default order, B is first
+        '''
 
-            assertScript '''
-                trait A {
-                    int foo() { 1 }
-                }
-                trait B {
-                    int foo() { 2 }
-                }
-                class AB implements B,A {
-                }
-                def x = new AB()
-                assert x.foo() == 1 // default order, A is first
-            '''
+        assertScript '''
+            trait A {
+                int foo() { 1 }
+            }
+            trait B {
+                int foo() { 2 }
+            }
+            class AB implements B,A {
+            }
+            def x = new AB()
+            assert x.foo() == 1 // default order, A is first
+        '''
 
-            assertScript '''
-                trait A {
-                    int foo() { 1 }
-                }
-                trait B {
-                    int foo() { 2 }
-                }
-                class AB implements A,B {
-                    int foo() {
-                        A.super.foo() // explicit use of A
-                    }
+        assertScript '''
+            trait A {
+                int foo() { 1 }
+            }
+            trait B {
+                int foo() { 2 }
+            }
+            class AB implements A,B {
+                int foo() {
+                    A.super.foo() // explicit use of A
                 }
-                def x = new AB()
-                assert x.foo() == 1
-            '''
+            }
+            def x = new AB()
+            assert x.foo() == 1
+        '''
 
-            assertScript '''
-                trait A {
-                    int foo() { 1 }
-                }
-                trait B {
-                    int foo() { 2 }
-                }
-                class AB implements A,B {
-                    int foo() {
-                        A.super.foo()  // explicit take of A
-                    }
+        assertScript '''
+            trait A {
+                int foo() { 1 }
+            }
+            trait B {
+                int foo() { 2 }
+            }
+            class AB implements A,B {
+                int foo() {
+                    A.super.foo()  // explicit take of A
                 }
-                def x = new AB()
-                assert x.foo() == 1
-            '''
-        }
+            }
+            def x = new AB()
+            assert x.foo() == 1
+        '''
 
         // make sure it is compatible with @CompileStatic
         assertScript '''
@@ -497,6 +495,21 @@ final class TraitASTTransformationTest {
             def x = new AB()
             assert x.foo() == 2
         '''
+
+        // GROOVY-10144
+        assertScript '''
+            trait T {
+                def m() { 'T' }
+            }
+            class C implements T {
+                @Override
+                def m() {
+                    'C' + T.super.m()
+                }
+            }
+            String result = new C().m()
+            assert result == 'CT'
+        '''
     }
 
     @Test
@@ -1845,7 +1858,7 @@ final class TraitASTTransformationTest {
     }
 
     @Test
-    void testStaticMethodInTrait() {
+    void testTraitStaticMethod() {
         assertScript '''
             trait StaticProvider {
                 static String foo() { 'static method' }
@@ -1865,7 +1878,7 @@ final class TraitASTTransformationTest {
     }
 
     @Test
-    void testStaticFieldInTrait() {
+    void testTraitStaticField() {
         assertScript '''
             trait StaticFieldProvider {
                 public static int VAL = 123
@@ -1873,10 +1886,7 @@ final class TraitASTTransformationTest {
             class Foo implements StaticFieldProvider {}
             assert Foo.StaticFieldProvider__VAL == 123
         '''
-    }
 
-    @Test
-    void testStaticFieldModifiedInTrait() {
         assertScript '''
             trait StaticFieldProvider {
                 public static int VAL = 123
@@ -1890,17 +1900,47 @@ final class TraitASTTransformationTest {
     }
 
     @Test
-    void testStaticPropertyModifiedInTrait() {
+    void testTraitStaticProperty() {
         assertScript '''
-            trait StaticFieldProvider {
+            trait StaticPropertyProvider {
                 static int VAL = 123
                 public static void update(int x) { VAL = x }
             }
-            class Foo implements StaticFieldProvider {}
+            class Foo implements StaticPropertyProvider {
+            }
             assert Foo.VAL == 123
             Foo.update(456)
             assert Foo.VAL == 456
         '''
+
+        assertScript '''
+            trait T {
+                static p = 1
+            }
+            class C implements T {
+                static m() {
+                    setP(2)
+                    setP(getP() + 1)
+                    return getP()
+                }
+            }
+            assert C.m() == 3
+        '''
+
+        // GROOVY-9678
+        assertScript '''
+            trait T {
+                static p = 1
+            }
+            class C implements T {
+                static m() {
+                    p = 2
+                    p += 1
+                    return p
+                }
+            }
+            assert C.m() == 3
+        '''
     }
 
     @Test