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 2019/11/09 16:15:01 UTC

[groovy] branch master updated (9e95211 -> a219aca)

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

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


    from 9e95211  Remove outdated javadoc hotfix (#1074)
     new 11fb3f9  JUnit 4
     new a219aca  minor edits for readability

The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 .../codehaus/groovy/ast/tools/GenericsUtils.java   | 21 ++---
 src/test/groovy/grape/GrabResolverTest.groovy      | 93 ++++++++++++----------
 2 files changed, 65 insertions(+), 49 deletions(-)


[groovy] 02/02: minor edits for readability

Posted by em...@apache.org.
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

commit a219aca034911057aa44c2644acac171b540a327
Author: Eric Milles <er...@thomsonreuters.com>
AuthorDate: Sat Nov 9 10:14:50 2019 -0600

    minor edits for readability
---
 .../codehaus/groovy/ast/tools/GenericsUtils.java    | 21 ++++++++++++---------
 1 file changed, 12 insertions(+), 9 deletions(-)

diff --git a/src/main/java/org/codehaus/groovy/ast/tools/GenericsUtils.java b/src/main/java/org/codehaus/groovy/ast/tools/GenericsUtils.java
index 0644ed9..0ff33de 100644
--- a/src/main/java/org/codehaus/groovy/ast/tools/GenericsUtils.java
+++ b/src/main/java/org/codehaus/groovy/ast/tools/GenericsUtils.java
@@ -370,28 +370,31 @@ public class GenericsUtils {
             newgTypes = new GenericsType[oldgTypes.length];
             for (int i = 0; i < newgTypes.length; i++) {
                 GenericsType oldgType = oldgTypes[i];
-                if (oldgType.isPlaceholder()) {
-                    if (genericsSpec.get(oldgType.getName()) != null) {
-                        newgTypes[i] = new GenericsType(genericsSpec.get(oldgType.getName()));
-                    } else {
-                        newgTypes[i] = new GenericsType(ClassHelper.OBJECT_TYPE);
-                    }
-                } else if (oldgType.isWildcard()) {
-                    ClassNode oldLower = oldgType.getLowerBound();
-                    ClassNode lower = oldLower != null ? correctToGenericsSpecRecurse(genericsSpec, oldLower, exclusions) : null;
+                if (oldgType.isWildcard()) {
                     ClassNode[] oldUpper = oldgType.getUpperBounds();
                     ClassNode[] upper = null;
                     if (oldUpper != null) {
+                        // correct "? extends T" or "? extends T & I"
                         upper = new ClassNode[oldUpper.length];
                         for (int j = 0; j < oldUpper.length; j++) {
                             upper[j] = correctToGenericsSpecRecurse(genericsSpec, oldUpper[j], exclusions);
                         }
                     }
+                    ClassNode oldLower = oldgType.getLowerBound();
+                    ClassNode lower = null;
+                    if (oldLower != null) {
+                        // correct "? super T"
+                        lower = correctToGenericsSpecRecurse(genericsSpec, oldLower, exclusions);
+                    }
                     GenericsType fixed = new GenericsType(oldgType.getType(), upper, lower);
                     fixed.setName(oldgType.getName());
                     fixed.setWildcard(true);
                     newgTypes[i] = fixed;
+                } else if (oldgType.isPlaceholder()) {
+                    // correct "T"
+                    newgTypes[i] = new GenericsType(genericsSpec.getOrDefault(oldgType.getName(), ClassHelper.OBJECT_TYPE));
                 } else {
+                    // correct "List<T>", etc.
                     newgTypes[i] = new GenericsType(correctToGenericsSpecRecurse(genericsSpec, correctToGenericsSpec(genericsSpec, oldgType), exclusions));
                 }
             }


[groovy] 01/02: JUnit 4

Posted by em...@apache.org.
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

commit 11fb3f97c2582e2db87320495a7682cc6bfe818c
Author: Eric Milles <er...@thomsonreuters.com>
AuthorDate: Sat Nov 9 10:13:57 2019 -0600

    JUnit 4
---
 src/test/groovy/grape/GrabResolverTest.groovy | 93 +++++++++++++++------------
 1 file changed, 53 insertions(+), 40 deletions(-)

diff --git a/src/test/groovy/grape/GrabResolverTest.groovy b/src/test/groovy/grape/GrabResolverTest.groovy
index 369f10b..f7e4429 100644
--- a/src/test/groovy/grape/GrabResolverTest.groovy
+++ b/src/test/groovy/grape/GrabResolverTest.groovy
@@ -18,82 +18,95 @@
  */
 package groovy.grape
 
-import groovy.test.GroovyTestCase
+import groovy.transform.CompileStatic
 import org.codehaus.groovy.control.CompilationFailedException
+import org.junit.AfterClass
+import org.junit.Before
+import org.junit.BeforeClass
+import org.junit.Ignore
+import org.junit.Test
 
-class GrabResolverTest extends GroovyTestCase {
-    def originalGrapeRoot
-    def grapeRoot
+import static groovy.test.GroovyAssert.assertScript
+import static groovy.test.GroovyAssert.shouldFail
 
+@CompileStatic
+final class GrabResolverTest {
+
+    private static String originalGrapeRoot
+
+    @BeforeClass
+    static void setUpTestSuite() {
+        originalGrapeRoot = System.getProperty('grape.root')
+    }
+
+    @Before
     void setUp() {
-        Grape.@instance = null // isolate our test from other tests
+        Grape.@instance = null // isolate each test
 
-        // create a new grape root directory so as to insure a clean slate for this test
-        originalGrapeRoot = System.getProperty("grape.root")
-        grapeRoot = new File(System.getProperty("java.io.tmpdir"), "GrabResolverTest${System.currentTimeMillis()}")
+        // create a new grape root directory so as to insure a clean slate for each test
+        def grapeRoot = new File(System.getProperty('java.io.tmpdir'), "GrabResolverTest${System.currentTimeMillis()}")
+        System.setProperty('grape.root', grapeRoot.path)
         assert grapeRoot.mkdir()
         grapeRoot.deleteOnExit()
-        System.setProperty("grape.root", grapeRoot.path)
     }
 
-    void tearDown() {
+    @AfterClass
+    static void tearDownTestSuite() {
         if (originalGrapeRoot == null) {
-            // SDN bug: 4463345
-            System.getProperties().remove("grape.root")
+            System.clearProperty('grape.root')
         } else {
-            System.setProperty("grape.root", originalGrapeRoot)
+            System.setProperty('grape.root', originalGrapeRoot)
         }
 
-        Grape.@instance = null // isolate our test from other tests
+        Grape.@instance = null // isolate these tests from other tests
     }
 
-    void manualTestChecksumsCanBeDisabled() {
+    @Test @Ignore('manual')
+    void testChecksumsCanBeDisabled() {
         // TODO someone has cleaned up the checksum info in the public repos that this test
         // was relying on and so this test no longer fails unless you have the corrupt SHA1
         // value cached in your local grapes repo, change test to not rely on that fact and
         // then reinstate (use a local file repo?)
-        GroovyShell shell = new GroovyShell(new GroovyClassLoader())
-        shouldFail(RuntimeException) {
-            shell.evaluate """
+        shouldFail RuntimeException, '''
             @Grab('org.mvel:mvel2:2.1.3.Final')
             import org.mvel2.MVEL
             assert MVEL.name == 'org.mvel2.MVEL'
-            """
-        }
-        shell.evaluate """
-        @Grab('org.mvel:mvel2:2.1.3.Final')
-        @GrabConfig(disableChecksums=true)
-        import org.mvel2.MVEL
-        assert MVEL.name == 'org.mvel2.MVEL'
-        """
+        '''
+        assertScript '''
+            @Grab('org.mvel:mvel2:2.1.3.Final')
+            @GrabConfig(disableChecksums=true)
+            import org.mvel2.MVEL
+            assert MVEL.name == 'org.mvel2.MVEL'
+        '''
     }
 
+    @Test // NOTE: 'org.restlet:org.restlet:1.1.6' must not be in local m2 repository for this test to pass
     void testResolverDefinitionIsRequired() {
-        GroovyShell shell = new GroovyShell(new GroovyClassLoader())
-        shouldFail(CompilationFailedException) {
-            shell.evaluate("""
-                @Grab(group='org.restlet', module='org.restlet', version='1.1.6')
-                class AnnotationHost {}
-                import org.restlet.Application
-            """)
-        }
+        shouldFail CompilationFailedException, '''
+            @Grab(group='org.restlet', module='org.restlet', version='1.1.6')
+            import org.restlet.Application
+            class AnnotationHost {}
+            println 'hello world'
+        '''
     }
 
+    @Test
     void testResolverDefinitionResolvesDependency() {
-        GroovyShell shell = new GroovyShell(new GroovyClassLoader())
-        shell.evaluate("""
+        assertScript '''
             @GrabResolver(name='restlet.org', root='http://maven.restlet.org')
             @Grab(group='org.restlet', module='org.restlet', version='1.1.6')
             class AnnotationHost {}
-            assert org.restlet.Application.class.simpleName == 'Application'""")
+            assert org.restlet.Application.class.simpleName == 'Application'
+        '''
     }
 
+    @Test
     void testResolverDefinitionResolvesDependencyWithShorthand() {
-        GroovyShell shell = new GroovyShell(new GroovyClassLoader())
-        shell.evaluate("""
+        assertScript '''
             @GrabResolver('http://maven.restlet.org')
             @Grab('org.restlet:org.restlet:1.1.6')
             class AnnotationHost {}
-            assert org.restlet.Application.class.simpleName == 'Application'""")
+            assert org.restlet.Application.class.simpleName == 'Application'
+        '''
     }
 }