Mercurial > hg > truffle
comparison truffle/com.oracle.truffle.sl.test/src/com/oracle/truffle/sl/test/instrument/SLInstrumentTestRunner.java @ 22165:67f75f61c974
Certain languages (like FastR) prefer access to raw byte streams. Offering it. One always has an option to wrap Input and Output Streams into character based Readers and Writers
author | Jaroslav Tulach <jaroslav.tulach@oracle.com> |
---|---|
date | Mon, 21 Sep 2015 12:36:30 +0200 |
parents | dc83cc1f94f2 |
children | d2c32a9a5f27 |
comparison
equal
deleted
inserted
replaced
22164:567d324c306c | 22165:67f75f61c974 |
---|---|
49 import com.oracle.truffle.api.vm.TruffleVM; | 49 import com.oracle.truffle.api.vm.TruffleVM; |
50 import com.oracle.truffle.sl.nodes.instrument.SLStandardASTProber; | 50 import com.oracle.truffle.sl.nodes.instrument.SLStandardASTProber; |
51 import com.oracle.truffle.sl.nodes.local.SLWriteLocalVariableNode; | 51 import com.oracle.truffle.sl.nodes.local.SLWriteLocalVariableNode; |
52 import com.oracle.truffle.sl.test.SLTestRunner; | 52 import com.oracle.truffle.sl.test.SLTestRunner; |
53 import com.oracle.truffle.sl.test.instrument.SLInstrumentTestRunner.InstrumentTestCase; | 53 import com.oracle.truffle.sl.test.instrument.SLInstrumentTestRunner.InstrumentTestCase; |
54 import java.io.BufferedReader; | 54 import java.io.ByteArrayInputStream; |
55 import java.io.ByteArrayOutputStream; | 55 import java.io.ByteArrayOutputStream; |
56 import java.io.FileNotFoundException; | 56 import java.io.FileNotFoundException; |
57 import java.io.IOException; | 57 import java.io.IOException; |
58 import java.io.PrintWriter; | 58 import java.io.PrintWriter; |
59 import java.io.StringReader; | |
60 import java.nio.charset.Charset; | 59 import java.nio.charset.Charset; |
61 import java.nio.file.FileSystems; | 60 import java.nio.file.FileSystems; |
62 import java.nio.file.FileVisitResult; | 61 import java.nio.file.FileVisitResult; |
63 import java.nio.file.Files; | 62 import java.nio.file.Files; |
64 import java.nio.file.Path; | 63 import java.nio.file.Path; |
233 protected void runChild(InstrumentTestCase testCase, RunNotifier notifier) { | 232 protected void runChild(InstrumentTestCase testCase, RunNotifier notifier) { |
234 // TODO Current tests are hard-coded, automate this eventually | 233 // TODO Current tests are hard-coded, automate this eventually |
235 notifier.fireTestStarted(testCase.name); | 234 notifier.fireTestStarted(testCase.name); |
236 | 235 |
237 ByteArrayOutputStream out = new ByteArrayOutputStream(); | 236 ByteArrayOutputStream out = new ByteArrayOutputStream(); |
238 PrintWriter printer = new PrintWriter(out); | |
239 final ASTProber prober = new SLStandardASTProber(); | 237 final ASTProber prober = new SLStandardASTProber(); |
240 Probe.registerASTProber(prober); | 238 Probe.registerASTProber(prober); |
241 try { | 239 try { |
242 // We use the name of the file to determine what visitor to attach to it. | 240 // We use the name of the file to determine what visitor to attach to it. |
243 if (testCase.baseName.endsWith(ASSIGNMENT_VALUE_SUFFIX)) { | 241 if (testCase.baseName.endsWith(ASSIGNMENT_VALUE_SUFFIX)) { |
244 // Set up the execution context for Simple and register our two listeners | 242 // Set up the execution context for Simple and register our two listeners |
245 TruffleVM vm = TruffleVM.newVM().stdIn(new BufferedReader(new StringReader(testCase.testInput))).stdOut(printer).build(); | 243 TruffleVM vm = TruffleVM.newVM().setIn(new ByteArrayInputStream(testCase.testInput.getBytes("UTF-8"))).setOut(out).build(); |
246 | 244 |
247 final String src = readAllLines(testCase.path); | 245 final String src = readAllLines(testCase.path); |
248 vm.eval(Source.fromText(src, testCase.path.toString()).withMimeType("application/x-sl")); | 246 vm.eval(Source.fromText(src, testCase.path.toString()).withMimeType("application/x-sl")); |
249 | 247 |
250 // Attach an instrument to every probe tagged as an assignment | 248 // Attach an instrument to every probe tagged as an assignment |
251 for (Probe probe : Probe.findProbesTaggedAs(StandardSyntaxTag.ASSIGNMENT)) { | 249 for (Probe probe : Probe.findProbesTaggedAs(StandardSyntaxTag.ASSIGNMENT)) { |
252 SLPrintAssigmentValueListener slPrintAssigmentValueListener = new SLPrintAssigmentValueListener(printer); | 250 PrintWriter pw = new PrintWriter(out); |
251 SLPrintAssigmentValueListener slPrintAssigmentValueListener = new SLPrintAssigmentValueListener(pw); | |
252 pw.close(); | |
253 probe.attach(Instrument.create(slPrintAssigmentValueListener, "SL print assignment value")); | 253 probe.attach(Instrument.create(slPrintAssigmentValueListener, "SL print assignment value")); |
254 } | 254 } |
255 | 255 |
256 TruffleVM.Symbol main = vm.findGlobalSymbol("main"); | 256 TruffleVM.Symbol main = vm.findGlobalSymbol("main"); |
257 main.invoke(null); | 257 main.invoke(null); |
258 } else { | 258 } else { |
259 notifier.fireTestFailure(new Failure(testCase.name, new UnsupportedOperationException("No instrumentation found."))); | 259 notifier.fireTestFailure(new Failure(testCase.name, new UnsupportedOperationException("No instrumentation found."))); |
260 } | 260 } |
261 | 261 out.flush(); |
262 printer.flush(); | |
263 String actualOutput = new String(out.toByteArray()); | 262 String actualOutput = new String(out.toByteArray()); |
264 Assert.assertEquals(testCase.expectedOutput, actualOutput); | 263 Assert.assertEquals(testCase.expectedOutput, actualOutput); |
265 } catch (Throwable ex) { | 264 } catch (Throwable ex) { |
266 notifier.fireTestFailure(new Failure(testCase.name, ex)); | 265 notifier.fireTestFailure(new Failure(testCase.name, ex)); |
267 } finally { | 266 } finally { |