changeset 22166:d2c32a9a5f27

Returning PrintStream usage back into SL instrumentation test
author Jaroslav Tulach <jaroslav.tulach@oracle.com>
date Mon, 21 Sep 2015 12:51:55 +0200
parents 67f75f61c974
children 0480c4873a4a
files truffle/com.oracle.truffle.sl.test/src/com/oracle/truffle/sl/test/instrument/SLInstrumentTestRunner.java
diffstat 1 files changed, 7 insertions(+), 9 deletions(-) [+]
line wrap: on
line diff
--- a/truffle/com.oracle.truffle.sl.test/src/com/oracle/truffle/sl/test/instrument/SLInstrumentTestRunner.java	Mon Sep 21 12:36:30 2015 +0200
+++ b/truffle/com.oracle.truffle.sl.test/src/com/oracle/truffle/sl/test/instrument/SLInstrumentTestRunner.java	Mon Sep 21 12:51:55 2015 +0200
@@ -55,7 +55,7 @@
 import java.io.ByteArrayOutputStream;
 import java.io.FileNotFoundException;
 import java.io.IOException;
-import java.io.PrintWriter;
+import java.io.PrintStream;
 import java.nio.charset.Charset;
 import java.nio.file.FileSystems;
 import java.nio.file.FileVisitResult;
@@ -234,6 +234,7 @@
         notifier.fireTestStarted(testCase.name);
 
         ByteArrayOutputStream out = new ByteArrayOutputStream();
+        PrintStream ps = new PrintStream(out);
         final ASTProber prober = new SLStandardASTProber();
         Probe.registerASTProber(prober);
         try {
@@ -247,9 +248,7 @@
 
                 // Attach an instrument to every probe tagged as an assignment
                 for (Probe probe : Probe.findProbesTaggedAs(StandardSyntaxTag.ASSIGNMENT)) {
-                    PrintWriter pw = new PrintWriter(out);
-                    SLPrintAssigmentValueListener slPrintAssigmentValueListener = new SLPrintAssigmentValueListener(pw);
-                    pw.close();
+                    SLPrintAssigmentValueListener slPrintAssigmentValueListener = new SLPrintAssigmentValueListener(ps);
                     probe.attach(Instrument.create(slPrintAssigmentValueListener, "SL print assignment value"));
                 }
 
@@ -258,7 +257,7 @@
             } else {
                 notifier.fireTestFailure(new Failure(testCase.name, new UnsupportedOperationException("No instrumentation found.")));
             }
-            out.flush();
+            ps.flush();
             String actualOutput = new String(out.toByteArray());
             Assert.assertEquals(testCase.expectedOutput, actualOutput);
         } catch (Throwable ex) {
@@ -303,15 +302,14 @@
 
     /**
      * This sample listener provides prints the value of an assignment (after the assignment is
-     * complete) to the {@link PrintWriter} specified in the constructor. This listener can only be
+     * complete) to the {@link PrintStream} specified in the constructor. This listener can only be
      * attached at {@link SLWriteLocalVariableNode}, but provides no guards to protect it from being
      * attached elsewhere.
      */
     public final class SLPrintAssigmentValueListener extends DefaultSimpleInstrumentListener {
+        private final PrintStream output;
 
-        private PrintWriter output;
-
-        public SLPrintAssigmentValueListener(PrintWriter output) {
+        public SLPrintAssigmentValueListener(PrintStream output) {
             this.output = output;
         }