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/05/05 22:59:43 UTC

[groovy] branch GROOVY_2_5_X updated (4bde222 -> 4d06974)

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

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


    from 4bde222  GROOVY-9058: each parameter type not correctly inferred in Object[] case (closes #921)
     new 3e9df6a  minor refactor: move test
     new a185f4b  minor refactor: rename test
     new 7310e4e  minor refactor: remove codenarc warnings
     new 4d06974  GROOVY-9065: Add support for @Testable annotation in JUnit5Runner (closes #922)

The 4 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:
 .../PackageScopeTransformTest.groovy               |  2 +-
 .../java/groovy/junit5/plugin/JUnit5Runner.java    | 31 +++++++++++-----
 .../{MyTestJunit5.groovy => JUnit5Test.groovy}     | 42 +++++++++++-----------
 .../src/test/groovy/TestableTest.groovy            | 40 ++++++++++-----------
 .../src/test/groovy/testable/MyTest.groovy         | 12 ++++---
 .../src/test/groovy/testable/MyTestable.groovy     | 13 ++++---
 .../test/groovy/testable/TestableExtension.groovy  | 39 +++++++-------------
 .../groovy/groovy/util/GroovyShellTestCase.groovy  |  8 ++---
 8 files changed, 96 insertions(+), 91 deletions(-)
 rename src/test/org/codehaus/groovy/transform/{ => packageScope}/PackageScopeTransformTest.groovy (98%)
 rename subprojects/groovy-test-junit5/src/test/groovy/{MyTestJunit5.groovy => JUnit5Test.groovy} (58%)
 copy src/test/groovy/bugs/ClosureWithStaticVariablesBug.groovy => subprojects/groovy-test-junit5/src/test/groovy/TestableTest.groovy (60%)
 copy src/test/gls/annotations/ConstAnnotation.groovy => subprojects/groovy-test-junit5/src/test/groovy/testable/MyTest.groovy (88%)
 copy src/test/gls/annotations/ConstAnnotation.groovy => subprojects/groovy-test-junit5/src/test/groovy/testable/MyTestable.groovy (82%)
 copy src/main/groovy/groovy/lang/Tuple1.java => subprojects/groovy-test-junit5/src/test/groovy/testable/TestableExtension.groovy (58%)


[groovy] 03/04: minor refactor: remove codenarc warnings

Posted by pa...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit 7310e4e503f8a50fb7a5326a2f235d6faea5c713
Author: Paul King <pa...@asert.com.au>
AuthorDate: Sun May 5 17:59:10 2019 +1000

    minor refactor: remove codenarc warnings
---
 .../src/main/groovy/groovy/util/GroovyShellTestCase.groovy        | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/subprojects/groovy-test/src/main/groovy/groovy/util/GroovyShellTestCase.groovy b/subprojects/groovy-test/src/main/groovy/groovy/util/GroovyShellTestCase.groovy
index 463aa65..e2254e4 100644
--- a/subprojects/groovy-test/src/main/groovy/groovy/util/GroovyShellTestCase.groovy
+++ b/subprojects/groovy-test/src/main/groovy/groovy/util/GroovyShellTestCase.groovy
@@ -26,13 +26,13 @@ class GroovyShellTestCase extends GroovyTestCase {
     @Delegate protected GroovyShell shell
 
     protected void setUp() {
-        super.setUp();
-        shell = createNewShell();
+        super.setUp()
+        shell = createNewShell()
     }
 
     protected void tearDown() {
-        shell = null;
-        super.tearDown();
+        shell = null
+        super.tearDown()
     }
 
     /**


[groovy] 01/04: minor refactor: move test

Posted by pa...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit 3e9df6a7d0c90712b417f7c4a5081ef02cf8356a
Author: Paul King <pa...@asert.com.au>
AuthorDate: Sun May 5 14:13:20 2019 +1000

    minor refactor: move test
---
 .../transform/{ => packageScope}/PackageScopeTransformTest.groovy       | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/test/org/codehaus/groovy/transform/PackageScopeTransformTest.groovy b/src/test/org/codehaus/groovy/transform/packageScope/PackageScopeTransformTest.groovy
similarity index 98%
rename from src/test/org/codehaus/groovy/transform/PackageScopeTransformTest.groovy
rename to src/test/org/codehaus/groovy/transform/packageScope/PackageScopeTransformTest.groovy
index 37f8f4f..83f8048 100644
--- a/src/test/org/codehaus/groovy/transform/PackageScopeTransformTest.groovy
+++ b/src/test/org/codehaus/groovy/transform/packageScope/PackageScopeTransformTest.groovy
@@ -16,7 +16,7 @@
  *  specific language governing permissions and limitations
  *  under the License.
  */
-package org.codehaus.groovy.transform
+package org.codehaus.groovy.transform.packageScope
 
 import java.lang.reflect.Modifier
 


[groovy] 02/04: minor refactor: rename test

Posted by pa...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit a185f4be026dbb05acbc59de95fce7c4bb935c46
Author: Paul King <pa...@asert.com.au>
AuthorDate: Sun May 5 14:19:29 2019 +1000

    minor refactor: rename test
---
 .../{MyTestJunit5.groovy => JUnit5Test.groovy}     | 42 +++++++++++-----------
 1 file changed, 22 insertions(+), 20 deletions(-)

diff --git a/subprojects/groovy-test-junit5/src/test/groovy/MyTestJunit5.groovy b/subprojects/groovy-test-junit5/src/test/groovy/JUnit5Test.groovy
similarity index 58%
rename from subprojects/groovy-test-junit5/src/test/groovy/MyTestJunit5.groovy
rename to subprojects/groovy-test-junit5/src/test/groovy/JUnit5Test.groovy
index 37bf440..cb358ed 100644
--- a/subprojects/groovy-test-junit5/src/test/groovy/MyTestJunit5.groovy
+++ b/subprojects/groovy-test-junit5/src/test/groovy/JUnit5Test.groovy
@@ -23,29 +23,31 @@ import org.junit.jupiter.params.provider.ValueSource
 import java.util.stream.Stream
 import static org.junit.jupiter.api.DynamicTest.dynamicTest
 
-class MyTestJUnit5 {
+class JUnit5Test {
 
-  @Test
-  void streamSum() {
-    assert Stream.of(1, 2, 3).mapToInt{ i -> i }.sum() > 5
-  }
+    @Test
+    void streamSum() {
+        assert Stream.of(1, 2, 3).mapToInt { i -> i }.sum() > 5
+    }
 
-  @RepeatedTest(value=2, name = "{displayName} {currentRepetition}/{totalRepetitions}")
-  void streamSumRepeated() {
-    assert Stream.of(1, 2, 3).mapToInt{ i -> i }.sum() == 6
-  }
+    @RepeatedTest(value = 2, name = "{displayName} {currentRepetition}/{totalRepetitions}")
+    void streamSumRepeated() {
+        assert Stream.of(1, 2, 3).mapToInt { i -> i }.sum() == 6
+    }
 
-  private boolean isPalindrome(s) { s == s.reverse()  }
+    private boolean isPalindrome(s) { s == s.reverse() }
 
-  @ParameterizedTest
-  @ValueSource(strings = [ "racecar", "radar", "able was I ere I saw elba" ])
-  void palindromes(String candidate) {
-    assert isPalindrome(candidate)
-  }
+    @ParameterizedTest
+    @ValueSource(strings = ["racecar", "radar", "able was I ere I saw elba"])
+    void palindromes(String candidate) {
+        assert isPalindrome(candidate)
+    }
 
-  @TestFactory
-  def dynamicTestCollection() {[
-    dynamicTest("Add test") { -> assert 1 + 1 == 2 },
-    dynamicTest("Multiply Test") { -> assert 2 * 3 == 6 }
-  ]}
+    @TestFactory
+    def dynamicTestCollection() {
+        [
+                dynamicTest("Add test") { -> assert 1 + 1 == 2 },
+                dynamicTest("Multiply Test") { -> assert 2 * 3 == 6 }
+        ]
+    }
 }


[groovy] 04/04: GROOVY-9065: Add support for @Testable annotation in JUnit5Runner (closes #922)

Posted by pa...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit 4d069746b7a084f8da5da9d6802f65c916774f04
Author: Paul King <pa...@asert.com.au>
AuthorDate: Sun May 5 20:54:34 2019 +1000

    GROOVY-9065: Add support for @Testable annotation in JUnit5Runner (closes #922)
---
 .../java/groovy/junit5/plugin/JUnit5Runner.java    | 31 +++++++++++-----
 .../src/test/groovy/TestableTest.groovy            | 42 ++++++++++++++++++++++
 .../src/test/groovy/testable/MyTest.groovy         | 28 +++++++++++++++
 .../src/test/groovy/testable/MyTestable.groovy     | 29 +++++++++++++++
 .../test/groovy/testable/TestableExtension.groovy  | 41 +++++++++++++++++++++
 5 files changed, 163 insertions(+), 8 deletions(-)

diff --git a/subprojects/groovy-test-junit5/src/main/java/groovy/junit5/plugin/JUnit5Runner.java b/subprojects/groovy-test-junit5/src/main/java/groovy/junit5/plugin/JUnit5Runner.java
index 8cd13f6..15e6709 100644
--- a/subprojects/groovy-test-junit5/src/main/java/groovy/junit5/plugin/JUnit5Runner.java
+++ b/subprojects/groovy-test-junit5/src/main/java/groovy/junit5/plugin/JUnit5Runner.java
@@ -41,14 +41,16 @@ public class JUnit5Runner implements GroovyRunner {
      */
     @Override
     public boolean canRun(Class<?> scriptClass, GroovyClassLoader loader) {
+        if (!tryLoadClass("org.junit.jupiter.api.Test", loader)) {
+            return false;
+        }
         if (isJUnit5AnnotationPresent(scriptClass.getAnnotations(), loader)) {
             return true;
-        } else {
-            Method[] methods = scriptClass.getMethods();
-            for (Method method : methods) {
-                if (isJUnit5AnnotationPresent(method.getAnnotations(), loader)) {
-                    return true;
-                }
+        }
+        Method[] methods = scriptClass.getMethods();
+        for (Method method : methods) {
+            if (isJUnit5AnnotationPresent(method.getAnnotations(), loader)) {
+                return true;
             }
         }
         return false;
@@ -56,17 +58,30 @@ public class JUnit5Runner implements GroovyRunner {
 
     private boolean isJUnit5AnnotationPresent(Annotation[] annotations, GroovyClassLoader loader) {
         for (Annotation annotation : annotations) {
-            String name = annotation.annotationType().getName();
+            Class<? extends Annotation> type = annotation.annotationType();
+            String name = type.getName();
             if (name.startsWith("org.junit.jupiter.api.") && tryLoadClass(name, loader)) {
                 return true;
             }
+            if (isJUnit5TestableMetaAnnotationPresent(type) && tryLoadClass(name, loader)) {
+                return true;
+            }
+        }
+        return false;
+    }
+
+    private boolean isJUnit5TestableMetaAnnotationPresent(Class<? extends Annotation> type) {
+        for (Annotation annotation : type.getAnnotations()) {
+            if ("org.junit.platform.commons.annotation.Testable".equals(annotation.annotationType().getName())) {
+                return true;
+            }
         }
         return false;
     }
 
     private boolean tryLoadClass(String name, GroovyClassLoader loader) {
         try {
-            loader.loadClass("org.junit.jupiter.api.Test");
+            loader.loadClass(name);
             return true;
         } catch (ClassNotFoundException ignore) {
             // fall through
diff --git a/subprojects/groovy-test-junit5/src/test/groovy/TestableTest.groovy b/subprojects/groovy-test-junit5/src/test/groovy/TestableTest.groovy
new file mode 100644
index 0000000..57cb874
--- /dev/null
+++ b/subprojects/groovy-test-junit5/src/test/groovy/TestableTest.groovy
@@ -0,0 +1,42 @@
+/*
+ *  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.
+ */
+import org.junit.jupiter.api.Test
+import testable.TestableExtension
+
+class TestableTest {
+    @Test
+    void testTestableRecognized() {
+        new GroovyShell().run '''
+            import testable.*
+
+            @MyTestable
+            class Dummy {
+                @MyTest
+                void testNumber1() {}
+
+                @MyTest
+                void testNumber2() {}
+
+                @MyTest
+                void testNumber3() {}
+            }
+        ''', 'DummyName'
+        assert TestableExtension.testNames == ['testNumber1', 'testNumber2', 'testNumber3']
+    }
+}
diff --git a/subprojects/groovy-test-junit5/src/test/groovy/testable/MyTest.groovy b/subprojects/groovy-test-junit5/src/test/groovy/testable/MyTest.groovy
new file mode 100644
index 0000000..96018d5
--- /dev/null
+++ b/subprojects/groovy-test-junit5/src/test/groovy/testable/MyTest.groovy
@@ -0,0 +1,28 @@
+/*
+ *  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 testable
+
+import org.junit.jupiter.api.Test
+
+import java.lang.annotation.*
+
+@Test
+@Target(ElementType.METHOD)
+@Retention(RetentionPolicy.RUNTIME)
+@interface MyTest {}
diff --git a/subprojects/groovy-test-junit5/src/test/groovy/testable/MyTestable.groovy b/subprojects/groovy-test-junit5/src/test/groovy/testable/MyTestable.groovy
new file mode 100644
index 0000000..34eb925
--- /dev/null
+++ b/subprojects/groovy-test-junit5/src/test/groovy/testable/MyTestable.groovy
@@ -0,0 +1,29 @@
+/*
+ *  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 testable
+
+import java.lang.annotation.*
+import org.junit.jupiter.api.extension.ExtendWith
+import org.junit.platform.commons.annotation.Testable
+
+@Testable
+@ExtendWith(TestableExtension)
+@Target(ElementType.TYPE)
+@Retention(RetentionPolicy.RUNTIME)
+@interface MyTestable {}
diff --git a/subprojects/groovy-test-junit5/src/test/groovy/testable/TestableExtension.groovy b/subprojects/groovy-test-junit5/src/test/groovy/testable/TestableExtension.groovy
new file mode 100644
index 0000000..e80c9ff
--- /dev/null
+++ b/subprojects/groovy-test-junit5/src/test/groovy/testable/TestableExtension.groovy
@@ -0,0 +1,41 @@
+/*
+ *  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 testable
+
+import org.junit.jupiter.api.extension.BeforeEachCallback
+import org.junit.jupiter.api.extension.BeforeAllCallback
+import org.junit.jupiter.api.extension.ExtensionContext
+
+/**
+ * Trivial extension that logs test names. Not designed for anything other than
+ * it usage in this test suite.
+ */
+class TestableExtension implements BeforeAllCallback, BeforeEachCallback {
+    public static List<String> testNames = []
+
+    @Override
+    void beforeEach(ExtensionContext context) throws Exception {
+        testNames << context.requiredTestMethod.name
+    }
+
+    @Override
+    void beforeAll(ExtensionContext context) throws Exception {
+        testNames.clear()
+    }
+}