You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@groovy.apache.org by su...@apache.org on 2019/11/17 08:53:57 UTC

[groovy] 02/18: minor edits

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

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

commit d1f9977722da5762fee40c3b1730267f476f45ad
Author: Eric Milles <er...@thomsonreuters.com>
AuthorDate: Mon Nov 11 12:46:38 2019 -0600

    minor edits
    
    (cherry picked from commit 81d8ac64923b9d514b3c49295a7f28241bbb46d4)
---
 .../main/java/org/codehaus/groovy/ant/Groovyc.java | 82 +++++++++-------------
 .../org/codehaus/groovy/ant/GroovycTest.xml        | 22 +++---
 .../org/codehaus/groovy/ant/GroovycTest2.java      |  6 +-
 .../org/codehaus/groovy/ant/GroovycTest.java       | 62 +++++++++-------
 4 files changed, 85 insertions(+), 87 deletions(-)

diff --git a/subprojects/groovy-ant/src/main/java/org/codehaus/groovy/ant/Groovyc.java b/subprojects/groovy-ant/src/main/java/org/codehaus/groovy/ant/Groovyc.java
index f617d8e..a7d41af 100644
--- a/subprojects/groovy-ant/src/main/java/org/codehaus/groovy/ant/Groovyc.java
+++ b/subprojects/groovy-ant/src/main/java/org/codehaus/groovy/ant/Groovyc.java
@@ -19,7 +19,6 @@
 package org.codehaus.groovy.ant;
 
 import groovy.lang.GroovyClassLoader;
-import groovy.lang.GroovyResourceLoader;
 import org.apache.groovy.io.StringBuilderWriter;
 import org.apache.tools.ant.AntClassLoader;
 import org.apache.tools.ant.BuildException;
@@ -48,7 +47,6 @@ import java.io.FileWriter;
 import java.io.IOException;
 import java.io.PrintWriter;
 import java.io.Writer;
-import java.net.MalformedURLException;
 import java.net.URL;
 import java.nio.charset.Charset;
 import java.security.AccessController;
@@ -58,6 +56,7 @@ import java.util.Enumeration;
 import java.util.LinkedHashSet;
 import java.util.List;
 import java.util.Map;
+import java.util.Optional;
 import java.util.Set;
 import java.util.StringTokenizer;
 
@@ -169,6 +168,7 @@ public class Groovyc extends MatchingTask {
     private static final URL[] EMPTY_URL_ARRAY = new URL[0];
     private static final File[] EMPTY_FILE_ARRAY = new File[0];
     private static final String[] EMPTY_STRING_ARRAY = new String[0];
+
     private final LoggingHelper log = new LoggingHelper(this);
 
     private Path src;
@@ -297,7 +297,6 @@ public class Groovyc extends MatchingTask {
      * @param version the bytecode compatibility level
      */
     public void setTargetBytecode(String version) {
-
         for (String allowedJdk : CompilerConfiguration.ALLOWED_JDKS) {
             if (allowedJdk.equals(version)) {
                 this.targetBytecode = version;
@@ -966,10 +965,9 @@ public class Groovyc extends MatchingTask {
 
         // extract joint options, some get pushed up...
         RuntimeConfigurable rc = javac.getRuntimeConfigurableWrapper();
-        for (Object o1 : rc.getAttributeMap().entrySet()) {
-            final Map.Entry e = (Map.Entry) o1;
-            final String key = e.getKey().toString();
-            final String value = getProject().replaceProperties(e.getValue().toString());
+        for (Map.Entry<String, Object> e : rc.getAttributeMap().entrySet()) {
+            String key = e.getKey();
+            String value = getProject().replaceProperties(e.getValue().toString());
             if (key.contains("debug")) {
                 String level = "";
                 if (javac.getDebugLevel() != null) {
@@ -999,15 +997,14 @@ public class Groovyc extends MatchingTask {
 
         // ant's <javac> supports nested <compilerarg value=""> elements (there can be multiple of them)
         // for additional options to be passed to javac.
-        Enumeration children = rc.getChildren();
+        Enumeration<RuntimeConfigurable> children = rc.getChildren();
         while (children.hasMoreElements()) {
-            RuntimeConfigurable childrc = (RuntimeConfigurable) children.nextElement();
+            RuntimeConfigurable childrc = children.nextElement();
             if (childrc.getElementTag().equals("compilerarg")) {
-                for (Object o : childrc.getAttributeMap().entrySet()) {
-                    final Map.Entry e = (Map.Entry) o;
-                    final String key = e.getKey().toString();
+                for (Map.Entry<String, Object> e : childrc.getAttributeMap().entrySet()) {
+                    String key = e.getKey();
                     if (key.equals("value")) {
-                        final String value = getProject().replaceProperties(e.getValue().toString());
+                        String value = getProject().replaceProperties(e.getValue().toString());
                         StringTokenizer st = new StringTokenizer(value, " ");
                         while (st.hasMoreTokens()) {
                             String optionStr = st.nextToken();
@@ -1026,16 +1023,14 @@ public class Groovyc extends MatchingTask {
     }
 
     private void doForkCommandLineList(List<String> commandLineList, Path classpath, String separator) {
-        if (!fork) return;
-
         if (includeAntRuntime) {
-            classpath.addExisting((new Path(getProject())).concatSystemClasspath("last"));
+            classpath.addExisting(new Path(getProject()).concatSystemClasspath("last"));
         }
         if (includeJavaRuntime) {
             classpath.addJavaRuntime();
         }
 
-        if (forkedExecutable != null && !forkedExecutable.equals("")) {
+        if (forkedExecutable != null && !forkedExecutable.isEmpty()) {
             commandLineList.add(forkedExecutable);
         } else {
             String javaHome;
@@ -1049,18 +1044,17 @@ public class Groovyc extends MatchingTask {
         commandLineList.add("-classpath");
         commandLineList.add(getClasspathRelative(classpath));
 
-        final String fileEncodingProp = System.getProperty("file.encoding");
-        if ((fileEncodingProp != null) && !fileEncodingProp.equals("")) {
-            commandLineList.add("-Dfile.encoding=" + fileEncodingProp);
+        String fileEncoding = System.getProperty("file.encoding");
+        if (fileEncoding != null && !fileEncoding.isEmpty()) {
+            commandLineList.add("-Dfile.encoding=" + fileEncoding);
         }
         if (targetBytecode != null) {
             commandLineList.add("-Dgroovy.target.bytecode=" + targetBytecode);
         }
-
-        if ((memoryInitialSize != null) && !memoryInitialSize.equals("")) {
+        if (memoryInitialSize != null && !memoryInitialSize.isEmpty()) {
             commandLineList.add("-Xms" + memoryInitialSize);
         }
-        if ((memoryMaximumSize != null) && !memoryMaximumSize.equals("")) {
+        if (memoryMaximumSize != null && !memoryMaximumSize.isEmpty()) {
             commandLineList.add("-Xmx" + memoryMaximumSize);
         }
         if (!"*.groovy".equals(getScriptExtension())) {
@@ -1172,12 +1166,12 @@ public class Groovyc extends MatchingTask {
     }
 
     private String[] makeCommandLine(List<String> commandLineList) {
-        log.verbose("Compilation arguments:\n" + DefaultGroovyMethods.join((Iterable)commandLineList, "\n"));
+        log.verbose("Compilation arguments:\n" + DefaultGroovyMethods.join((Iterable<String>) commandLineList, "\n"));
         return commandLineList.toArray(EMPTY_STRING_ARRAY);
     }
 
     private void runForked(String[] commandLine) {
-        final Execute executor = new Execute();
+        Execute executor = new Execute();
         executor.setAntRun(getProject());
         executor.setWorkingDirectory(getProject().getBaseDir());
         executor.setCommandline(commandLine);
@@ -1186,7 +1180,7 @@ public class Groovyc extends MatchingTask {
         } catch (final IOException ioe) {
             throw new BuildException("Error running forked groovyc.", ioe);
         }
-        final int returnCode = executor.getExitValue();
+        int returnCode = executor.getExitValue();
         if (returnCode != 0) {
             taskSuccess = false;
             if (errorProperty != null) {
@@ -1212,28 +1206,23 @@ public class Groovyc extends MatchingTask {
             if (tmpExtension.startsWith("*."))
                 tmpExtension = tmpExtension.substring(1);
             configuration.setDefaultScriptExtension(tmpExtension);
-
-            // Load the file name list
-            String[] filenames = options.generateFileNames();
-            boolean fileNameErrors = filenames == null;
-
-            fileNameErrors = fileNameErrors || !FileSystemCompiler.validateFiles(filenames);
-
             if (targetBytecode != null) {
                 configuration.setTargetBytecode(targetBytecode);
             }
 
+            // Load the file name list
+            String[] fileNames = options.generateFileNames();
+            boolean fileNameErrors = (fileNames == null || !FileSystemCompiler.validateFiles(fileNames));
             if (!fileNameErrors) {
                 try (GroovyClassLoader loader = buildClassLoaderFor()) {
-                    FileSystemCompiler.doCompilation(configuration, makeCompileUnit(loader), filenames, forceLookupUnnamedFiles);
+                    FileSystemCompiler.doCompilation(configuration, makeCompileUnit(loader), fileNames, forceLookupUnnamedFiles);
                 }
             }
-
-        } catch (Exception re) {
-            Throwable t = re;
-            if ((re.getClass() == RuntimeException.class) && (re.getCause() != null)) {
+        } catch (Exception e) {
+            Throwable t = e;
+            if (e.getClass() == RuntimeException.class && e.getCause() != null) {
                 // unwrap to the real exception
-                t = re.getCause();
+                t = e.getCause();
             }
             Writer writer = new StringBuilderWriter();
             new ErrorReporter(t, false).write(new PrintWriter(writer));
@@ -1262,13 +1251,13 @@ public class Groovyc extends MatchingTask {
                     + (destDir != null ? " to " + destDir : ""));
 
             listFiles();
-            Path classpath = getClasspath() != null ? getClasspath() : new Path(getProject());
-            List<String> jointOptions = extractJointOptions(classpath);
 
+            Path classpath = Optional.ofNullable(getClasspath()).orElse(new Path(getProject()));
+            List<String> jointOptions = extractJointOptions(classpath);
             String separator = System.getProperty("file.separator");
             List<String> commandLineList = new ArrayList<>();
 
-            doForkCommandLineList(commandLineList, classpath, separator);
+            if (fork) doForkCommandLineList(commandLineList, classpath, separator);
             doNormalCommandLineList(commandLineList, jointOptions, classpath);
             addSourceFiles(commandLineList);
 
@@ -1326,7 +1315,8 @@ public class Groovyc extends MatchingTask {
         if (!fork && !getIncludeantruntime()) {
             throw new IllegalArgumentException("The includeAntRuntime=false option is not compatible with fork=false");
         }
-        final ClassLoader parent =
+
+        ClassLoader parent =
                 AccessController.doPrivileged(
                         new PrivilegedAction<ClassLoader>() {
                             @Override
@@ -1368,9 +1358,8 @@ public class Groovyc extends MatchingTask {
             }
         }
 
-        GroovyClassLoader loader =
-                AccessController.doPrivileged(
-                        (PrivilegedAction<GroovyClassLoader>) () -> new GroovyClassLoader(parent, configuration));
+        GroovyClassLoader loader = AccessController.doPrivileged(
+                (PrivilegedAction<GroovyClassLoader>) () -> new GroovyClassLoader(parent, configuration));
         if (!forceLookupUnnamedFiles) {
             // in normal case we don't need to do script lookups
             loader.setResourceLoader(filename -> null);
@@ -1384,7 +1373,6 @@ public class Groovyc extends MatchingTask {
 
     private void loadRegisteredScriptExtensions() {
         if (scriptExtensions.isEmpty()) {
-
             scriptExtensions.add(getScriptExtension().substring(2)); // first extension will be the one set explicitly on <groovyc>
 
             Path classpath = getClasspath() != null ? getClasspath() : new Path(getProject());
diff --git a/subprojects/groovy-ant/src/test-resources/org/codehaus/groovy/ant/GroovycTest.xml b/subprojects/groovy-ant/src/test-resources/org/codehaus/groovy/ant/GroovycTest.xml
index 2a3f68b..d4fb8d2 100644
--- a/subprojects/groovy-ant/src/test-resources/org/codehaus/groovy/ant/GroovycTest.xml
+++ b/subprojects/groovy-ant/src/test-resources/org/codehaus/groovy/ant/GroovycTest.xml
@@ -78,7 +78,7 @@
     </target>
 
     <target name="GroovycTest1_Joint_NoFork_NoClasspath">
-        <groovyc srcdir="${srcPath}" destdir="${destPath}" includes="GroovycTest1.groovy,Groovyc2.java">
+        <groovyc srcdir="${srcPath}" destdir="${destPath}" includes="GroovycTest1.groovy,GroovyTest2.java">
             <javac source="${javaVersion}" target="${javaVersion}" debug="true"/>
         </groovyc>
         <java classname="org.codehaus.groovy.ant.GroovycTest1"/>
@@ -86,7 +86,7 @@
     </target>
 
     <target name="GroovycTest1_Joint_NoFork_WithGroovyClasspath">
-        <groovyc srcdir="${srcPath}" destdir="${destPath}" includes="GroovycTest1.groovy,Groovyc2.java"
+        <groovyc srcdir="${srcPath}" destdir="${destPath}" includes="GroovycTest1.groovy,GroovycTest2.java"
                  classpathref="groovyMaterials">
             <javac source="${javaVersion}" target="${javaVersion}" debug="true"/>
         </groovyc>
@@ -104,7 +104,7 @@
     </target>
 
     <target name="GroovycTest1_Joint_NoFork_WithJavaClasspath">
-        <groovyc srcdir="${srcPath}" destdir="${destPath}" includes="GroovycTest1.groovy,Groovyc2.java">
+        <groovyc srcdir="${srcPath}" destdir="${destPath}" includes="GroovycTest1.groovy,GroovycTest2.java">
             <javac source="${javaVersion}" target="${javaVersion}" debug="true"/>
         </groovyc>
         <java classname="org.codehaus.groovy.ant.GroovycTest1" classpathref="groovyMaterials"/>
@@ -112,7 +112,7 @@
     </target>
 
     <target name="GroovycTest1_Joint_NoFork_WithBothClasspath">
-        <groovyc srcdir="${srcPath}" destdir="${destPath}" includes="GroovycTest1.groovy,Groovyc2.java"
+        <groovyc srcdir="${srcPath}" destdir="${destPath}" includes="GroovycTest1.groovy,GroovycTest2.java"
                  classpathref="groovyMaterials">
             <javac source="${javaVersion}" target="${javaVersion}" debug="true"/>
         </groovyc>
@@ -121,7 +121,7 @@
     </target>
 
     <target name="GroovycTest1_Joint_ForkGroovy_NoClasspath">
-        <groovyc srcdir="${srcPath}" destdir="${destPath}" includes="GroovycTest1.groovy,Groovyc2.java" fork="true">
+        <groovyc srcdir="${srcPath}" destdir="${destPath}" includes="GroovycTest1.groovy,GroovycTest2.java" fork="true">
             <javac source="${javaVersion}" target="${javaVersion}" debug="true"/>
         </groovyc>
         <java classname="org.codehaus.groovy.ant.GroovycTest1"/>
@@ -129,8 +129,8 @@
     </target>
 
     <target name="GroovycTest1_Joint_ForkGroovy_WithGroovyClasspath">
-        <groovyc srcdir="${srcPath}" destdir="${destPath}" includes="GroovycTest1.groovy,Groovyc2.java"
-                 classpathref="groovyMaterials" fork="true">
+        <groovyc srcdir="${srcPath}" destdir="${destPath}" includes="GroovycTest1.groovy,GroovycTest2.java" fork="true"
+                 classpathref="groovyMaterials">
             <javac source="${javaVersion}" target="${javaVersion}" debug="true"/>
         </groovyc>
         <java classname="org.codehaus.groovy.ant.GroovycTest1"/>
@@ -138,7 +138,7 @@
     </target>
 
     <target name="GroovycTest1_Joint_ForkGroovy_WithJavaClasspath">
-        <groovyc srcdir="${srcPath}" destdir="${destPath}" includes="GroovycTest1.groovy,Groovyc2.java" fork="true">
+        <groovyc srcdir="${srcPath}" destdir="${destPath}" includes="GroovycTest1.groovy,GroovycTest2.java" fork="true">
             <javac source="${javaVersion}" target="${javaVersion}" debug="true"/>
         </groovyc>
         <java classname="org.codehaus.groovy.ant.GroovycTest1" classpathref="groovyMaterials"/>
@@ -146,8 +146,8 @@
     </target>
 
     <target name="GroovycTest1_Joint_ForkGroovy_WithBothClasspath">
-        <groovyc srcdir="${srcPath}" destdir="${destPath}" includes="GroovycTest1.groovy,Groovyc2.java"
-                 classpathref="groovyMaterials" fork="true">
+        <groovyc srcdir="${srcPath}" destdir="${destPath}" includes="GroovycTest1.groovy,GroovycTest2.java" fork="true"
+                 classpathref="groovyMaterials">
             <javac source="${javaVersion}" target="${javaVersion}" debug="true"/>
         </groovyc>
         <java classname="org.codehaus.groovy.ant.GroovycTest1" classpathref="groovyMaterials"/>
@@ -191,7 +191,9 @@
         <delete quiet="true">
             <fileset dir="${destPath}/org/codehaus/groovy/ant">
                 <include name="GroovycTest1*.class"/>
+                <include name="GroovycTest2*.class"/>
                 <include name="IncorrectGenericsUsage.class"/>
+                <include name="MakesExternalReference.class"/>
             </fileset>
         </delete>
     </target>
diff --git a/subprojects/groovy-ant/src/test-resources/org/codehaus/groovy/ant/GroovycTest2.java b/subprojects/groovy-ant/src/test-resources/org/codehaus/groovy/ant/GroovycTest2.java
index d7ef1d5..ff990c2 100644
--- a/subprojects/groovy-ant/src/test-resources/org/codehaus/groovy/ant/GroovycTest2.java
+++ b/subprojects/groovy-ant/src/test-resources/org/codehaus/groovy/ant/GroovycTest2.java
@@ -24,14 +24,14 @@ import java.io.IOException;
 
 class GroovycTest2 {
     static void main(String[] args) throws IOException {
-        File f = new File("target/classes/test/org/codehaus/groovy/ant/GroovycTest2_Result.txt");
-        FileOutputStream fout = new FileOutputStream(f);
+        FileOutputStream fout = new FileOutputStream(
+            new File("target/classes/groovy/test/org/codehaus/groovy/ant/GroovycTest2_Result.txt"));
         try {
             fout.write("OK.".getBytes());
         } finally {
             try {
                 fout.close();
-            } catch (IOException ioe) {
+            } catch (IOException ignore) {
             }
         }
     }
diff --git a/subprojects/groovy-ant/src/test/groovy/org/codehaus/groovy/ant/GroovycTest.java b/subprojects/groovy-ant/src/test/groovy/org/codehaus/groovy/ant/GroovycTest.java
index e0f25dc..cb60c5d 100644
--- a/subprojects/groovy-ant/src/test/groovy/org/codehaus/groovy/ant/GroovycTest.java
+++ b/subprojects/groovy-ant/src/test/groovy/org/codehaus/groovy/ant/GroovycTest.java
@@ -30,6 +30,8 @@ import java.io.FileOutputStream;
 import java.io.FileReader;
 import java.io.IOException;
 import java.io.PrintStream;
+import java.net.URISyntaxException;
+import java.nio.file.Paths;
 import java.util.regex.Pattern;
 
 /**
@@ -40,17 +42,16 @@ import java.util.regex.Pattern;
  * matter as the tests remove all class files that should not pre-exist from this directory at each step.
  */
 public class GroovycTest extends GroovyTestCase {
-    private final String classDirectory = "target/classes/groovy/test/org/codehaus/groovy/ant/";
     private final File antFile = new File("src/test-resources/org/codehaus/groovy/ant/GroovycTest.xml");
     private Project project;
     private static boolean warned = false;
 
-    protected void setUp() throws Exception {
-        super.setUp(); //  Potentially throws Exception.
+    protected void setUp() {
         project = new Project();
         project.init();
         ProjectHelper.getProjectHelper().parse(project, antFile);
         project.executeTarget("clean");
+
         String altJavaHome = System.getProperty("java.home");
         if (altJavaHome.lastIndexOf("jre") >= 0) {
             altJavaHome = altJavaHome.substring(0, altJavaHome.lastIndexOf("jre"));
@@ -62,32 +63,40 @@ public class GroovycTest extends GroovyTestCase {
             if (altFile.exists()) {
                 project.setProperty("alt.java.home", altJavaHome);
             }
-        } catch (Exception e) {
-            // could be security, io, etc.  Ignore it.
+        } catch (Exception ignore) {
+            // could be security, io, etc.
             // End result is as if .exists() returned null
         }
     }
 
+    private String getTargetDirectory() {
+        try {
+            return Paths.get(getClass().getResource(".").toURI()).toString() + File.separator;
+        } catch (URISyntaxException e) {
+            throw new RuntimeException(e);
+        }
+    }
+
     private void ensureNotPresent(final String classname) {
-        if (!(new File(classDirectory + "GroovycTest.class")).exists()) {
+        if (!(new File(getTargetDirectory() + getClass().getSimpleName() + ".class")).exists()) {
             fail("Class file for GroovycTest does not exist and should.");
         }
-        if ((new File(classDirectory + classname + ".class")).exists()) {
+        if ((new File(getTargetDirectory() + classname + ".class")).exists()) {
             fail("Class file for " + classname + " already exists and shouldn't.");
         }
     }
 
     private void ensurePresent(final String classname) {
-        if (!(new File(classDirectory + classname + ".class")).exists()) {
+        if (!(new File(getTargetDirectory() + classname + ".class")).exists()) {
             fail("Class file for " + classname + " does not exist and should.");
         }
     }
 
     private void ensureResultOK(final String classname) {
-        if (!(new File(classDirectory + classname + ".class")).exists()) {
+        if (!(new File(getTargetDirectory() + classname + ".class")).exists()) {
             fail("Class file for " + classname + " does not exist and should.");
         }
-        final File result = new File(classDirectory + classname + "_Result.txt");
+        final File result = new File(getTargetDirectory() + classname + "_Result.txt");
         final char[] buffer = new char[10];
         FileReader fr = null;
         try {
@@ -153,23 +162,23 @@ public class GroovycTest extends GroovyTestCase {
     public void testGroovyc_Joint_NoFork_NestedCompilerArg_WithGroovyClasspath() {
         // capture ant's output so we can verify the effect of passing compilerarg to javac
         ByteArrayOutputStream allOutput = new ByteArrayOutputStream();
-        PrintStream out = new PrintStream(allOutput);
-        PrintStream origOut = System.out;
-        System.setOut(out);
-
-        ensureNotPresent("IncorrectGenericsUsage");
-        project.executeTarget("Groovyc_Joint_NoFork_NestedCompilerArg_WithGroovyClasspath");
-        ensurePresent("IncorrectGenericsUsage");
 
-        String antOutput = allOutput.toString();
-        antOutput = adjustOutputToHandleOpenJDKJavacOutputDifference(antOutput);
-        System.setOut(origOut);
-
-        // verify if passing -Xlint in compilerarg had its effect
-        Pattern p = Pattern.compile(".*?found[ ]*:[ ]*java.util.ArrayList.*", Pattern.DOTALL);
-        assertTrue("Expected line 1 not found in ant output", p.matcher(antOutput).matches());
-        p = Pattern.compile(".*?required[ ]*:[ ]*java.util.ArrayList<java.lang.String>.*", Pattern.DOTALL);
-        assertTrue("Expected line 2 not found in ant output", p.matcher(antOutput).matches());
+        PrintStream out = System.out;
+        System.setOut(new PrintStream(allOutput));
+        try {
+            ensureNotPresent("IncorrectGenericsUsage");
+            project.executeTarget("Groovyc_Joint_NoFork_NestedCompilerArg_WithGroovyClasspath");
+            ensurePresent("IncorrectGenericsUsage");
+
+            String antOutput = adjustOutputToHandleOpenJDKJavacOutputDifference(allOutput.toString());
+            // verify if passing -Xlint in compilerarg had its effect
+            Pattern p = Pattern.compile(".*?found[ ]*:[ ]*java.util.ArrayList.*", Pattern.DOTALL);
+            assertTrue("Expected line 1 not found in ant output", p.matcher(antOutput).matches());
+            p = Pattern.compile(".*?required[ ]*:[ ]*java.util.ArrayList<java.lang.String>.*", Pattern.DOTALL);
+            assertTrue("Expected line 2 not found in ant output", p.matcher(antOutput).matches());
+        } finally {
+            System.setOut(out);
+        }
     }
 
     /**
@@ -281,5 +290,4 @@ public class GroovycTest extends GroovyTestCase {
             badGroovy.delete();
         }
     }
-
 }