groovy-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sun...@apache.org
Subject [groovy] 01/04: Add script filters for test support files
Date Tue, 13 Aug 2019 13:32:37 GMT
This is an automated email from the ASF dual-hosted git repository.

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

commit bd9a6e8cacacabd705db9d09e666654694e41faf
Author: Eric Milles <eric.milles@thomsonreuters.com>
AuthorDate: Mon Aug 12 11:01:24 2019 -0500

    Add script filters for test support files
---
 gradle/eclipse.gradle                              |  2 ++
 .../HelloWorld.groovy => ScriptAsUnitTest.groovy}  |  6 +++--
 src/test/groovy/UnitTestAsScriptTest.groovy        | 22 ----------------
 .../bugs/{Groovy1567_Bug.java => Groovy1567.java}  | 21 ++++++++--------
 .../{Groovy3719Bug.groovy => Groovy3719.groovy}    | 21 ++++++++++------
 src/test/groovy/bugs/Groovy3719Bug_script.groovy   | 20 ---------------
 ...67_script.groovy => scriptForGroovy1567.groovy} |  1 -
 ...934Helper.groovy => scriptForGroovy3934.groovy} |  3 ++-
 src/test/groovy/lang/GroovyShellTest.java          |  2 +-
 src/test/groovy/script/ScriptTest.groovy           | 19 ++++++--------
 src/test/groovy/script/ScriptWithFunctions.groovy  | 29 ----------------------
 .../script/{ShowArgs.groovy => scriptArgs.groovy}  |  0
 .../{HelloWorld.groovy => scriptHelloWorld.groovy} |  0
 ...HelloWorld2.groovy => scriptHelloWorld2.groovy} |  0
 ...Script.groovy => scriptMethodReflection.groovy} |  0
 ...Script.groovy => scriptThatCallsAnother.groovy} |  2 +-
 ...assWithScript.groovy => scriptWithClass.groovy} |  0
 ...ureInScript.groovy => scriptWithClosure.groovy} |  0
 .../{EvalInScript.groovy => scriptWithEval.groovy} |  2 +-
 ...pt.groovy => scriptWithPackageStatement.groovy} |  0
 .../org/codehaus/groovy/classgen/RunBugsTest.java  |  2 +-
 21 files changed, 43 insertions(+), 109 deletions(-)

diff --git a/gradle/eclipse.gradle b/gradle/eclipse.gradle
index 207142e..2372bc4 100644
--- a/gradle/eclipse.gradle
+++ b/gradle/eclipse.gradle
@@ -59,6 +59,8 @@ allprojects {
                 append('''\
                     eclipse.preferences.version=1
                     groovy.compiler.level=30
+                    groovy.script.filters=**/*.gradle,n,**/script*.groovy,y,**/*resources/**/*.groovy,y,**/benchmarks/**/*.groovy,y
+                    org.codehaus.groovy.eclipse.preferences.compiler.project=true
                     '''.stripIndent()
                 )
             }
diff --git a/src/test/groovy/script/HelloWorld.groovy b/src/test/ScriptAsUnitTest.groovy
similarity index 91%
copy from src/test/groovy/script/HelloWorld.groovy
copy to src/test/ScriptAsUnitTest.groovy
index 8764681..f8ec0a0 100644
--- a/src/test/groovy/script/HelloWorld.groovy
+++ b/src/test/ScriptAsUnitTest.groovy
@@ -16,6 +16,8 @@
  *  specific language governing permissions and limitations
  *  under the License.
  */
-println "Hello world"
-
 
+x = 123
+x *= 2
+println "Running unit test with a = ${x}"
+assert x == 246
diff --git a/src/test/groovy/UnitTestAsScriptTest.groovy b/src/test/groovy/UnitTestAsScriptTest.groovy
deleted file mode 100644
index da8b751..0000000
--- a/src/test/groovy/UnitTestAsScriptTest.groovy
+++ /dev/null
@@ -1,22 +0,0 @@
-/*
- *  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.
- */
-a = 123
-a *= 2
-println "Running unit test with a = ${a}"
-assert a == 246
diff --git a/src/test/groovy/bugs/Groovy1567_Bug.java b/src/test/groovy/bugs/Groovy1567.java
similarity index 73%
rename from src/test/groovy/bugs/Groovy1567_Bug.java
rename to src/test/groovy/bugs/Groovy1567.java
index bb54183..cac78fc 100644
--- a/src/test/groovy/bugs/Groovy1567_Bug.java
+++ b/src/test/groovy/bugs/Groovy1567.java
@@ -21,30 +21,29 @@ package groovy.bugs;
 import groovy.lang.Binding;
 import groovy.lang.GroovyShell;
 import groovy.util.GroovyScriptEngine;
-import groovy.util.ResourceException;
-import groovy.util.ScriptException;
+import org.junit.Test;
 
 import java.io.File;
-import java.io.IOException;
 
-import junit.framework.TestCase;
+public final class Groovy1567 {
 
-public class Groovy1567_Bug extends TestCase {
-    public void testGroovyScriptEngineVsGroovyShell() throws IOException, ResourceException,
ScriptException {
+    @Test
+    public void testGroovyScriptEngineVsGroovyShell() throws Exception {
         // @todo refactor this path
-        File currentDir = new File("./src/test/groovy/bugs");
-        String file = "bug1567_script.groovy";
+        File currentDir = new File("src/test/groovy/bugs");
+        String file = "scriptForGroovy1567.groovy";
 
         Binding binding = new Binding();
         GroovyShell shell = new GroovyShell(binding);
         String[] test = null;
-        Object result = shell.run(new File(currentDir, file), test);
+
+        //
+        shell.run(new File(currentDir, file), test);
 
         String[] roots = new String[]{currentDir.getAbsolutePath()};
         GroovyScriptEngine gse = new GroovyScriptEngine(roots);
         binding = new Binding();
-        // a MME was ensued here stating no 't.start()' was available
-        // in the script
+        // a MME was ensued here stating no 't.start()' was available in the script
         gse.run(file, binding);
     }
 }
diff --git a/src/test/groovy/bugs/Groovy3719Bug.groovy b/src/test/groovy/bugs/Groovy3719.groovy
similarity index 73%
rename from src/test/groovy/bugs/Groovy3719Bug.groovy
rename to src/test/groovy/bugs/Groovy3719.groovy
index 190c312..e7c55db 100644
--- a/src/test/groovy/bugs/Groovy3719Bug.groovy
+++ b/src/test/groovy/bugs/Groovy3719.groovy
@@ -18,14 +18,19 @@
  */
 package groovy.bugs
 
-class Groovy3719Bug extends GroovyTestCase {
+import org.junit.Test
+
+import static groovy.test.GroovyAssert.shouldFail
+
+final class Groovy3719 {
+
+    @Test
     void testScriptThrowingNoSuchMethodException() {
-        try {
-            GroovyShell shell = new GroovyShell();
-            String[] args = new String[0];
-            shell.run(new File("src/test/groovy/bugs/Groovy3719Bug_script.groovy"), args);
-        } catch(ex) {
-            assert ex instanceof NoSuchMethodException
-        }
+        def err = shouldFail '''
+            println "YES I CAN!"
+            throw new NoSuchMethodException()
+        '''
+
+        assert err instanceof NoSuchMethodException
     }
 }
diff --git a/src/test/groovy/bugs/Groovy3719Bug_script.groovy b/src/test/groovy/bugs/Groovy3719Bug_script.groovy
deleted file mode 100644
index d9b883d..0000000
--- a/src/test/groovy/bugs/Groovy3719Bug_script.groovy
+++ /dev/null
@@ -1,20 +0,0 @@
-/*
- *  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.
- */
-println "YES I CAN!"
-throw new NoSuchMethodException()
\ No newline at end of file
diff --git a/src/test/groovy/bugs/bug1567_script.groovy b/src/test/groovy/bugs/scriptForGroovy1567.groovy
similarity index 97%
rename from src/test/groovy/bugs/bug1567_script.groovy
rename to src/test/groovy/bugs/scriptForGroovy1567.groovy
index 8a0a68a..be594bc 100644
--- a/src/test/groovy/bugs/bug1567_script.groovy
+++ b/src/test/groovy/bugs/scriptForGroovy1567.groovy
@@ -16,7 +16,6 @@
  *  specific language governing permissions and limitations
  *  under the License.
  */
-package groovy.bugs
 
 t = new Thread({ println "Groovy" })
 t.start()
diff --git a/src/test/groovy/bugs/GROOVY3934Helper.groovy b/src/test/groovy/bugs/scriptForGroovy3934.groovy
similarity index 95%
rename from src/test/groovy/bugs/GROOVY3934Helper.groovy
rename to src/test/groovy/bugs/scriptForGroovy3934.groovy
index 10a3b36..9ac9b3f 100644
--- a/src/test/groovy/bugs/GROOVY3934Helper.groovy
+++ b/src/test/groovy/bugs/scriptForGroovy3934.groovy
@@ -16,4 +16,5 @@
  *  specific language governing permissions and limitations
  *  under the License.
  */
-return 'GROOVY3934Helper script called'
\ No newline at end of file
+
+return 'GROOVY3934Helper script called'
diff --git a/src/test/groovy/lang/GroovyShellTest.java b/src/test/groovy/lang/GroovyShellTest.java
index 15c8964..d254a74 100644
--- a/src/test/groovy/lang/GroovyShellTest.java
+++ b/src/test/groovy/lang/GroovyShellTest.java
@@ -119,7 +119,7 @@ public class GroovyShellTest extends GroovyTestCase {
     }
 
     public void testWithGCSWithURL() throws Exception {
-        String scriptFileName = "src/test/groovy/bugs/GROOVY3934Helper.groovy";
+        String scriptFileName = "src/test/groovy/bugs/scriptForGroovy3934.groovy";
         File helperScript = new File(scriptFileName);
         if(!helperScript.exists()) {
             fail("File " + scriptFileName + " does not exist");
diff --git a/src/test/groovy/script/ScriptTest.groovy b/src/test/groovy/script/ScriptTest.groovy
index 9098b17..3adccca 100644
--- a/src/test/groovy/script/ScriptTest.groovy
+++ b/src/test/groovy/script/ScriptTest.groovy
@@ -18,18 +18,15 @@
  */
 package groovy.script
 
-class ScriptTest extends GroovyTestCase {
+import groovy.test.GroovyTestCase
+
+final class ScriptTes extends GroovyTestCase {
+
     void testScripts() {
-        def file = new File("src/test/groovy/script")
-        file.eachFile {
+        new File('src/test/groovy/script').eachFile {
             def name = it.name
-            if (name.endsWith('.groovy')) {
-                if (name.startsWith('ScriptTest')) {
-                    //
-                }
-                else {
-                    runScript(it)
-                }
+            if (name.startsWith('script') && name.endsWith('.groovy')) {
+                runScript(it)
             }
         }
     }
@@ -47,4 +44,4 @@ class ScriptTest extends GroovyTestCase {
             println("Caught: " + e)
         }
     }
-}
\ No newline at end of file
+}
diff --git a/src/test/groovy/script/ScriptWithFunctions.groovy b/src/test/groovy/script/ScriptWithFunctions.groovy
deleted file mode 100644
index 3db157d..0000000
--- a/src/test/groovy/script/ScriptWithFunctions.groovy
+++ /dev/null
@@ -1,29 +0,0 @@
-/*
- *  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.
- */
-def foo(list, value) {
-    println "Calling function foo() with param ${value}"
-    list << value
-}
-
-x = []
-foo(x, 1)
-foo(x, 2)
-assert x == [1, 2]
-
-println "Creating list ${x}"
\ No newline at end of file
diff --git a/src/test/groovy/script/ShowArgs.groovy b/src/test/groovy/script/scriptArgs.groovy
similarity index 100%
rename from src/test/groovy/script/ShowArgs.groovy
rename to src/test/groovy/script/scriptArgs.groovy
diff --git a/src/test/groovy/script/HelloWorld.groovy b/src/test/groovy/script/scriptHelloWorld.groovy
similarity index 100%
rename from src/test/groovy/script/HelloWorld.groovy
rename to src/test/groovy/script/scriptHelloWorld.groovy
diff --git a/src/test/groovy/script/HelloWorld2.groovy b/src/test/groovy/script/scriptHelloWorld2.groovy
similarity index 100%
rename from src/test/groovy/script/HelloWorld2.groovy
rename to src/test/groovy/script/scriptHelloWorld2.groovy
diff --git a/src/test/groovy/script/MethodTestScript.groovy b/src/test/groovy/script/scriptMethodReflection.groovy
similarity index 100%
rename from src/test/groovy/script/MethodTestScript.groovy
rename to src/test/groovy/script/scriptMethodReflection.groovy
diff --git a/src/test/groovy/script/CallAnotherScript.groovy b/src/test/groovy/script/scriptThatCallsAnother.groovy
similarity index 92%
rename from src/test/groovy/script/CallAnotherScript.groovy
rename to src/test/groovy/script/scriptThatCallsAnother.groovy
index 888cda1..26acc7e 100644
--- a/src/test/groovy/script/CallAnotherScript.groovy
+++ b/src/test/groovy/script/scriptThatCallsAnother.groovy
@@ -19,6 +19,6 @@
 println("About to call another script")
 
 script = new GroovyShell()
-script.run(new File("src/test/groovy/script/HelloWorld.groovy"), [])
+script.run(new File("src/test/groovy/script/scriptHelloWorld.groovy"), [])
 
 println("Done")
diff --git a/src/test/groovy/script/ClassWithScript.groovy b/src/test/groovy/script/scriptWithClass.groovy
similarity index 100%
rename from src/test/groovy/script/ClassWithScript.groovy
rename to src/test/groovy/script/scriptWithClass.groovy
diff --git a/src/test/groovy/script/UseClosureInScript.groovy b/src/test/groovy/script/scriptWithClosure.groovy
similarity index 100%
rename from src/test/groovy/script/UseClosureInScript.groovy
rename to src/test/groovy/script/scriptWithClosure.groovy
diff --git a/src/test/groovy/script/EvalInScript.groovy b/src/test/groovy/script/scriptWithEval.groovy
similarity index 93%
rename from src/test/groovy/script/EvalInScript.groovy
rename to src/test/groovy/script/scriptWithEval.groovy
index 28dbc5e..f95b417 100644
--- a/src/test/groovy/script/EvalInScript.groovy
+++ b/src/test/groovy/script/scriptWithEval.groovy
@@ -25,6 +25,6 @@ println("Done and now set a to ${a}")
 
 println("About to call another script")
 
-evaluate(new File("src/test/groovy/script/HelloWorld.groovy"))
+evaluate(new File("src/test/groovy/script/scriptHelloWorld.groovy"))
 
 println("Done")
diff --git a/src/test/groovy/script/PackageScript.groovy b/src/test/groovy/script/scriptWithPackageStatement.groovy
similarity index 100%
rename from src/test/groovy/script/PackageScript.groovy
rename to src/test/groovy/script/scriptWithPackageStatement.groovy
diff --git a/src/test/org/codehaus/groovy/classgen/RunBugsTest.java b/src/test/org/codehaus/groovy/classgen/RunBugsTest.java
index 4e081c9..6edaf85 100644
--- a/src/test/org/codehaus/groovy/classgen/RunBugsTest.java
+++ b/src/test/org/codehaus/groovy/classgen/RunBugsTest.java
@@ -53,7 +53,7 @@ public class RunBugsTest extends TestSupport {
     }
 
     public void testUseClosureInScript() throws Exception {
-        GroovyObject object = compile("src/test/groovy/script/UseClosureInScript.groovy");
+        GroovyObject object = compile("src/test/groovy/script/scriptWithClosure.groovy");
         object.invokeMethod("run", null);
     }
 


Mime
View raw message