1- import java .io .{ByteArrayOutputStream , PrintStream }
1+ import java .io .{ByteArrayOutputStream , File , PrintStream }
22
3+ import dotty .tools .dotc .core .Contexts
4+ import dotty .tools .dotc .reporting .Reporter
5+ import dotty .tools .dotc .reporting .diagnostic .MessageContainer
36import dotty .tools .dotc .util .DiffUtil
7+ import dotty .tools .io .Path
48
59import scala .io .Source
610import scala .tasty .file ._
@@ -9,12 +13,8 @@ import scala.tasty.Reflection
913
1014object Test {
1115 def main (args : Array [String ]): Unit = {
12- val ps = new ByteArrayOutputStream ()
13- try scala.Console .withOut(ps) {
14- ConsumeTasty (" " , List (" IntepretedMain" , " InterpretedBar" ), new TastyInterpreter )
15- } catch {
16- case e : Throwable => throw new Exception (ps.toString, e)
17- }
16+
17+ val actualOutput = interpret(" " )(" IntepretedMain" , " InterpretedBar" )
1818 val expectedOutput =
1919 """ 42
2020 |
@@ -54,12 +54,45 @@ object Test {
5454 |68
5555 |""" .stripMargin
5656
57- val actualOutput = ps.toString
58-
5957 assert(expectedOutput == actualOutput,
6058 " \n >>>>>>>>>>>>>>>>>>\n " +
6159 DiffUtil .mkColoredCodeDiff(actualOutput, expectedOutput, true ) +
6260 " <<<<<<<<<<<<<<<<<<"
6361 )
62+
63+ // compileAndInterpret("HelloWorld")
64+ // compileAndInterpret("i3518")
65+ // compileAndInterpret("withIndex")
66+ }
67+
68+ def compileAndInterpret (testName : String ) = {
69+ val reproter = new Reporter {
70+ def doReport (m : MessageContainer )(implicit ctx : Contexts .Context ): Unit = println(m)
71+ }
72+ val out = java.nio.file.Paths .get(" out/interpreted" )
73+ if (! java.nio.file.Files .exists(out))
74+ java.nio.file.Files .createDirectory(out)
75+ dotty.tools.dotc.Main .process(Array (" -classpath" , System .getProperty(" java.class.path" ), " -d" , out.toString, " tests/run/" + testName + " .scala" ), reproter)
76+
77+ val actualOutput = interpret(out.toString)(" Test" )
78+
79+ val checkFile = java.nio.file.Paths .get(" tests/run/" + testName + " .check" )
80+ val expectedOutput = Source .fromFile(checkFile.toFile).getLines().mkString(" \n " )
81+
82+ assert(expectedOutput == actualOutput,
83+ " \n >>>>>>>>>>>>>>>>>>\n " +
84+ DiffUtil .mkColoredCodeDiff(actualOutput, expectedOutput, true ) +
85+ " <<<<<<<<<<<<<<<<<<"
86+ )
87+ }
88+
89+ def interpret (classpath : String * )(interpretedClasses : String * ): String = {
90+ val ps = new ByteArrayOutputStream ()
91+ try scala.Console .withOut(ps) {
92+ ConsumeTasty (classpath.mkString(java.io.File .pathSeparatorChar.toString), interpretedClasses.toList, new TastyInterpreter )
93+ } catch {
94+ case e : Throwable => throw new Exception (ps.toString, e)
95+ }
96+ ps.toString
6497 }
6598}
0 commit comments