groovy-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From pa...@apache.org
Subject [1/2] groovy git commit: GROOVY-8347: AutoFinalTransformBlackBoxTest: Added @AutoFinal(enabled=false) testing (closes #615)
Date Wed, 11 Oct 2017 14:30:49 GMT
Repository: groovy
Updated Branches:
  refs/heads/master 9a7c98d24 -> 8714484ea


GROOVY-8347: AutoFinalTransformBlackBoxTest: Added @AutoFinal(enabled=false) testing (closes
#615)


Project: http://git-wip-us.apache.org/repos/asf/groovy/repo
Commit: http://git-wip-us.apache.org/repos/asf/groovy/commit/5690a5a9
Tree: http://git-wip-us.apache.org/repos/asf/groovy/tree/5690a5a9
Diff: http://git-wip-us.apache.org/repos/asf/groovy/diff/5690a5a9

Branch: refs/heads/master
Commit: 5690a5a9df2327a1ac479245b5b887c2d0eeb098
Parents: 9a7c98d
Author: mgroovy <31455466+mgroovy@users.noreply.github.com>
Authored: Tue Oct 10 19:03:43 2017 +0200
Committer: paulk <paulk@asert.com.au>
Committed: Thu Oct 12 00:00:23 2017 +1000

----------------------------------------------------------------------
 .../AutoFinalTransformBlackBoxTest.groovy       | 33 +++++++++++++++-----
 1 file changed, 25 insertions(+), 8 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/groovy/blob/5690a5a9/src/test/org/codehaus/groovy/transform/AutoFinalTransformBlackBoxTest.groovy
----------------------------------------------------------------------
diff --git a/src/test/org/codehaus/groovy/transform/AutoFinalTransformBlackBoxTest.groovy
b/src/test/org/codehaus/groovy/transform/AutoFinalTransformBlackBoxTest.groovy
index d9625ed..4e7bf26 100644
--- a/src/test/org/codehaus/groovy/transform/AutoFinalTransformBlackBoxTest.groovy
+++ b/src/test/org/codehaus/groovy/transform/AutoFinalTransformBlackBoxTest.groovy
@@ -23,6 +23,8 @@ import org.junit.Test
 import org.junit.runner.RunWith
 import org.junit.runners.JUnit4
 
+import java.util.Map.Entry
+
 
 /**
  * Tests for the {@code @AutoFinal} AST transform.
@@ -63,42 +65,57 @@ class AutoFinalTransformBlackBoxTest extends CompilableTestSupport {
         return param0 
       }
     """
-    final script = autoFinalTestScript(true, classPart, "final foo = new $autoFinalTestClassName();
foo.foo()" )
+    final script = autoFinalTestScript(true, [:], classPart, "final foo = new $autoFinalTestClassName();
foo.foo()" )
     assert script.contains('@AutoFinal')
     assertScript(script)
   }
 
 
 
-
   void assertAutoFinalClassTestScript(final String paramName, final String classPart) {
     assertAutoFinalTestScriptWithAnnotation(paramName, classPart)
-    assertAutoFinalTestScriptWithoutAnnotation(paramName, classPart)
+    assertAutoFinalTestScriptWithoutAnnotation(classPart)
+    assertAutoFinalTestScriptWithDisabledAnnotation(classPart)
   }
 
+  //
   // Checks Groovy compiler behavior when putting the passed classPart into an @AutoFinal
annotated class
+  //
+
+  // @AutoFinal
   void assertAutoFinalTestScriptWithAnnotation(final String paramName, final String classPart)
{
-    final script = autoFinalTestScript(true, classPart)
+    final script = autoFinalTestScript(true, [:], classPart)
     assert script.contains('@AutoFinal')
     final result = shouldNotCompile(script)
     println "\nassertAutoFinalTestScript result: |$result|\n\n"
     assert result.contains("The parameter [$paramName] is declared final but is reassigned")
   }
 
-  void assertAutoFinalTestScriptWithoutAnnotation(final String paramName, final String classPart)
{
-    final script = autoFinalTestScript(false, classPart)
+  // @AutoFinal(enabled=false)
+  void assertAutoFinalTestScriptWithDisabledAnnotation(final String classPart) {
+    final script = autoFinalTestScript(true, [enabled:false], classPart)
+    assert script.contains('@AutoFinal(enabled=false)')
+    shouldCompile(script)
+  }
+
+  // No annotation
+  void assertAutoFinalTestScriptWithoutAnnotation(final String classPart) {
+    final script = autoFinalTestScript(false, null, classPart)
     assert !script.contains('@AutoFinal')
     shouldCompile(script)
   }
 
-  String autoFinalTestScript(final boolean autoFinalAnnotationQ, final String classPart,
final String scriptPart = '') {
+
+  String autoFinalTestScript(final boolean autoFinalAnnotationQ, final Map<String,Object>
autoFinalAnnotationParamaters, final String classPart, final String scriptPart = '') {
+    assert !autoFinalAnnotationQ || (autoFinalAnnotationParamaters != null); assert classPart
+    final String autoFinalAnnotationParamatersTerm = autoFinalAnnotationParamaters ? "(${autoFinalAnnotationParamaters.collect
{ final Entry<String, Object> e -> "$e.key=$e.value" }.join(', ')})" : ''
     final String script = """
             import groovy.transform.AutoFinal
             import groovy.transform.ASTTest
             import static org.codehaus.groovy.control.CompilePhase.SEMANTIC_ANALYSIS
             import static java.lang.reflect.Modifier.isFinal
 
-            ${autoFinalAnnotationQ ? '@AutoFinal' : ''}
+            ${autoFinalAnnotationQ ? "@AutoFinal${autoFinalAnnotationParamatersTerm}" : ''}
             class $autoFinalTestClassName {
                 $classPart
             } 


Mime
View raw message