1
- import java .io .{ByteArrayOutputStream , PrintStream }
1
+ import java .io .{ByteArrayOutputStream , File , PrintStream }
2
2
3
+ import dotty .tools .dotc .core .Contexts
4
+ import dotty .tools .dotc .reporting .Reporter
5
+ import dotty .tools .dotc .reporting .diagnostic .MessageContainer
3
6
import dotty .tools .dotc .util .DiffUtil
7
+ import dotty .tools .io .Path
4
8
5
9
import scala .io .Source
6
10
import scala .tasty .file ._
@@ -9,12 +13,8 @@ import scala.tasty.Reflection
9
13
10
14
object Test {
11
15
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" )
18
18
val expectedOutput =
19
19
""" 42
20
20
|
@@ -54,12 +54,45 @@ object Test {
54
54
|68
55
55
|""" .stripMargin
56
56
57
- val actualOutput = ps.toString
58
-
59
57
assert(expectedOutput == actualOutput,
60
58
" \n >>>>>>>>>>>>>>>>>>\n " +
61
59
DiffUtil .mkColoredCodeDiff(actualOutput, expectedOutput, true ) +
62
60
" <<<<<<<<<<<<<<<<<<"
63
61
)
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
64
97
}
65
98
}
0 commit comments